Need to move a character INSTANTANEOUSLY (Solved)

Started by Jared, Thu 14/05/2009 12:01:50

Previous topic - Next topic

Jared

I've been a bit frustrated working with different sized sprites that others in a project have made - to make a scene work sprites need to jump across a scene in a literal instant, and I briefly thought that this was what Character.Move() does and I've been a bit disappointed (though it has cleared up one part of the scene..) I know that characters generally aren't meant to jump all over the screen but it will be REALLY USEFUL if it's possible in this context.

Thanks for your help in advance, because it's always good stuff.

GarageGothic

You can just change Character.x and Character.y directly to instantly transport the character to those coordinates.

Jared

...really? Damn, that's buried away in the manual...

Okay, I'll do that right now..

Dualnames

Or you can use:

cChar.ChangeRoom(cChar.Room, coordx, coordy);
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Jared

Thanks, but that was one of the first things I tried and it made it crash when I ran it.

Anyway, the cChar.x thing worked fine. So this one's solved.

monkey0506

#5
I don't see why you would want to change the character to the room they're already in Dual...the function is called ChangeRoom...ChangeRoom...

The correct way is of course to modify the Character.x and Character.y properties directly (make sure Character.Moving is false first!).

If you want you could even write a custom extender method like this:

Code: ags
// GlobalScript.ash
import bool SetPosition(this Character*, int x, int y, bool stopMoving=true);

// GlobalScript.asc
bool SetPosition(this Character*, int x, int y, bool stopMoving) {
  if (this.Moving) {
    if (!stopMoving) return false;
    else this.StopMoving();
  }
  this.x = x;
  this.y = y;
  return true;
}

// any script
cChar.SetPosition(new_x, new_y);


;)

Edit: I added an optional parameter to the code so if you like you can now force the character to stop moving (if they are moving) and still put them at the new position.

SMF spam blocked by CleanTalk