Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Snapshot Optimisation Problem - Moving images between group and canvas
Started by tap32 Mar 04 2014 06:23 AM

No replies to this topic
graphics 2.0 canvas snapshot group
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Contributor

  • 257 posts
  • Corona SDK

I've just run my game through Corona Profiler, and the overriding feedback is that the following line of code is horrifically slow:


    local g=snapshot.group
    local c=snapshot.canvas
    for i=g.numChildren, 1,-1 do
      c:insert(g[i]) -- <-- The offending line 


I assume this is because both groups are changing size as objects are removed from one list and added to the other. As far as I can see, this could be solved by having an extra canvas mode in which objects from the canvas remain in the canvas group after the invalidate, or by having a single function to shift all items from one group into another (though beyond this use case where you want to return former canvas items to the group I can't see a use for it).


What am I trying to do? Basically I am trying to use the canvas to create a firework effect. So each frame I update the firework particles positions, fade the trails already on the canvas, add the particles back to the canvas and call invalidate. That last call chucks all the particles into the canvas's group, so next frame I have to fish them out again.


Can anyone think of any ways around this?