ZFGC

Resources => Coding => Topic started by: Martijn dh on July 04, 2009, 01:50:46 pm

Title: Turn current screen into background or other image?
Post by: Martijn dh on July 04, 2009, 01:50:46 pm
A Gamemaker question

Why:
In my game I want to create a better pause option. Before I did pause by running through all relevant objects, saving there current state and then stopping them. I didn't have pro so it seemed one of few available options. The drawbacks are that it's not efficient, not failprove and a pain to keep up as more objects are added to the game. I just got the pro addition and I'm working on a better sollution. I just haven't been able to get the bit below to work.

The problem:
I want to create a screenshot of the current screen and save it to a background (or object).

The reason for this is that I want to place that screenshot at depth X covering the current screen so that I can still place menu's etc in front of it while being able to deactivate all objects behind. I anybody thinks there is a more efficient/easier way to do something like this than be sure to drop a hint XD

Any help will be appreciated.
Title: Re: Turn current screen into background or other image?
Post by: Martijn dh on July 04, 2009, 03:06:24 pm
Never mind. I figured it out myself.

The pause script is now:
Quote
obj_Master_Control_Tile.Game_Mode = argument[0];
screen_save(temp_directory+'\tempscreen.bmp');
sprite_replace(842,temp_directory+'\tempscreen.bmp',1,false,false,false,false,0,0);
instance_deactivate_all(true);

// (Re)activate all the needed objects
instance_activate_object(parent_Control_Tile);
instance_create(view_xview[view_current], view_yview[view_current], obj_Screenshot);

The unpause script is now:
Quote
obj_Master_Control_Tile.Game_Mode = 0;
with (obj_Screenshot) {instance_destroy()};

// Reactive all instances
instance_activate_all();

Well that's the basis anyway. I left out the gamespecific / boring bits.
Title: Re: Turn current screen into background or other image?
Post by: noseblunt3 on July 04, 2009, 04:09:36 pm
You should check out this topic http://www.zfgc.com/forum/index.php?topic=1603.0 (http://www.zfgc.com/forum/index.php?topic=1603.0)
It explain how to do it with surface. Pretty useful.
Title: Re: Turn current screen into background or other image?
Post by: Martijn dh on July 04, 2009, 05:35:14 pm
Looks usefull. I don't get it (yet) since I've never before used surfaces, alpha's or draw events, but I'll be sure to take a closer look at it when I have some more time.
Title: Re: Turn current screen into background or other image?
Post by: Martijn dh on July 04, 2009, 06:47:32 pm
I just can't let this one go just yet. It works but I still don't get half of it.

Here is the code the guy in the other topic suggested:
Quote
s = surface_create(view_wview,view_hview);
surface_set_target(s);
draw_clear_alpha(c_black,0);
screen_redraw();
draw_set_blend_mode_ext(bm_inv_dest_alpha,bm_one);
draw_set_color(c_black);
draw_rectangle(view_xview,view_yview,view_xview+view_wview,view_yview+view_hview,0);
draw_set_blend_mode(bm_normal);
surface_reset_target();
instance_deactivate_all(1);

Here is the code I am using, that seems (?) to work just as well:
Quote
surface_screenshot = surface_create(view_wview[current_view], view_hview[current_view]);
surface_set_target(surface_screenshot);
screen_redraw();
surface_reset_target();
instance_deactivate_all(true);

Both codes looks more efficient then my own concoction since they do not require saving to an external file, changing a sprite's image and they have the option to later empty the used layer. You create a surface, draw the current screen onto it and use it as a replacement image during the drawing event of an object. I get that part.

So what do the lines do between my shorten code and the code above it? What is there added value?
Title: Re: Turn current screen into background or other image?
Post by: noseblunt3 on July 04, 2009, 10:28:25 pm
Quote
So what do the lines do between my shorten code and the code above it? What is there added value?
They draw a semi-transparent black rectangle on the screen, to give an impression of darkness.
Title: Re: Turn current screen into background or other image?
Post by: DJvenom on July 04, 2009, 10:32:58 pm
background_create_from_screen(x,y,w,h,transparent,smooth,preload) ?? or did GM7 remove that functipon?
Title: Re: Turn current screen into background or other image?
Post by: Martijn dh on July 05, 2009, 05:12:59 am
Okay, so that stuff is usefull for when you want to change the colors to empifice your pause mode.

DJVenom: You can still use it. It saves the screenshot into a background but the surface bit seems more practical now since backgrounds don't have variable depth. The background will either get behind my tiles or infront of my menu's.

Still it's good to know such functions exist. Thanks.

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved