• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Create_Sprite_From_Surface

S

SlightlyAngryGMLUser

Guest
Hello,
I'm my past free time I have been making a game using Gamemaker Studio 1 and I would like to add an pause function. Because of the fact that I have a lot of different objects which are all inherently different I have searched for an easy solution where I do not have to add a lot of code to each object but where I could 'carpetbomb' them all with one function.

The function I came up with is the instance_deactivate_all() function and to unpause the instance_activate_all() function, which both work perfect. While everything is paused I would like to have a screenshot of the game in the background with the words paused on it. The word paused was easy enough to do, and the screenshot too, or so I thought.

Using the function Create_sprite_from_surface I made a sprite which i wanted to draw on the screen. However, it would always snap to the top left of the room, no matter if I used draw_sprite or draw_sprite_ext. Then I thought I would use an object and give it the screenshot as a sprite. That didn't work, because it still snapped to the top left of the room. When I give this object an arbitrary sprite, a yellow square for example, it however does appear in the middle of the screen, which it should. (This is because using the create_sprite function, i give the screenshot I create it's origin in the middle) Is there something dumb which I missed or is there something buggy with the Create_Sprite_From_Surface function?

The key_pressed(p) where the pause function is started
Code:
if instance_exists(obj_pause)
{
    with (obj_pause)
    {
        sprite_delete(spr_screenShot)
        instance_destroy()
    }
    instance_activate_all();
    view_visible[2] = false
    if instance_exists(obj_dash)
    {
        view_visible[1] = true
    }
    else
    {
        view_visible[0] = true
    }
}
else
{   
    if room = Town
    {
        if instance_exists(obj_dash)
        {
            global.xx = obj_dash.x
            global.yy = obj_dash.y
            view_visible[1] = false
        }
        else
        {
            global.xx = obj_player.x
            global.yy = obj_player.y
            view_visible[0] = false
        }
        instance_create(clamp(global.xx,480,544),clamp(global.yy,270,658),obj_pause);
        with (obj_pause)
        {
            spr_screenShot = sprite_create_from_surface(application_surface,clamp(global.xx-480,0,1024-960),clamp(global.yy-270,0,928-540),960,540,0,0,480,270);
            sprite_index = spr_screenShot
        }
        instance_deactivate_all(1)
        instance_activate_object(obj_pause)
        view_visible[2]= true
    }
}
(It will always be in the room Town)
My views are 960x540 and the room is 1024x928
View[0] is following the obj_player
View[1] is following the obj_dash (a mechanic in my game where you can dash)
View[2] is following the obj_pause

As I earlier said, when I comment out the line "sprite_index = spr_screenShot" then the object does appear correctly in the middle of the screen.

Any help would be appreciated. If you have another, better way of pausing the game, I would like to hear them!
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Your code seems slightly over-complicated - application_surface contains exactly what's on the screen - you don't need to specify an offset inside it. As you have multiple views, I'd suggest to try stretching out spr_screenShot over the entire screen (display_get_gui_width/height) in Draw GUI event, which draws over views as-is
 
B

Bert de Beer

Guest
Thank you, when I removed the offset in the function it worked how I wanted it to!
 
Top