Tile movewment with transition animation

Get help using Construct 2

Post » Sun Oct 30, 2011 2:49 am

Hi Im new to C2 and I found the example from this post interesting. But I was wondering how to implement the same grid-like movement but you can see the player move between each square rather than just teleport between each grid.

Here are my thoughts:
When a directional key is pressed: An instance variables on the player (object to be moved) to store the 'target' X,Y coordinates to the next grid and for every 'n' ticks increment (or decrement) the players current direction until the players 'current' X,Y is equal to the target X,Y.

I think this might work but I was wondering if there was a more optimal way of implementing this tile movement. Also I want the camera to lock on to the player during this transition. Since I've only started using C2 I'm guessing that this is simply done in one of the attributes of the player, 'scrolling' is it?

I want to implement my game so that the player sprite is shown moving between two adjacent tiles with a duration of 0.5 seconds.

Thanks.
B
2
G
1
Posts: 5
Reputation: 460

Post » Sun Oct 30, 2011 4:53 am

This can probably be done with less events/values but here ya go.

http://dl.dropbox.com/u/17634050/GridMovement_1.capx

Er..think this is what you were talking about atleast ^^; Not sure what you want for the scrolling..sounds like a simple "Always set scrollx,y to player.x,y"

For continuous movement just replace "on key pressed" to "on key is down"Tokinsom2011-10-30 04:57:41
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Sun Oct 30, 2011 6:39 am

Hey thanks! Didn't expect a reply so soon. Your way of doing it much better. But when I added continuous movement with 'key pressed down' the sprite was slightly out of alignment with the grid. This meant that the timer was set to 16 while the sprite is moving between two squares and when it stops moving it is slightly out of place.

Any idea on how to set the timer so that the key held down does not reset the timer to while it is counting down?

Edit: We'll I sort figured out the problem, I also had to add the condition that the Timer <= 0 together with the 'Key Down' and I noticed that you subtracted the timer by dt*60 instead of 1, I think this is to set the speed of the movement (please confirm because I am not too sure) but it is also causing the sprite to be out of alignment by a pixel or two.smurfee2011-10-30 06:58:29
B
2
G
1
Posts: 5
Reputation: 460

Post » Sun Oct 30, 2011 7:21 am

Yyyyeah I was afraid that would happen with delta time. Thinking of a better way to do this..

edit: Wow, how embarrassing. I dunno man XD Delta time makes stuff like this way more complicated than it should be.

All I can think of is making an invisible 'base' that moves to the final location as soon as you press a key, then have the player move to it (and deactivate controls until it meets its destination). I tried doing it with just values, kinda like you mentioned earlier, but I couldn't get it to work; kept getting floating point values so it never properly met the destination. Using int() didn't help either.Tokinsom2011-10-30 07:47:35
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, SpartCrafter, Yahoo [Bot] and 25 guests