I have the following problem.
I'm trying to make sprite animated. However, the sprite-animation works, I tested AddSpriteAnimationFrame and SetSpriteAnimation.
However, somehow it doesn't work for me to move the character in a certain direction and playing while this the animation selected frames. I wrote a scrappy code for rapid testing. However, the animation is often triggered when the event (KeyState) already happened
and GetRawKeypressed is as it seems after it got pressed and not while it get pressed. GetLastKey thing also wasn't helpful. Very annoying there is no built-in explanation..
So, I tested different events because GetRawKeyState 1 / 0 returns didn't work. But there are only GetRawkeypressed and keyreleased else there and they also didn't work using the right return-code check.
However, I edited multiple parts of the code again and again for testing, so now it's a bit a mess:
function Bewegung_Hauptspieler(SpielerspriteObjekt)
Spielerbild = SpielerspriteObjekt
KoordX = GetSpriteX(Spielerbild)
KoordY = GetSpriteY(Spielerbild)
//LoadImage ( 1, "CharAnim_links.png" )
remstart
3.Mai 520
W - A - S - D | Ref. GDs>ScanCd
(GetKeyboardExists)
remend
if GetRawKeyState(65) = 1
PlaySprite ( Spielerbild, 3, 1, 1, 7 )
//StopSprite(Spielerbild)
SetSpritePosition(Spielerbild, KoordX-5, KoordY) // A
//StopSprite(Spielerbild)
endif
if GetRawKeyState(68) = 1
PlaySprite ( Spielerbild, 3, 1, 8, 15 )
SetSpritePosition(Spielerbild, KoordX+5, KoordY) // D
//else
//StopSprite(Spielerbild)
endif
// W
if GetRawKeyState(87) = 1
SetSpritePosition(Spielerbild, KoordX, KoordY-5)
if GetRawKeyState(65) = 1
SetSpritePosition(Spielerbild, KoordX-5, KoordY-5)
endif
if GetRawKeyState(68) = 1
SetSpritePosition(Spielerbild, KoordX+5, KoordY-5)
endif
else
StopSprite(Spielerbild)
endif
// S
if GetRawKeyState(83) = 1
SetSpritePosition(Spielerbild, KoordX, KoordY+5)
if GetRawKeyState(65) = 1 then SetSpritePosition(Spielerbild, KoordX-5, KoordY+5)
if GetRawKeyState(68) = 1 then SetSpritePosition(Spielerbild, KoordX+5, KoordY+5)
endif
endfunction
(gets called in do loop)
Btw as you see I try to move sprite without physics so just using SetSpritePosition. Does it even work to play animation DURING position change? As I tried different solutions the animation the result stayed the same.. the animation starts after I released the key.
But doing a if GetRawKeyReleased = 0 within getrawkeystate didnt work. Is this relevant to the reason that the loop & this function is called every 60 frames? Not, right? Unfortunately they didn't show in help how to use different direction animation combined with controls.