Walk sideways? (Locking character Loop)

Started by spook1, Fri 16/06/2006 09:35:01

Previous topic - Next topic

spook1

For a special puzzle I need a character to move, but not always in the same "loop".

Sometimes I want my chatracter to kove to the right, but shown in the "up" loop.
I can do this with a locked view, but this feature freezes the view in a single frame.
Is the a way to choose the loop of the view, and still have the character animated?

Ashen

Short answer: Not really.
The easiest way is probably to make new views with only one loop (i.e. view 3 for the down loop, view 4 for left, view 5 for right, etc), and use Character.ChangeView (rather than LockView) to set them. It might get a bit wasteful if you have lots of characters you need to do this for - but with a limit of 600 views, that shouldn't be a problem.

Or, you could use a variable to force the loop to what you want, e.g.:
Code: ags

// Top of Room Script:
int Dir = -1;

//Room's repeatedly_execute function:
if (Dir != -1) player.Loop = Dir;


Then just set Dir to the appropriate loop (e.g. Dir = 3; for up) to lock it, and back to -1 to release again. The downside to this is, you'll probably see a flash of the loop it should be, before the character starts moving. Another way would be to use LockView as you are doing, and Character.Animate to simulate the Walking animation. (You'll also need someway to tell AGS when to stop the animation, e.g. a variable checked in rep_ex.)

But if you don't mind the extra Views, that's still the simplest way I can think of.
I know what you're thinking ... Don't think that.

GarageGothic

#2
You could also add a dummy character and hide the real one and do something like this:

Code: ags

//in player_enters_room_beforefadein
  cDummy.View = player.View;
  cDummy.Loop = 3; //up loop
  player.Transparency = 100;
  cDummy.Room = player.Room;


Code: ags

// in repeatedly_execute_always
if (cDummy.Room == player.Room) { //or any variable you set to trigger this effect
  cDummy.x = player.x;
  cDummy.y = player.y;
  cDummy.Frame = player.Frame;
}


Edit: if you need more animations than just walking (talking, idle etc.) of course you have to change the cDummy.Loop manually. You can add a section in the repeatedly_execute_always to catch the player.Loop and set the cDummy.Loop to the corresponding up loop. Just make sure to do it before the line where you set cDummy.Frame, or the game could crash (if for example the player.Frame is frame 13 in a 15 frame idle animation and your walking animation is only 8 frames, then the cDummy.Frame = player.Frame would be trying to set a non-existent frame number).

Akumayo

I need to do something a lot like this.  I'm making a platformer/shooter where the character needs to be able to run left/right with his gun pointed straight, as well as being able to run left/right with his gun pointed up/down at 45 degree angles.  6 loops to make that.  It would be incredibly helpful if I could use Ashen's suggestion.  Are there any downsides to doing so?  I can't test it yet, as the animations aren't anywhere near complete.  Would it cause any problems that you can think of?

-Thanks in advance, Akumayo
"Power is not a means - it is an end."

GarageGothic

#4
Since you're not using mouse control and thus don't need pathfinding, there's little point in keeping AGS's own walk system. So I say go for Ashen's simulated walking animation. Another thing is that in a platformer you probably want the player to be able just to take one step at a time unlike two steps in a normal walking animation. So it would be a good idea to have the left/right foot movement in separate loops if you're going to use Character.Animate.

Edit: The one-step thing above was in reference to a Prince of Persia type of game, where you always move one whole step at a time. If you just need the player to move for the exact time that the button is held down (not waiting to finish their step) a la Mario, just use normal loops with full walkcycle.

Akumayo

I think I understand what you mean.  I'll come back if it gives me any more trouble.  (Which I'm sure it will, what fun would game making be if you never ran into problems?)
"Power is not a means - it is an end."

SMF spam blocked by CleanTalk