Dynamically create new room from application_surface?

B

bigtunacan

Guest
I would like to create a new room where I just capture the application_surface from my existing room into the new room. The idea then is to have a sort of "freeze" effect where I can draw on top of the new room, and then return to the original room with everything as it began.

I'm still relatively new to GM:S and I've read a few articles and help topics, but having a hard time wrapping my head around how to actually do this.
 
B

bigtunacan

Guest
Are you talking about creating a sprite from the application surface? Are you trying to do a menu effect or something?
Yes, that's exactly what I'm trying to do. I'm trying to do a menu that is stored in a separate room that will transition partly or totally over the game.
 
B

bigtunacan

Guest
Ok; so I looked at that documentation and I tried this, but it doesn't draw anything in the new room, I just get a black background.

In the game room that I'm going to transition out of I have this.

Code:
    global.spr_game_capture = sprite_create_from_surface(application_surface, 0, 0, window_get_width(), window_get_height(), false, true, 0, 0);
    room_goto(room_menu_start);
Then in the menu room I have this in the room creation code.
Code:
    layer_background_create("bg_layer_menu_start", global.spr_game_capture);
 

Simon Gust

Member
Consider this ->
upload_2018-12-14_8-47-38.png

In what event do you have that code written?
Make sure that the surface is copied after everything has been drawn to it in that frame.
 
B

bigtunacan

Guest
Thanks, I wasn't aware of that. Based on that, if I'm understanding it correctly, then It should go in the "Draw end" event. I tried that with the same code I have, but the results are the same.
 

CMAllen

Member
Without seeing where you're placing your code and what you're doing, it's difficult to say what you're doing wrong.
 
B

bigtunacan

Guest
I have this in my Draw End event in the game room that I'm transitioning out of.

Code:
    global.spr_game_capture = sprite_create_from_surface(application_surface, 0, 0, window_get_width(), window_get_height(), false, true, 0, 0);
    room_goto(room_menu_start);
Then in the room_menu_start create code I have this.

Code:
    layer_background_create("bg_layer_menu_start", global.spr_game_capture);
 

Joe Ellis

Member
MAn, I dont wanna seem arrogant, but this is such an easy thing to work out, ok, I seem arrogant, but hear me out! once you get used to the "application_surface", and certain view you can set.... ok sorryy just carry on learning! (I'm at a stage now where I can't relate to other people... sorry, I tried to help but the basic parts are blurry now, well... if anyone wants to ask me about things, feel free to message me! I've got alot of "very" complex things that you can discuss and learn with me, and this is in no way trying to get money from you (WOW what a refreshment!)) but basically I know how to create 3d models with gml, and render them, and several other things . wow i seem so arrogant, but I'm basically offering my help to anyone else who wants to do this
 

Relic

Member
The post draw event would be better than the draw end event, as Now the application surface is finished being drawn to, excepting GUI layer elements.

Any chance this background layer is being covered by another background layer that would be drawing over the top of it? Is the layer visible?

Edit: also, any chance scaling may be occurring? Creating a sprite the size of the window makes sense as the application surface is the size of the window. However, when you use this sprite as a background, it will be drawn in room coordinates, not application surface coordinates.- so your background sprite may just be in the centre/top left (not sure how it defaults) rather than filling the room.
 
Last edited:
B

bigtunacan

Guest
@Relic,

I've moved it to the Post Draw even like you suggested. For Windows I'm not using any scaling and it doesn't work there. The room that I'm using for my menu has only an empty background layer which I'm using to draw the game capture to and a controller object. Other than that it's still empty.

----------------

I made a few updates and this seems closer to what I need, but it still doesn't work properly.

I moved the code into the Post-Draw event like @Relic suggested.

I changed it to use surface_create and draw_surface instead.

With this, on Windows where I don't use any scaling, it ends up drawing now but everything moves up the screen a few pixels.

Then on Android there is an issue with scaling. For Android/iOS I'm using a resolution init script to scale my game and stored my post-resolution init width/height in global.ideal_width/global.ideal_height and then used those to create the surface, so I would have expected it to be ok, but the scaling looks to be about 4X wrong.


The updated code in the game Post-Draw event looks like this now.

Code:
if(sprite_index == spr_santa_dying) {
    if(os_type == os_android || os_type == os_ios)
    {
        global.scrn = surface_create(global.ideal_width, global.ideal_height);
    } else {
        global.scrn = surface_create(display_get_width(), display_get_height());
    }
    surface_copy(global.scrn, 0, 0, application_surface);

    room_goto(room_menu_start);
The, in the menu room's object controller step even I have this.

Code:
draw_surface(global.scrn, 0, 0);



surface_render.PNG surface_render_android.PNG
 
B

bigtunacan

Guest
It's been a few days since I posted with my current issue. I still haven't been able to resolve this so I'm bumping in the hope someone with a bit more experience will see and can help me out.

Thanks!
 

Rob

Member
MAn, I dont wanna seem arrogant, but this is such an easy thing to work out, ok, I seem arrogant, but hear me out! once you get used to the "application_surface", and certain view you can set.... ok sorryy just carry on learning! (I'm at a stage now where I can't relate to other people... sorry, I tried to help but the basic parts are blurry now, well... if anyone wants to ask me about things, feel free to message me! I've got alot of "very" complex things that you can discuss and learn with me, and this is in no way trying to get money from you (WOW what a refreshment!)) but basically I know how to create 3d models with gml, and render them, and several other things . wow i seem so arrogant, but I'm basically offering my help to anyone else who wants to do this
I don't think my puny brain could comprehend your greatness :(

It's been a few days since I posted with my current issue. I still haven't been able to resolve this so I'm bumping in the hope someone with a bit more experience will see and can help me out.

Thanks!
Did you try what the previous posters suggested? What problems did you run into afterwards and please post the relevant code if you did.
 
Last edited:
B

bigtunacan

Guest
@Rob Yes; I've tried all of the suggestions from previous posters as well as read more documentation and articles on the subject. When using sprite_create_from_surface, which was originally suggested here, I never could get anything to display. I literally just had an empty room with a background layer that's sole purpose was so I could draw my screen capture to it so I don't see how that could be an issue.

The other main suggestion was to move things into the post-draw event; that makes sense and I made that change, but was still just getting a black screen.

I found a couple of articles that suggest using surface_create instead of sprite_create_from_surface citing that surface_create is easier to use and more efficient (right now I'd settle for something that just works :))

So then I switched to the surface_create and that did get me further. The result is my two screenshots above. On Windows the surface is drawn, but it's X position is off a bit, which I don't understand since I'm capturing and drawing to the same size surface. On mobile it's much worse, the scale is way off. I'm not sure what's happening there, but I can say I'm using the scr_initResolution from Faux Operative Games (https://pastebin.com/er4iyVsf) to adapt my game to fit different resolution on mobile, so I assume this is somehow impacting it.
 
C

CedSharp

Guest
note that you might consider using surface_get_width/height instead of display_get_width/height. The surface might be scaled to fit the display. That could explain your size/offset issue.

I didn't read the whole thing so ignore this if I'm not relevant
 
B

bigtunacan

Guest
@CedSharp Thanks for that. Using surface_get_width/surface_get_height seems to be an improvement. Now mobile behaves the same as Windows. The scale is correct, but everything is still being shifted upwards for some reason that I can't determine.
 
Last edited by a moderator:

Joe Ellis

Member
I don't think my puny brain could comprehend your greatness :(.
I have something to confess, I have thing I like doing when I'm drunk where I pretend I'm someone else
and write something completely made up writing whatever some rediculous person would write.
I try to not do it on here, but it slipped out that time
I normally do it on youtube, cus it literally blends in with all the radical maniacs on there
 
  • Like
Reactions: Rob
Top