Drawingsurface (How to refresh/update background?)

Started by TMuh, Sat 13/07/2013 12:01:31

Previous topic - Next topic

TMuh

Im doing level editor for my tilebased game. Level is drawn to the background and then exported as a bmp file. The problem is that one command in the editor is supposed to fill entire background with the selected tile graphic. Drawing works fine but the background doesnt update. I can update background by using wait command between code but id like to know if there is more proper way to do it. And id like to understand how drawingsurface works and why it doesnt update background rightaway.

Without wait command background updates only if I for example move character on the screen and the area where character moves is updated.

if (keycode == eKeyCtrlF) {
ViewFrame *frame = Game.GetViewFrame(CURSORVIEW,  0, 0);
DrawingSurface *mainBackground = Room.GetDrawingSurfaceForBackground(0);
int tx = 0; int ty = 0;
while (ty < 480) {
  while (tx < 640) {   
    mainBackground.DrawImage(tx, ty, frame.Graphic);
    //Wait(1); IT WORKS IF I USE WAIT COMMAND HERE BUT IT SLOWS THE EDITOR
    tx = tx + 32;
  }
  tx = 0;
  ty = ty + 32;
}
mainBackground.Release();
}

Khris

Whenever you're drawing something to a drawing surface, you're not changing the screen, you're just changing the part of the RAM that stores the DrawingSurface. Only when the next game loop arrives, and the engine redraws the screen, changes become visible. Calling Wait(1); will run one game loop and update the screen.

There are a couple of solutions here: move the Wait() command to the outer loop, or increase the Game's Speed: SetGameSpeed(120); (default is 40). Or do both.

TMuh

Thanks for quick reply. Moving wait to outer loop did the job.

SMF spam blocked by CleanTalk