I'm really struggling with the global variables...or I assume that's my problem.
I'm trying to implement a scrolling background by using animated sprites (14 frames at 10fps) that move x values using 'swap' at certain frame values. Once the animation completes (frame = 14), the tile should remove itself. Frustratingly, when I capture the frame of the tile instance using frame event.x,event.y
, the variable is global and all instances of the sprite appear to execute based on a single instances value.
Additionally, tiles instantiated using swap
appear to not always start on frame 0. My logging shows a mixed bag that leads me to believe there is a global inaccessible clock that manages sprite frames. I've tried getting around it by forcing frame 0
immediately after swap, but it seems ineffective.
The code below is called every other frame by the main game script's loop
event (every other frame because game is at 20fps and tile animation is at 10fps). Any insights would be much appreciated.
on moveUpFingers do
// capture current instance frame
fUpFrame = frame event.x,event.y
log "Current up finger frame = {fUpFrame}"
if fUpFrame==14 then
// if on final frame, remove animated tile by swapping with blank
log "removing up finger at {event.x},{event.y}"
tell event.x,event.y to
swap "white"
end
elseif event.x!=0 then
if fUpFrame==7 then
// if at right frame, draw new tile to the left to show continuous scrolling animation
newUpX = event.x
newUpX -= 1
tell newUpX,event.y to
log "instantiate new up finger at {newUpX},{event.y}"
swap "FingerUp"
frame 0
end
end
end
end