Hi I am trying to handle animations through coroutines:
I successfully did something, but I was wondering if it's possible to stop a coroutine from the outside.
Assuming a code similar to this one from
@Apollo14local rooster=Bitmap.new(rooster_tpack:getTextureRegion("rooster_1.png"))
stage:addChild(rooster)
function rooster:run()
for i=1,17 do
rooster:setTextureRegion(rooster_tpack:getTextureRegion("rooster_"..i..".png"))
Core.yield(true) --we can set delay Core.yield(.02) for example
end
rooster:run() --repeat again after one cycle of animation finished
end
Core.asyncCall(rooster.run) |
can we stop "on call" (ie. on mouse down) Core.asyncCall(rooster.run)?
I thought of inserting a condition to make the function return/break, but I haven't got the time to test it yet:
function rooster:run()
for i=1,17 do
rooster:setTextureRegion(rooster_tpack:getTextureRegion("rooster_"..i..".png"))
Core.yield(true) --we can set delay Core.yield(.02) for example
end
if stoprooster then
return
else
rooster:run() --repeat again after one cycle of animation finished
end
end |
Is there a better way to do it?
Thank you
Comments
@antix I don't have real proof to show yet, but I think it looks pretty awesome: in windows player I placed 500 instances of a 7 frame animation (two different animations sharing the same 30x30 textures) without lags at 60fps.
I don't know how would it perform in a real world though
I'll keep you posted, if this works I think I will share it
(but I guess you already skipped them in your real project)
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
I'd still like to know if the async method is better than an EnterFrame event method.
Preloading all the textures that we may need later would not keep some memory busy?
This will be quite quick and pre caching them yourself will be quicker as well, but I don;t think the performance gain would be significant unless you managed to get thousands of objects on screen at once.
maybe precaching looks worse, because there is a small delay while it is creating all the instances.
I have a prototype which can precache textures or not: can you suggest how to benchmark it "for real"?
paying attention to the fps shown in my windows player I'd say
1500 instances of the same animation
no precache: 58-60 fps
precache: 59-61 fps, showing a delay at the beginning, down to 45 fps
Reading the profiler outputs confuse me a bit, I attach them here if someone can read those better than me
thank you
I've tested 'getTextureRegion' vs 'pre-loaded value', attached gproj and profiler results.
If I understood Profiler correctly, pre-loaded values are 8-10x faster than getTextureRegion (383ms vs 4663ms).
(@pie I guess it's not 'texture pre-caching', it's only values pre-caching)
but I'm not sure if I understood profiler correctly, you'd better check it
and there will be no difference in the real projects anyway, cause we never need to load huge amounts of such values so frequently
Likes: pie, SinisterSoft
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
However for a small number of actors (say 200-500) the gain would maybe not be worth the time to code the changes
Likes: Apollo14
Likes: Apollo14, antix
https://deluxepixel.com