Posted: 5th Sep 2011 2:39
i am using this to load and setup and animate a sprite a woman walking

+ Code Snippet
//Load First PLayer
LoadImage (2, "woman_001.png")
CreateSprite (2, 2)

SetSpritePosition (2, 500, 240)
SetSpriteAnimation (2, 39, 98, 9)




now to make it animate i use

PlaySprite (2, 7, 1, 1, 9)

and to move the sprite around i use

SetSpritePosition (2, newX#, newY# )

however i noticed that i cant move the sprite around and have the walking animation at the same time. it will move the sprite to desitination then play the animation

even if using

PlaySprite (2, 7, 1, 1, 9)
SetSpritePosition (2, newX#, newY# )


or

SetSpritePosition (2, newX#, newY# )
PlaySprite (2, 7, 1, 1, 9)


is there a way to do it asynch so it can run both commands at once?
Posted: 5th Sep 2011 3:59
Without seeing your code, I'll hazzard a guess...

You have the PlaySprite() command inside the loop where the movement commands are.

PlaySprite() only needs to be called once, outside the loop. It runs by itself, until you tell it to stop.

It will play the same starting frame every time it is called. Then, when you stop calling it, the animation will play the rest of the frames.

So, in answer to your question, PlaySprite is already asynchronous.
Posted: 5th Sep 2011 4:49
here is the code i am using

+ Code Snippet
rem
rem AGK Application
rem

rem Landscape App
SetVirtualResolution (1024, 768)
SetDisplayAspect ( 4.0/3.0 )

// display a background
CreateSprite (1, LoadImage("gameboard.png"))
SetSpriteSize (1, 1024, 768)

//Load First PLayer
LoadImage (2, "woman_001.png")
CreateSprite (2, 2)

SetSpritePosition (2, 500, 240)
SetSpriteAnimation (2, 39, 98, 9)


global g_flagPlayerSelected = 1;
global sprite = 0
global flag = 0

rem A Wizard Did It!
do

    if (GetPointerPressed() = 1)

        // store the location of input
        x = GetPointerX ( )
        y = GetPointerY ( )

        if ( move = 0 )

            flag = 1
            move = 1

            // save the current position
            originalX# = GetSpriteX ( 2 )
            originalY# = GetSpriteY ( 2 )


            // work out the destination
            destinationX# = x
            destinationY# = y
            distanceX# = destinationX# - originalX#
            distanceY# = destinationY# - originalY#
            distanceFromAtoB# = sqrt ( ( distanceX# * distanceX# ) + ( distanceY# * distanceY# ) )

            if ( distanceFromAtoB# <> 0.0 )
                directionX# = distanceX# / distanceFromAtoB#
                directionY# = distanceY# / distanceFromAtoB#
            endif

        endif

    endif

    // check if it's okay to move
    if ( flag = 1 )

        // work out new location
        newX# = originalX# + directionX# * move
        newY# = originalY# + directionY# * move

        // increment our move variable as long as we haven't reached our destination
        if ( move < distanceFromAtoB# )
            move = move + 0.51
        else
            // reset variables
            move = 0
            flag = 0
        endif

        // start the walk animation
        animatePlayer(2)

        // update position of our sprite
        movePlayer(2, newX#, newY#)

    else
        StopAnimatingPlayer(2)
    endif


    Sync()

loop


function animatePlayer(spriteID as integer)
    PlaySprite (2, 7, 1, 1, 9)
endfunction

function StopAnimatingPlayer(spriteID as integer)
    StopSprite(2)
endfunction

function movePlayer(spriteID as integer, x as integer, y as integer)
    SetSpritePosition (spriteID, x, y)
endfunction


just as a side not though, if i comment out the
SetSpritePosition (spriteID, x, y)

it takes like 4 seconds til the animation truely starts animating. the file isnt to big i have it attached.

i guess what i dont understand is that the main game loop will always be running, from direct x past, its fairly easy to start animating a sprite then move it all at the same time, by doing much what i already have above.

thanks for the help


p.s. is there a equivelent to vb's doevents function that will force the animation to run while moving by using the above code?
Posted: 5th Sep 2011 4:56
opps never mind i realize what you meant, i put a flag showing it was curently animating so it would no longer call the PlaySprite command and now they both are in sync.

thanks