• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Scene management problem

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.

GML:
switch Action {
case 0:
//    Null..
break;
case 1:
if scrMoveObjects(objEnemy, -32, -32, 1) == "Continue"        Action++;
break;
};
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..

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");
};
};
};
What can I do to fix this?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Use variables to hold the x/y go to values, then modify your code to check just the goto values not x+xgoto/y+ygoto.
 
Thats what I initially wanted to do but the problem is this function needs to be run multiple times by different values. I want this code to be efficient so if I ever wanted to move more objects at the same time to different places then all I need are some parameters and thats all :)
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, then... Why not just make the xgoto and ygoto input values absolute room coordinates rather than relative ones?
 
Top