I need to draw many circles on the screen, but I never need to modify their postion, transform them, change their color, etc. I just need to draw them and for them to stay visible until something else draws over there.
I am currently doing this with display objects but very quickly my droid x is getting bogged down. Is there a trick to do this? Perhaps to draw without objects?
[import]uid: 9562 topic_id: 3458 reply_id: 303458[/import]
Hi,
I have not tried this on a device, but I tried to see how Corona handled a number of objects.
local random = math.random
local maxObjects=50000 --- Play with this
local currentObject = 1
local startDeleting = false
local holdObject={} --- Array/Table that holds the objects
local newObject
local tempObject
drawObject = function(event)
local x
local y
if event.phase == "ended" then
x = event.x
y = event.y
newObject = display.newCircle(x,y,10)
newObject:setFillColor(random(1,255),random(1,255),random(1,255))
if startDeleting then
tempObject = holdObject[currentObject]
tempObject:removeSelf()
end
holdObject[currentObject] = newObject
currentObject = currentObject+1
if currentObject\>maxObjects then
startDeleting = true
currentObjects=1
end
end
end
--Create the maxObject number of circles on screen, optional to test
local i=1
while i \<= maxObjects do
local x = random(0,display.contentWidth)
local y = random(0,display.contentHeight)
newObject = display.newCircle(x,y,10)
newObject:setFillColor(random(1,255),random(1,255),random(1,255))
holdObject[i] = newObject
i = i+1
end
startDeleting = true
Runtime:addEventListener("touch", drawObject)
The other thing was, if your circles are the same size, have you tried making it a sprite? I think sprites are pretty optimised on Corona.
cheers,
Jayant C Varma [import]uid: 3826 topic_id: 3458 reply_id: 10408[/import]
Sorry jtal… 4000 -8000 sprites on an idevice… that is out of this world. We are talking about mobile devices here, not desktop computers.
Images are faster than a circle primitive but still. You need to reduce your app specs seriously. [import]uid: 5712 topic_id: 3458 reply_id: 10418[/import]
Mike, I dont need thousands of sprites…I just need to draw thousands of shapes. It is not unreasonable at all. I dont need to ever access them again, because I’ll never need to transform them in the future or even remove them.
In java I just draw to a bitmap and display the bitmap on the screen- it works fine and many apps do this- imagine a maze app where the path of your finger is drawn to the screen, or a paint program.
I’m really excited to use Corona, but so far I’ve had two ideas for games and both of them have been foiled by very basic problems. This one, and the other documented here: http://developer.anscamobile.com/issues/3150
In all fairness, this software is marked “alpha”. [import]uid: 9562 topic_id: 3458 reply_id: 10421[/import]
What Corona could really use is a way to draw to a bitmap, manipulate it (crop, resize, recolor), and save it to use as a sprite.
[import]uid: 9659 topic_id: 3458 reply_id: 10424[/import]