Draw over 30'000 circles?

Ok, so I’m playing around with DrawScript and I’m writing a LUA wrapper so that I can import images from Illustrator (through DrawScript) directly into Corona.

There might be another way to draw the objects but here is how I do it now:

I have an image with a lot of Bezier curves and I import them from a JSON file. After that I calculate the different points (through Rajendras excellent snippet: https://github.com/neostar20/Bezier-Curve-for-Corona-SDK/blob/master/bezier.lua ) and then I draw diffrent circles for all the different points and they are a lot.

Why do I do it like this? It’s because later on I draw up the image on the screen.

So, can I make it so it doesn’t consume to much memory as it starts lagging after a while?

I precache all the circles i.e. move them on-screen and then off-screen.

I’m trying out snapshot right now but it doesn’t seem to affect the performance that much.

Does anyone know how I can draw a lot of objects without the application lagging?

Thanks in advance,

Best regards,

Tomas

Hi Tomas,

Snapshot is probably your best approach, because it makes several objects into “one display object”. You won’t be able to add 30,000 objects to any app on any device, as that will severely overload the hardware. So, keep experimenting with snapshots, adding new objects to the snapshot and then removing the original object afterward.

Take care,

Brent

Hi Brent,

thanks for your reply.

So basically I should be able to do this:

  1. Create the snapshot (Now it’s double the screen size, will fix later so it’s anchored to the upper-left corner):

    snapshot = display.newSnapshot( 640, 960 ) snapshot.x, snapshot.y = 0, 0

  2. Create the dot, insert it into the group and delete the object:

    – Snapshot if ss ~= nil then ss.group:insert( self.dot ) ss:invalidate() timer.performWithDelay( 1000, removeSelf ) end

    local function removeSelf() self.dot:removeSelf() self.dot = nil end

But when I remove the actual object (self.dot) it’s being removed from screen.

Shouldn’t the object be deleted but it should still be visible through the snapshot?

Best regards,

Tomas

Best regards,

Tomas

Hi Tomas,

Unfortunately I’m not an expert with snapshots, but I think you can achieve this by using the snapshot “canvas” instead of the snapshot “group”. Perhaps the documentation on this can describe it all better:

http://docs.coronalabs.com/api/type/SnapshotObject/canvas.html

Take care,

Brent

Hi Brent,

Yeah,  I noticed that after playing around a little bit!

Thanks for your help,

Best regards,

Tomas

Hi Tomas,

Snapshot is probably your best approach, because it makes several objects into “one display object”. You won’t be able to add 30,000 objects to any app on any device, as that will severely overload the hardware. So, keep experimenting with snapshots, adding new objects to the snapshot and then removing the original object afterward.

Take care,

Brent

Hi Brent,

thanks for your reply.

So basically I should be able to do this:

  1. Create the snapshot (Now it’s double the screen size, will fix later so it’s anchored to the upper-left corner):

    snapshot = display.newSnapshot( 640, 960 ) snapshot.x, snapshot.y = 0, 0

  2. Create the dot, insert it into the group and delete the object:

    – Snapshot if ss ~= nil then ss.group:insert( self.dot ) ss:invalidate() timer.performWithDelay( 1000, removeSelf ) end

    local function removeSelf() self.dot:removeSelf() self.dot = nil end

But when I remove the actual object (self.dot) it’s being removed from screen.

Shouldn’t the object be deleted but it should still be visible through the snapshot?

Best regards,

Tomas

Best regards,

Tomas

Hi Tomas,

Unfortunately I’m not an expert with snapshots, but I think you can achieve this by using the snapshot “canvas” instead of the snapshot “group”. Perhaps the documentation on this can describe it all better:

http://docs.coronalabs.com/api/type/SnapshotObject/canvas.html

Take care,

Brent

Hi Brent,

Yeah,  I noticed that after playing around a little bit!

Thanks for your help,

Best regards,

Tomas