Copy / reuse image multiple times

Hi,

I’m developing a game (sort of a pac man clone) and around the map there are about 800 “pills” - what’s the most efficient way of drawing these?

In obj-c I used to be able to load a single texture and on each screen refresh draw the one texture to all the required positions.

In corona this seems to slow down slightly when running on a device as I’m effectively drawing 800+ sprites (all loaded initially through multiple calls to display.newImage())

Any tips or thoughts for improving speed?

Thanks,

Mal
[import]uid: 13758 topic_id: 6708 reply_id: 306708[/import]

newSprite [import]uid: 6645 topic_id: 6708 reply_id: 23414[/import]

^ Absolutely useless answer.

If your level is bigger than the screen (srollable) there is no need to draw all 800 pills at once. I’d use a tile based map then and draw / remove pills dynamically depending if they are inside the visible screen area or not).

Otherwise I’d reduce the amount of pills since 800 objects are way too much to draw at once. [import]uid: 9644 topic_id: 6708 reply_id: 23417[/import]

it’s not a useless answer… i’d still advise using newSprite over newImage in this case.

[import]uid: 6645 topic_id: 6708 reply_id: 23422[/import]

Thanks for the replies, I’ll try newSprite and see if that improves it.

It’s not a scrolling map, so no optimizations there I’m afraid, I guess I’ll just have to see if I can figure any other workarounds.

Out of interest is there any benchmarking on corona and the number of sprites it can handle drawn to screen?

Cheers,
[import]uid: 13758 topic_id: 6708 reply_id: 23426[/import]

newSprite will give you benefits if you’re animating your pills etc since you just jump to a frame in the texture (spriteSet), otherwise if you were using newImage, you’d have to remove the image and display a new one. I’m not actually sure how much optimization using newSprite over newImage gives you for single static images. (newImage is cached to texture memory once you load an image once anyway)

I don’t know how Corona’s renderer works compared to the obj-c opengl quad “blitting” you are used to.

I wonder if a feature request for a coordinate blit is worthwhile?

eg
[lua]local coords = {{10,10,1},{20,30,1},{50,50,3},{100,100,5}} – x,y,frame

local blitGroup = display.newBlit(spriteSheet, coords)[/lua]

do you normally have access to each item in the quad list after, or is like a static blit fill?

if you were using a grid system rather than a collision system then you wouldnt need access to each “pill” as such for collisions

just a thought anyway

[import]uid: 6645 topic_id: 6708 reply_id: 23429[/import]

Sorry, jmp, I misunderstood your post because I did not realize that you tried to point out that there should be a speed gain using sprites.

Anyway, I doubt that this will handle 800 screen objects at once, so I would focus on some code optimization instead. [import]uid: 9644 topic_id: 6708 reply_id: 23630[/import]