Forum Moderators: open

Message Too Old, No Replies

multi-object movement

for server-based game

         

adni18

3:33 am on Dec 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have two squares on the stage. there are 2 input fields, xcoords and ycoords. the goal is to get it so that when you type in the coords, the box will move there.

I got it to work with one box by saying box1._x ++ and so on, but I want there to be an argument in the move function that asks for the box number. here's what I have so far:

var xcoords = 100;
var ycoords = 100;
var speed = 1;
xmax = 540;
xmin = 0;
ymax = 400;
ymin = 0;

function populate (); {
boxes = new Array [
[

}

function moveObj (num) {
if (xcoords>xmax) {
xcoords = xmax;
} else if (xcoords<xmin) {
xcoords = xmin;
}
if (ycoords>ymax) {
ycoords = ymax;
} else if (ycoords<ymin) {
ycoords = ymin;
}
curx = _root.boxnum[num]._x;
cury = _root.boxnum[num]._y;
if (curx>xcoords) {
_root.boxnum[num]._x -= speed;
} else if (curx<xcoords) {
_root.boxnum[num]._x += speed;
}
if (cury>ycoords) {
_root.boxnum[num]._y -= speed;
} else if (cury<ycoords) {
_root.boxnum[num]._y += speed;
}
}

and its called from:

onClipEvent (enterFrame) {
_root.moveObj(1);
}

this does nothing. the coords work, and the limits work, but nothing moves. help me please!

Richard_N

11:44 pm on Dec 29, 2005 (gmt 0)



look at the MX tween classes, should be quite simple to set up a variable to read both the x and y coordinates then place the imput text into a variable to control the destination, if you want I can knock up a quick example

Richard_N

12:03 am on Dec 30, 2005 (gmt 0)



OK quick example using the moveit button to control the test_mc clip, its easy to convert the parameters from the text boxes into variables and pass them to the moveclip function

//import transition classes----------------
import mx.transitions.Tween;
import mx.transitions.easing.*;

//control clip--------------------
function moveclip(xfinish:Number,yfinish:Number) {
var xstart:Number = test_mc._x;
var ystart:Number = test_mc._y;
var xMove:Tween = new Tween(test_mc, "_x", Bounce.easeOut, xstart, xfinish, 3, true);
var yMove:Tween = new Tween(test_mc, "_y", Bounce.easeOut, ystart, yfinish, 3, true);
}

//button function-------------------
moveit_btn.onPress = function(){
moveclip(300,200)
}