Legacy GM Sprite from Surface doesn't include GUI

clee2005

Member
Hey all! I'm using sprite_create_from_surface in the create event of my pause object, but it doesn't include my GUI layer elements. I imagine this is by design (GMS design or limitation), but my question is how can I get a snapshot of everything on the screen? I need the GUI elements included.

Thanks!
 
J

joakimFF

Guest
have you tried to sprite_create_from_surface in the gui event or draw end that should work
 

clee2005

Member
Hey thanks, I should have written that. Yes, I did try the GUI and GUI END events. Same result - no GUI elements included.
 
J

joakimFF

Guest
but does the obj_pause object have a lower depth then the object drawing the gui?
 
A

Aura

Guest
Sadly if you are using application_surface to do that, you can't because the Application Surface does not include Draw GUI elements. So you'd have to use screen_save() and load it back with the help of sprite_add(). :3
 

clee2005

Member
Sadly if you are using application_surface to do that, you can't because the Application Surface does not include Draw GUI elements. So you'd have to use screen_save() and load it back with the help of sprite_add(). :3
Where do the GUI elements get drawn? They must be on another surface? Could I not merge the two somehow? Take a sprite of each, and then just overlap them (assuming the GUI sprite comes with Alpha)?
 
J

joakimFF

Guest
cant you just create your own surface draw the application surface on that and then manually draw the gui elements onto the new surface
 

clee2005

Member
cant you just create your own surface draw the application surface on that and then manually draw the gui elements onto the new surface
I suppose I could do that. I guess I hadn't started thinking about the work arounds yet... I was still holding out hope for a simple solution :) Thanks for the suggestion and your previous responses!
 
M

Mauldini

Guest
I'm also interested if there's another gm layer constant for what the GUI events draw to.

I'm using a shader that takes the contents of the application surface, warps them etc, and draws it to screen in the GUI layer. My issue is I either lose all my GUI drawn text/sprites with the shader drawing over them, or they draw after the shader w/o the shader effects.
 

clee2005

Member
Sadly if you are using application_surface to do that, you can't because the Application Surface does not include Draw GUI elements. So you'd have to use screen_save() and load it back with the help of sprite_add(). :3
Thanks so much @Aura ! Turns out that worked perfectly for what I needed. I'll have to test on the slower devices, cause I think the screen_save() and then sprite_add combo are a bit intensive, and might not be great on an iPad2... but so far it's exactly what I was looking for. Cheers!
 

clee2005

Member
This works great for the full screen games. I'm using views however, and screen_save() seems to get the entire application surface rather than a what's in the view... I tried screen_save_part as well. I didn't account for the view when I first posted this issue... so now it looks like I have to go back to a secondary surface and drawing everything to that, with the GUI elements and using sprite_create_from_surface ()
 
A

Aura

Guest
That's completely expected behaviour. It saves the complete display region and not just a specific section or view. screen_save_part() should do what you are aiming for IMO.

Code:
screen_save_part("save.png", view_xview[0], view_yview[0], view_xview[0] + view_wview[0], view_yview[0] + view_hview[0]);
 

clee2005

Member
That's completely expected behavior. It saves the complete display region and not just a specific section or view. screen_save_part() should do what you are aiming for IMO.

Code:
screen_save_part("save.png", view_xview[0], view_yview[0], view_xview[0] + view_wview[0], view_yview[0] + view_hview[0]);
Yeah, that's what I tried (although for the height and width I just used view_wview[0] and view_hview[0]). I now realize because I'm using a different port size from the view, it doesn't scale properly ... I ended up using @joakimFF's and @Aura's suggestion of drawing the GUI to another surface. Here's what worked for me in the end, in case it helps someone else :

Create Event of my pause object.

Code:
// Get the Application Surface (doesn't include GUI)
sPause = sprite_create_from_surface(application_surface,0,0, view_wview[0], view_hview[0], false, false, 0,0);

// Force all GUI to draw to another surface
surf = surface_create(display_get_gui_width(),display_get_gui_height());
surface_set_target(surf);
with (all) {
    event_perform(ev_draw,ev_gui_begin);
    event_perform(ev_draw,ev_gui);
    event_perform(ev_draw,ev_gui_end);
}

surface_reset_target();
sPauseGUI = sprite_create_from_surface(surf,0,0, view_wview[0], view_hview[0], false, false, 0,0);

instance_deactivate_all(true);
instance_activate_object(objController);
Draw Event :

Code:
    draw_sprite(sPause, 0, view_xview[0], view_yview[0]);
    draw_sprite(sPauseGUI, 0, view_xview[0], view_yview[0]);
EDIT : Oh and while this works it should be noted that you shouldn't call the event_perform(ev_draw,...) events outside of a draw event. So I'm going to look at re-working this to have it happen in the draw event of the Pause object.
 
Last edited:

RyanC

Member



Hi All,

I'm currently trying to capture a screenshot of my game for Android and tried just about everything but have not succeeded in taking an exact replication of the screen.

The desired image is on the right and the screenshot on the left of the image above. As you can see it has alpha issues.

screen_save() on Android uses the device width rather than the application surface so I only get a quarter of the game screen on my phone with quad HD display.

I've tried using the event_perform method described above and now I'm getting particles drawn without the correct alpha and the gui is also brighter when layered over the application surface, even if I use draw_surface(application_surface) instead of copying it. You'd think there was an easy way to snap the screen but this is a nightmare!

Any help greatly appreciated!
 
Last edited:
Top