Posted: 26th Aug 2011 22:46
Hi everyone,

So I've been learning AppGameKit since the release, and have been blown away by it. I've been lurking here in the forums and also reading the documentation, and even visited the chat room and coupled with this great language/tool it's got me more excited to learn and eventually master something than I've been in a long time. I just wanted to thank everyone at TGC and in the community before asking my question.

Anyhow, I know this is probably bonehead simple, so I beg your indulgence. Below is the code I've put together for the player sprite in my game. The game is a vertical shooter (maybe I should call it "Yet Another Shooter"?) and I've created 7 frames of animation for it. 3 frames to bank left, 3 frames to bank right, and a center frame. I have no trouble creating the sprite and locking it to the center frame... but I can't get it to animate correctly when it gets player input to move the sprite. Instead, with the current code I've got the plane stays locked to the center frame, only randomly choosing to animate before snapping back to the center frame.

Here's the code, any tips or pointers would be greatly appreciated, thanks in advance!

+ Code Snippet
function Create_Player_Plane ( )

    planex# = 247
    planey# = 750
    PlaneStart# = 4
    PlaneEnd# = 4

    CreateSprite ( 5, 0 )
    setspritesize(5,146,186)
    SetSpritePosition ( 5, planex#,planey#)
    AddSpriteAnimationFrame ( 5, LoadImage ( "SuperSaber_01.png" ) )
    AddSpriteAnimationFrame ( 5, LoadImage ( "SuperSaber_02.png" ) )
    AddSpriteAnimationFrame ( 5, LoadImage ( "SuperSaber_03.png" ) )
    AddSpriteAnimationFrame ( 5, LoadImage ( "SuperSaber_04.png" ) )
    AddSpriteAnimationFrame ( 5, LoadImage ( "SuperSaber_05.png" ) )
    AddSpriteAnimationFrame ( 5, LoadImage ( "SuperSaber_06.png" ) )
    AddSpriteAnimationFrame ( 5, LoadImage ( "SuperSaber_07.png" ) )
    PlaySprite ( 5, 10, 0, PlaneStart#, PlaneEnd#)

    PlaySound (1,40,1)

endfunction

function Move_Player ( )

    multiplyer# = 6

    if (oldplaney# < GetDirectionY ( ))
        multiplyer# = 3
    endif

    if (oldplanex# < GetDirectionX ( ))
        PlaneStart# = 4
        PlaneEnd# = 1
        PlaySprite ( 5, 10, 0, PlaneStart#, PlaneEnd# )
    endif

    planex# = GetSpriteX(5)
    planey# = GetSpriteY(5)
    planex1# = GetDirectionX ( )
    planey1# = GetDirectionY ( )

    planex2# = planex# + planex1# * 6
    planey2# = planey# + planey1# * multiplyer#

    setspriteposition(5,planex2#,planey2#)
    oldplaney# = planey2#
    oldplanex# = planex2#

endfunction
Posted: 27th Aug 2011 2:57
Your probably have your animation playing over and over and reseting it before it gets chance to animate. Try putting an if getifspriteplaying(5)=0 endif around your playsprite command.
Posted: 27th Aug 2011 6:19
Thanks DVader, progress has been made, and the sprite is now animated!

However now I fear it's looping the animation. Without any player input the plane will first continually bank right for a while, then left for a while, then back to the right, etc.

Here's the current implementation of the move function... I suspect I am comparing the wrong variables to determine if the plane should animate or not... I appreciate any tips or advice:

+ Code Snippet
function Move_Player ( )

    multiplyer# = 6

    if (oldplaney# < GetDirectionY ( ))
        multiplyer# = 3
    endif

    if getspriteplaying(5)=0
        if (oldplanex# = planex#)
            PlaneStart# = 4
            PlaneEnd# = 4
        elseif (oldplanex# < planex#)
            PlaneStart# = 4
            PlaneEnd# = 1
        elseif (oldplanex# > planex#)
            PlaneStart# = 4
            PlaneEnd# = 8
        endif
        PlaySprite ( 5, 10, 0, PlaneStart#, PlaneEnd# )
    endif

    planex# = GetSpriteX(5)
    planey# = GetSpriteY(5)
    planex1# = GetDirectionX ( )
    planey1# = GetDirectionY ( )

    planex2# = planex# + planex1# * 6
    planey2# = planey# + planey1# * multiplyer#

    setspriteposition(5,planex2#,planey2#)

    oldplaney# = planey2#
    oldplanex# = planex2#

endfunction
Posted: 27th Aug 2011 18:23
Well it does seem a little overcoded for player movement. Why not simply check for your input direction, -1, 0 or 1 and set the anim for that rather than this oldplane# business?
So something more in the lines

y#=getdirectiony()
x#=getdirectionx()
if x#=0
playsprite......
endif
if x#>0
playsprite..
endif
if x#<0
playsprite..
endif

The same for the y axis. You could use a case statement if you don't like so many if endifs.

I haven't tried or even looked if there is a command to set the frame rather than play through them in AppGameKit yet. But for what you are doing it may be easier. Then you can simply move up and down through the frames, dependant on what frame you are on and what direction you press.
So if you are pushing left, and it is at it's lowest frame of 1 and you press right, it will inc through all the frames until it gets to 8. If you let go at this point it will inc through until it centers. Do the same for the right and you should be set.
Posted: 27th Aug 2011 20:02
Thanks again for your help DVader, I will try what you suggest and report back my results!
Posted: 30th Aug 2011 0:45
Any success?