Tile movewment with transition animation

0 favourites
  • 4 posts
From the Asset Store
slide the tiles to fill the board.60 awesome levels.
  • 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.

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

    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"

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)