• 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!

Legacy GM How to replicate the obsolete "sprite_create_from_screen" function

S

Silversea

Guest
Howdy.

I used sprite_create_from_screen in a few past projects, I now see this is "obsolete" in GMS 1.4. I'm hoping this means there is an alternative, but if there is one, I can't find it. Any ideas?

I see there is still a "sprite_create_from_surface" but I'd rather not start learning surfaces if I don't have to.
 

TheSnidr

Heavy metal viking dentist
GMC Elder
Surfaces is the way to go. The application_surfave (look it up inithe manual) is the "screen surface", so creating sprites from this is like creating sprites from the screen
 
S

Silversea

Guest
There are still some mysteries that I face with surfaces. One of those is, if I'm using the application_surface, do I need to create that? Doesn't it already exist in the game automatically. If so, how do I find out what the ID is for use in functions?
 

TheSnidr

Heavy metal viking dentist
GMC Elder
The application_surface always exists in the game. The id of the surface is stored in the variable called application_surface
 

Slyddar

Member
I've done this recently. This code seemed to work fine to create a sprite called spr_game, which was a sprite of the game screen.

Code:
//CREATE event
//create surface
scrn = surface_create(room_width,room_height);
surface_copy(scrn, 0, 0, application_surface);
if surface_exists(scrn) {
    spr_game = sprite_create_from_surface(scrn,0,0,room_width,room_height,false,false,0,0);
}
You don't really need to know much about surfaces to use it. You should also create a game end event though with this in it to clear it. Also delete the sprite when you've finished with it.
Code:
if surface_exists(scrn) surface_free(scrn);
 
S

Silversea

Guest
If that's the above is case couldn't you just do this?

Code:
//CREATE event
 spr_game = sprite_create_from_surface(application_surface,0,0,room_width,room_height,false,false,0,0);
 
Last edited by a moderator:
S

Silversea

Guest
Not having any luck with the code above. I hate surfaces because they give no feedback, and I can't debug them in any way. The manual does not explain the functions well enough for me to understand why they are necessary and how they are used.

For example: surface_copy "copies a source surface to its destination surface". Isn't this redundant? We just created a surface, and it already has the contents that we need, so why do we need to make a clone of it?
 

Slyddar

Member
If that's the above is case couldn't you just do this?
Yeh true, I copied and pasted that code from different parts of mine, so there were things happening in between. Just took out what related to you.

You can run the game in debug, with F6, and then place a breakpoint where you are doing your surface work, and then in the debugger you can view the contents of the surface. Might help to see what is not working for you.
 
S

Silversea

Guest
I'll try and explain in words. The code seems to work except that it only captures 10% or so of the screen. The sprite is equal to the width and height of the view, as it is asked to do, but most of it is blank and transparent. I can't really work it out.

My code as follows:

Code:
//Create
global.xv = view_xview[0]
global.yv = view_yview[0]
global.wv = view_wview[0]
global.hv = view_hview[0]

global.sprv = sprite_create_from_surface(application_surface,global.xv,global.yv,390,220,0,0,floor(global.wv/2),floor(global.hv/2))
 

kburkhart84

Firehammer Games
Your issue I believe is that you are using view_xview and view_yview to get the sprite. See, the application surface works the same regardless of views. The application surface is like any other surface in that to get the whole thing, you need to start at 0,0 and then the height and width are the whole thing. Your code is starting at whatever the xview/yview is. The confusion I think you have is that the application surface is literally what is on the screen...it won't have all the stuff offscreen outside of the view, so you don't need to account for the view at all.
 
S

Silversea

Guest
Riiiiight, I completely overlooked that. Ok, let's see if this works.
 

kburkhart84

Firehammer Games
I see no reason it wouldn't work. In fact, since you are using the application surface, it will basically always exist, unlike other surfaces. Normally you need to check if a surface exists, and if not, create it, but the engine itself handles this surface so not even that step is important. The only exception to this I know of is if you decide to disable the application surface yourself(which you would do in code).
 
Top