Animating Piece Movement (Puzzle Game)
by Brian Krabach · in Torque X 2D · 05/28/2009 (7:23 am) · 3 replies
I'm working on a puzzle game (think Bejeweled) that incorporates the swapping of pieces. I have written the code to layout the board and have the ability to select and swap two pieces currently. Right now, I am simply making note of the position of each of the two pieces and then changing the position of the first to the position of the second and vise-versa. This works great, but it happens instantly - could someone point me in the right direction as to where I would look if I wanted to make the pieces slide into position over X seconds?
One thought I had was to store the SceneObject and the destination vector for each in a private variable and then check on ProcessTick to see if it had completed it's move or not, then increment it a little further on it's way if it had not reached it's destination. While this would most likely work fine when I'm just swapping two pieces, the problem will come when I reach my next phase and I'm moving a dozen or more pieces at once to fill in for pieces that have been removed.
Any suggestions? Am I making this too difficult?
Thanks!
One thought I had was to store the SceneObject and the destination vector for each in a private variable and then check on ProcessTick to see if it had completed it's move or not, then increment it a little further on it's way if it had not reached it's destination. While this would most likely work fine when I'm just swapping two pieces, the problem will come when I reach my next phase and I'm moving a dozen or more pieces at once to fill in for pieces that have been removed.
Any suggestions? Am I making this too difficult?
Thanks!
About the author
#2
Thank you for your quick reply, I will go ahead and create the component.
By the way, on another note (since I posted this elsewhere and it has not been addressed yet) - is there a good way to use a tilemap when creating a hex based layout? My puzzle game is hex based, so I wrote some utility code to create a virtual grid with 4x7 ratio boxes so that I could plot out individual pieces on the grid intersect points (using every other point, similar to a checkers board) and use a coordinate system ("1,1", "3,7", etc) instead of using the actual vectors. I would have done this with a tilemap, but did not see any way to allow the graphics for the tilemap boxes to overflow the actual box. Here is my original posting about it (and that has more detail and a screenshot).
Thanks,
Brian
05/28/2009 (5:06 pm)
John,Thank you for your quick reply, I will go ahead and create the component.
By the way, on another note (since I posted this elsewhere and it has not been addressed yet) - is there a good way to use a tilemap when creating a hex based layout? My puzzle game is hex based, so I wrote some utility code to create a virtual grid with 4x7 ratio boxes so that I could plot out individual pieces on the grid intersect points (using every other point, similar to a checkers board) and use a coordinate system ("1,1", "3,7", etc) instead of using the actual vectors. I would have done this with a tilemap, but did not see any way to allow the graphics for the tilemap boxes to overflow the actual box. Here is my original posting about it (and that has more detail and a screenshot).
Thanks,
Brian
#3
The short answer is no, not really. Torque X tilemaps are strictly rectangular. I have a friend making a game using a custom diamond shape tilemap. I'll try to poke him for some details on how he did it. I think I came across something on Gamasutra, too. But even still, there won't be any designer support for it, so all of your level definition work will need to be in straight XML.
John K.
www.envygames.com
05/28/2009 (9:31 pm)
Sorry for not repyling... too many threads to keep on top of ;)The short answer is no, not really. Torque X tilemaps are strictly rectangular. I have a friend making a game using a custom diamond shape tilemap. I'll try to poke him for some details on how he did it. I think I came across something on Gamasutra, too. But even still, there won't be any designer support for it, so all of your level definition work will need to be in straight XML.
John K.
www.envygames.com
Associate John Kanalakis
EnvyGames
In that game, there is a cursor-box that you use to choose your active cell. As you move that cursor, it slides to the next cell, rather than snaps (as if you replaced the tile).
How to:
1. Create your tilemap containing its pieces
2. Create T2DStaticSprite objects for the pieces that will move (off-screen)
3. Create a new component to perform the movement work, such as PieceMoverComponent
4. The component should have a public bool moving property, such as: IsMoving
5. The component should also have a Vector2 property for start and target position
6. Attach the mover component to pieces that should slide
7. When you want to move the piece, set the mover component to True
8. The mover should hide the parent tile piece, display the sprite in its place, then move that sprite from the start position to the target position in the ProcessTick() method, then hide the sprite and show the tile in its new position.
Again, you will need to create the piece mover component, it doesn't already exist in the Torque X framework.
John K.
www.envygames.com