Hi People,
I am a complete newby to AppGameKit and am experiencing some issues with sprite animation.
I am just testing out controlling a sprite with key presses and want the sprite to animate when i do this.
I have a sprite setup with 4 animation frames. I can get it to animate on when one key is pressed but I want to be able to go left, right, up and down with animation.
My code is below
// Project: Test
// Created: 2015-07-22
// set window properties
SetWindowTitle( "Test" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
//Set key constants
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40
//Load background
CreateSprite( 1, LoadImage("background.png"))
SetSpriteSize( 1, 1024, 768)
CreateSprite(2, 0)
AddSpriteAnimationFrame(2, LoadImage("looking0.png"))
AddSpriteAnimationFrame(2, LoadImage("looking1.png"))
AddSpriteAnimationFrame(2, LoadImage("looking2.png"))
AddSpriteAnimationFrame(2, LoadImage("looking3.png"))
do
gosub control:
Sync()
loop
control:
if GetRawKeyState(KEY_LEFT)
if GetSpritePlaying(2) = 0
playsprite(2)
endif
SetSpritePosition( 2, GetSpriteX (2) -2, GetSpriteY(2))
else
if GetSpritePlaying(2) =1
stopsprite(2)
endif
endif
if GetRawKeyState(KEY_RIGHT)
if GetSpritePlaying(2) = 0
playsprite(2)
endif
SetSpritePosition( 2, GetSpriteX (2) +2, GetSpriteY (2))
else
if GetSpritePlaying(2) = 1
stopsprite(2)
endif
endif
return
I can see this type of code work with the playermovement project in the examples, but this uses the virtual joystick. Is it not possible to have the animation stop/start on multiple GetRawKeyState commands?
Any help would be appreciated.
Cheers
James