Posted: 29th Aug 2011 23:44
I'm still getting to grips with AppGameKit and types etc and I have got stuck with deleting a sprite if the animation has finished.
The following functions are called in the main program loop.
The problem is only the latest explosion gets deleted, So if theres more than one explosion happening the earlier ones stop on the last frame and stop on screen.
Any help would be appreciated.
+ Code Snippet
function explosion()

for t = 0 to alive
    alive = alive + 1
if alive > 20 then alive = 1
for k = 0 to count
  count = count + 1
if count > 30 then count = 1
    if GetSpriteExists(bullit[count].id)
        if GetSpriteExists(monster[alive].id)
            if  GetSpriteCollision( (bullit[count].id), (monster[alive].id) ) = 1
                deletesprite (bullit[count].id)
                fx#=  getspritex (monster[alive].id)
                fy#=  getspritey (monster[alive].id)
                deletesprite (monster[alive].id)
                debris = debris + 1
                    if debris > 10 then debris = 1
                        (explode[debris].id) = createsprite (plode)
                        setspritescale ((explode[debris].id),.5,.5)
                        setspritey((explode[debris].id),fy#)
                        setspritex((explode[debris].id),fx#)
                        SetSpriteAnimation ( (explode[debris].id), 128, 128, 32 )
                        PlaySprite ( (explode[debris].id), 30, 0, 1, 32 )
            endif
        endif
    endif
next k
next t

endfunction

function updateexplosion()

for d = 0 to debris
    if GetSpriteExists(explode[debris].id)
        if getspriteplaying (explode[debris].id) = 0
            deletesprite(explode[debris].id)
        endif
    endif
next d

endfunction

Posted: 29th Aug 2011 23:54
Rewrite your update code as follows:
+ Code Snippet
function updateexplosion()

for d = 1 to debris
    if GetSpriteExists(explode[d].id)
        if getspriteplaying (explode[d].id) = 0
            deletesprite(explode[d].id)
        endif
    endif
next d

endfunction

You need to check your variables against your loop counter, not the value of "debris" as it currently stands.

You also need to start your loop from 1, as that's what you're resetting "debris" to when it becomes larger than 10.
Posted: 30th Aug 2011 0:19
Thanks for the code, understand that bit now.
It actually turned out that debris wasn't set as global.
I thought when you set a variable outside a function it is Global by default.