Turning whatever's on the screen into an image
BlitzMax Forums/BlitzMax Beginners Area/Turning whatever's on the screen into an image
| ||
Here's what I'd like to do. Let's say you're playing a game and then you press pause. Here's the pause loop: repeat cls drawimage (What the game looked like before they hit PAUSE),0,0 drawtext,"PAUSED",in the center ;) flip until someone unpauses the game ;) Any ideas? :) |
| ||
Why make it so complex? if you don't cls and don't flip then the screen will stay the same anyway. Select GameState CASE RUNNING Cls ' DO all my game Stuff Flip If KeyHit(KEY_P) Then GameState = PAUSED DrawText("Oi Oi",300,300) FLIP EndIf CASE PAUSED If KeyHit(KEY_P) Then GameState = RUNNING End Select |
| ||
Oh right! But what if I was making a simple text box that appeared over my editor? and instead of clearing the screen it would look better if the text box just appeared and let you typed in some input? obviously we would need to clear the screen then right? |
| ||
if you don't cls and don't flip then the screen will stay the same anyway. This isn't possible on my computer. (Is it the same on all macs/minimacs?) The screen flickers, and old graphics that got overdrawn is sometimes visible. (Edit: but only in fullscreen) My method is a bit different. I alsways separate logic and drawing in my code, and when the game is paused it doesn't run the logic part. Like so: while not gameover if not paused run_logic() endif draw_graphics() wend |
| ||
But if you really needs to save the screen sometime, you can use GrabImage() or GrabPixmap() |
| ||
Yeah as deps says, either have a separate draw function (from logic) and call it even when paused OR when paused is pressed, grabimage the screen to a large image you've created and in pause mode show that behind the dialog every frame. You can also do tricks then like dimming the background image so it looks cool. |
| ||
hmm, I've never thought of seperating my code in such a way. Up untill now I would update everything ie. draw images and update logic in the same function or method. |
| ||
well Amon it's time to change as that is definitely the way to go! |
| ||
What deps and GA say--separating your drawing, animating, positioning and collision code into distinct functions is a good way to do this. Using this technique also makes it easier to do multi-pass game logic between draw commands (that is, you move everything at 1/4 speed but update 4 times between flips, which gives you more accurate collision detection...) |
| ||
I generally have the update/movement and draw as seperate functions that way when you pause you can continue to draw everything in game without moving and can draw text or whatever you want over the top as you like. |