News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Double buffer on CPCTelera

Started by ivavilagu, 16:13, 23 February 24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ivavilagu

I´m just making my first game with double buffer in CPCTelera. I just implemented double buffer in two blocks of 8K each. The simplified code:


While(1){

move player
animate player

   switch (cicle++ % 2)
   {
    case 0:
         move enemy A
         animate enemy A
   
     case 1:
         move enemy B
         animate enemy B
    }

cpct_waitVSYNC()

draw player
draw enemy A
draw enemy B
}

As you can see, player moves and draws every cycle.
Enemies moves every two cicles and draws every cycle.

My question is about enemies. Cicle 0 moves and draw enemy A. Cicle 1 only draws enemy A, even thought it hasn´t move.

Is there any way to avoid this second draw? With only one screen is easy but with double buffer I think I am obliged to draw each cycle

EgoTrip

Don't forget to break each case in a switch statement, otherwise it will do them all until it encounters a break.

lightforce6128

This is a tricky question. It would be nice to spare the time for the second drawing. But I agree: With a double buffer this is not possible. You have to draw two times, one time for each buffer. Because the enemy sprite moves after two steps, you have to redraw both buffers. So each drawing is only visible in one frame and cannot be reused in the next frame.

If there are not too many sprites and the sprites are not too big, you maybe can draw them synchronized to screen refresh without a double buffer. Then it would be possible to reuse already drawn sprites. But I'm uncertain if timing allows to do this. If the synchronization breaks anywhere, the sprites will start to flicker.

ivavilagu

Quote from: lightforce6128 on 21:38, 16 March 24This is a tricky question. It would be nice to spare the time for the second drawing. But I agree: With a double buffer this is not possible. You have to draw two times, one time for each buffer. Because the enemy sprite moves after two steps, you have to redraw both buffers. So each drawing is only visible in one frame and cannot be reused in the next frame.

If there are not too many sprites and the sprites are not too big, you maybe can draw them synchronized to screen refresh without a double buffer. Then it would be possible to reuse already drawn sprites. But I'm uncertain if timing allows to do this. If the synchronization breaks anywhere, the sprites will start to flicker.

I have decided to use double buffering to have a considerable amount of sprites, allows me to avoid flickering and not to fight with drawing synchronism.

For now it doesn´t slow down.

Powered by SMFPacks Menu Editor Mod