Here is an excerpt from a game, I've removed all the artificial intelligence logic, the collision detection logic and the code that calculates object positions on the screen and the code for creating and deleting sprites and animating explosions, calculating attack and retreat vectors, and handling input from the remote.
There are two large bitmaps involved, both are 2048 x 720, which scroll on screen at different rates, and 21 animated sprites, plus a variable number of sprite missiles, they all move on the screen nice and fast on both the older model devices and the new devices, in full HD 1280x720 mode. There is no problem with anything missing after returning from the screensaver. As you can see, I'm swapping the buffers constantly:
while true
msg=wait(1, msgport) ' wait for a button press
if animtimer.totalmilliseconds() > 50 then
animtimer.mark()
compositor.animationtick(animtimer.totalmilliseconds())
end if
movex=processRemoteInput(msg)
screen.setalphaenable(false)
big2048oneRegion.offset((movex/2),0,0,0)
screen.drawobject(0,st,big2048oneRegion)
screen.setalphaenable(true)
big2048TwoRegion.Offset(movex,0,0,0)
screen.drawobject(0,epos,big2048TwoRegion)
playsprite.moveto(ps.posx,ps.posy)
for i=0 to maxobjects-1
es[i]=calcluateNewPositions(es[i],ps)
enemyspritearray[i].moveto(int(es.posx),int(es.posy))
next i
compositor.drawall()
screen.SwapBuffers()
end while
It is true, I'm not clearing the screen on each iteration, but I'm drawing each element in layers, first the non-alpha blended background, then the transparent background, both are 2048 x 720 and I draw them each time through the loop.
I think that what I said about "every 1/30 second" is probably inaccurate, but I am drawing them as fast as possible (notwithstanding that I'm using wait() which has a 10ms delay bug), and it works quite well, no problems with screensavers.
Hopefully this structure can be useful to you.
- Joel