The Daily Click ::. Forums ::. Klik Coding Help ::. "Sliding" objects
 

Post Reply  Post Oekaki 
 

Posted By Message

Rory Griffin



Registered
  14/08/2003
Points
  239
18th February, 2005 at 08:17:05 -

How do I do smooth sliding effects for objects when I hit a direction button?

In example: In Zelda II: Adventure of Link, if you hit right (on overworld) Link moves right 16 spaces. If one continues holding right, he always goes on to keep that 16 space constant. I've failed at all attempts at doing this and need some help.

Thanks!

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
18th February, 2005 at 08:54:37 -

how about...


start of frame (or whatever)
* set alterable value A to X( "Active" )
* set alterable value B to Y( "Active" )

repeat while right is pressed
& alterable value C > 0;
* set alterable value A to ( ( X( "Active" ) / 16 ) * 16 ) + 16
* set alterable value C to 2

repeat while left is pressed
& alterable value C > 0;
* set alterable value A to ( ( ( X( "Active" ) - 8 ) / 16 ) * 16 )
* set alterable value C to 2

repeat while down is pressed
alterable value C < 2;
* set alterable value B to ( ( Y( "Active" ) / 16 ) * 16 ) + 16
* set alterable value C to 0

repeat while up is pressed
& alterable value C < 2;
* set alterable value B to ( ( ( Y( "Active" ) - 8 ) / 16 ) * 16 )
* set alterable value C to 0

X Position < Value A
& alterable value C = 2;
* set Xposition to X( "Active" ) + 1

X Position > Value A
& alterable value C = 2;
* set XPosition to X( "Active" ) - 1

Y Position < Value B
& alterable value C = 0;
* set Yposition to Y( "Active" ) + 1

Y Position > Value B
& alterable value C = 0;
* set YPosition to Y( "Active" ) - 1

X Position = Value A
& Y Position = Value B;
* set alterable value C to 1

hope that helps. if not, ive seen plenty of examples of this (try searching the clickteam forums for "grid movement" or something similar).

Image Edited by the Author.

 
n/a

DistantJ [FZ Games]



Registered
  02/08/2004
Points
  855
18th February, 2005 at 09:50:44 -

The reason it happens this way in Adventure of Link(Awesome game) is because the map is designed on a grid, and Link is literally just moving into the next square when the button is pressed, but since he doesn't pause between squares when the button is held, he moves across multiple squares flawlessly, giving the appearance that he's walking normally. This is used in a few games, some titles to name would be Pokémon and Final Fantasy Mystic Quest.

The grid movement works like this(Lets just say your grid is 16x16):

Give your character(let's say it's Link) two internal values, one for column(horizontal square), one for row(vertical square). Let's say these are Value A for column and Value B for row. Give him a third value which will store how many pixels he has to move to reach the next square. We'll say that one's Value C.

Firstly we add the events for each direction. Let's start with right. Add the event "Repeat while user presses right"(arrow keys, joystick, whichever you choose), and add with that "+ Value C = 0". Then in the actions, add 1 to Value A and set Value C to 16.

Do the same for left, and the same again for up and down only adding 1 to value B instead. This will then remember which square Link is in rather than his actual co-ordinates.

Now to make him actually move to the square. This is where Value C comes in. The reason we set Value C to 16 is because it's going to count down as Link moves a pixel. Then he will only move if Value C is 0 because that way it can only tell him to move to the next square once he has reached the current square. Make sense? Here's what we do to actually move him:

X position of Link < Value A * 16 (You may want to add -8 or a similiar value depending on Link's size and hot spot position to the end of this to ensure he's in the middle of the square rather than the top-left corner of it.) + Value C > 0: Set X position of Link to X position of Link + 1, Subtract 1 from Value C.

X position of Link > Value A * 16 + Value C > 0: Set X position of Link to X position of Link - 1, Subtract 1 from Value C.


Y position of Link < Value B * 16 + Value C > 0: Set Y position of Link to Y position of Link + 1, Subtract 1 from Value C.


Y position of Link > Value B * 16 + Value C > 0: Set Y position of Link to Y position of Link - 1, Subtract 1 from Value C.

I hope you can make sense of that. Basically it works out Link's actual X/Y co-ordinates by multiplying his actual grid co-ordinates by the size of the grid squares, and if he's not at those co-ordinates, it will move him to them. Value C ensures that he doesn't move another square across until he's reached the current one, but since the event is "repeat while button pressed" rather than "button pressed" he will continue to move the instant he reaches the square, creating the "sliding" motion you wished for. Also, this way, Link's grid co-ordinates are conveniently stored in two of his values should you need to retrieve them later.

A nice effect in this kind of engine is to then have invisible detectors which sit around Link, in just the right position so they're one square away from him, and to then not allow him to move another square if overlapping an obstacle.

Hope I helped.

 
http://www.fzgames.com

The Chris Street

Administrator
Unspeakably Lazy Admin

Registered
  14/05/2002
Points
  48488

Game of the Week WinnerClickzine StaffAcoders MemberKlikCast StarVIP MemberPicture Me This Round 35 Winner!Second GOTW AwardYou've Been Circy'd!Picture Me This Round 38 Winner!GOTM December Third Place!!
I am an April FoolKliktober Special Award Tag
18th February, 2005 at 11:47:02 -

If you have MMF 1.5, here's an engine I made ages ago:

http://www.klikacademy.com/circy/tutorials/rpgengine.zip

 
n/a
   

Post Reply



 



Advertisement

Worth A Click