Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Animate movement in a grid?

Author
Message
Fluorescent
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 7th Jan 2015 19:35
I've made a simple clone of the classic game Sokoban. And the player moves in a grid, just like in the original.

I'm moving the player using the really simple formula
x# = gridX# + tileWidth# * gridx
Where gridX# is the place where the grid starts on the screen, tileWidth# is obviously the width of a grid tile and gridx is the number of the column in the grid. And I have the same for Y.

The player is snapped to the grid, it works great. But in one frame the player has moved to the adjacent tile and I think that I want to animate the player walking between the tiles. At the same time I don't want the player to be able to change direction when he is between to tiles so the character is no longer snapped to the grid.

I'm note sure how to solve this, does anybody have a suggestion on how this is accomplished?
The Weeping Corpse
12
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 8th Jan 2015 00:30
Hi, you can move the player sprite via a tween in small steps (pixels) from one tile to the neighboring tile.

CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 8th Jan 2015 11:29
You could try using a positioning tween to move the sprite from one point to another. Look up:
SetTweenSpriteX
SetTweenSpriteY
PlayTweenSprite
and
UpdateAllTweens

Fluorescent
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 8th Jan 2015 16:33 Edited at: 8th Jan 2015 17:56
The tween functions seems to be a great way to solve this. But they don't use the offset of the sprites do they? I'm assuming that I am placing my sprites using the SetSpriteXByOffset and so on.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 9th Jan 2015 10:42
You could try manually adjusting the offset e.g.:
SetTweenSpriteX( tweenID, beginX-offset, endX-offset, interpolation )
Default offset would be half the width of your sprite.

Login to post a reply

Server time is: 2024-05-06 05:06:12
Your offset time is: 2024-05-06 05:06:12