I’m trying to implement my own caching system. I have a situation where I need multiple copies of an image, scaled to a particular value.
Doing this is slow:
[lua]for i=1,10 do
local image = display.newImageRect(imageName,width,height)
image.y = (i-1)*(height+margin)
group:insert(image)
end[/lua]
Notice that I’m just inserting 10 copies of the same scaled image into the group. Calling newImageRect 10 times is slow.
What I’d like to do is somehow cache a single image, then make 10 copies of it. Something like this:
[lua]local imageCache = display.newImageRect(imageName,width,height)
for i = 1,10 do
local image = copy of imageCache
image.y = (i-1)*(height+margin)
group:insert(image)
end[/lua]
This would load and scale the image once and then just make copies of it.
Now, if a display object was just a normal LUA table, then I could create a Copy function that just looped through the keys. But I know that Display Objects are special. So is there any way to do this? [import]uid: 12529 topic_id: 7153 reply_id: 307153[/import]