OghuzKhan36Li
Member
Hi all,
In my scene management I want to move an object until it is in position..
So I thought why not use switch cases to my advantage as Actions of a scene.
This idea was going great until I hit a wall.. I can't seem to make an efficient code that makes the given object move until it has reached its goal..
The problem is the obove code keeps repeating every step and because of that it keeps resetting the coordinates making the object move endlessly..
What can I do to fix this?
In my scene management I want to move an object until it is in position..
So I thought why not use switch cases to my advantage as Actions of a scene.
GML:
switch Action {
case 0:
// Null..
break;
case 1:
if scrMoveObjects(objEnemy, -32, -32, 1) == "Continue" Action++;
break;
};
The problem is the obove code keeps repeating every step and because of that it keeps resetting the coordinates making the object move endlessly..
GML:
/// @function scrMoveObjects(Object, xgoto, ygoto, Speed);
function scrMoveObjects(_Object, _xgoto, _ygoto, _Speed) {
with _Object {
if (x+_xgoto != x && y+_ygoto != y) {
if x != x+_xgoto x += _Speed*sign(_xgoto);
if y != y+_ygoto y += _Speed*sign(_ygoto);
}
else
{
return ("Continue");
};
};
};