
I'm hoping someone out there can help me solve the ever increasing speed of my bird animation. The goal is to have the ability to put these bird sprites (spr 39 is the static resting bird sprite) all over the map and as the player gets close to them they are disturbed and fly away. A counter ("birds") counts them and this counter is used to alter states later in the game. Everything is working except that every bird that is disturbed flaps it's wings faster than the previous bird. Any attempt to reset this just results in the bird not animating at all and floating away motionless which is kind of comical. :P

My update and draw code for these bad bois are below. Any ideas as to how I could get them to fly away at the same animation speed regardless of how many have been disturbed? Newish to coding in general here so I'm probably going about this the wrong way. FYI, sprite 39 and 19 are both static versions of the bird depending on the background they sit in front of.
--birds--
function u_bird()
-- btimer=0
for y = flr(p.y/8)-1,flr(p.y/8)+1 do
for x = flr(p.x/8)-1,flr(p.x/8)+1 do
if mget(x,y)==39 or mget(x,y)==19 then
add(fly,{
ex=x8,
ey=y8,
sp=39,
})
if mget(x,y)==39 then
mset(x,y,59)
elseif mget(x,y)==19 then
mset(x,y,38)
end
birds+=1
end
end
end
for e in all(fly) do
e.ey-=.5
e.ex+=.2
e.sp=birdsp
if birdsp<43.9 and birdsp>=40.1 then
birdsp+=.1
else
birdsp=40.1
end
end
end
function d_bird()
for e in all(fly) do
spr(birdsp,e.ex,e.ey)
end
end



I can't completely tell but it looks like your birdsp
is global, so that one value is updated for each active bird and applied to all birds. Set each bird's e.sp
directly using your conditional (based on that bird's e.sp
and not the global) and then use that in your spr call, spr(e.sp,e.ex,e.ey)



still learning the core concepts over here. Thank you kozm0naut!

[Please log in to post a comment]