background/sprite_create_from_screen in Game Maker

A place for people with an interest in developing new shmups.
Post Reply
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

background/sprite_create_from_screen in Game Maker

Post by BPzeBanshee »

While doing somework on the next release of GMOSSE, my lead tester Kaiser encountered an odd issue where after the game completed on the Stage 2 boss it went unresponsive and crashed.

We both did a bit of investigation and turns out Kaiser's machine happens to be a rare case where for who-knows-why the functions background_create_from_screen and sprite_create_from_screen do not work, resulting in unresponsiveness and occasionally a GM error stating that my background/sprite variable does not exist.

What does this mean? Well for those who don't know (most devs in this subforum that use GM either know of this command and/or use it) and can't figure it out for themselves, it creates a sprite/background from the current view on the screen for manipulation purposes. The best use this has seen on this forum has been for Pause menus using instance_deactivate_xxx functions (which make objects disappear as a result) to give an impression that everything in-game has stood still.

That's a pretty damn important function IMO and despite its rarity I looked around for alternate methods of doing the same thing. Eventually I found a thread on Yoyogames (which I subsequently lost the link for) where a user had the same experience and the solution suggested was this:

Code: Select all

/* DO NOT USE IN DRAW EVENT (can be used in Create/Step/etc) */
surf=surface_create(view_wview,view_hview);
surface_set_target(surf);
draw_clear_alpha(c_black,1);
screen_redraw();
surface_reset_target();
p = sprite_create_from_surface(surf,0,0,view_wview,view_hview,false,false,0,0);
surface_free(surf);
Yes, surfaces. I don't like them. One good thing I learned from my early days on the forum with Alluro was to avoid using these like the plague because of various compatibility issues. User-defined surfaces (the game screen is technically a surface) are known to on some machines: not create surfaces at all, transparency/rendering problems, disappear after a screen saver appears, etc. It's stored in VRAM if memory serves so the graphics card does a lot of work with it and if your graphics card isn't up to scratch or doesn't support it correctly, kaboom. It does have advantages however: I did find a thread which suggested that rendering text to a surface was actually FASTER (not slower as I thought) than normal text rendering, and that sprite-based fonts were at some point horribly slow to use thus surfaces were the way to go. Certainly in combination with blending techniques some excellent visual effects can be made if at the cost of reduced compatibility.

I've blabbed on enough, but suffice to say this bit of code fixed Kaiser's issue and I'm making this thread so that it's documented. I'm putting it in as an optional pause screen rendering method in GMOSSE soon and I think in the interests of maximum compatibility everyone here using background_create_from_screen should do the same and provide it as an alternative.
User avatar
eebrozgi
Posts: 178
Joined: Fri Nov 27, 2009 11:17 pm
Location: Finland
Contact:

Re: background/sprite_create_from_screen in Game Maker

Post by eebrozgi »

Thank you for bringing this up, I was actually going to make the pause screen in our game to work like that. Now I'm thinking whether or not I should drop that idea if it tampers with compatibility, regardless of the method...

What version of GM are you using, by the way? I'm still desperately waiting the strange issue with resolution changing to be patched in GM8.1, but seems like I have to downgrade it eventually, seeing how YoYo seems to have just abandoned GM8.1 in the complete favoring of GM Studio. Maybe the bug you brought up is version-specific, too.
If watching the trailer of the game
makes you feel a certain way
I would be very happy if
you would give the game a try

~Daisuke Amaya, 2015

ZeroRanger - RELEASED!
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: background/sprite_create_from_screen in Game Maker

Post by BPzeBanshee »

Deactivation of objects by itself is fine providing you manage it correctly as the GM manual says, although I think Studio did wipe it out in favour of a future new method of doing the same thing. You could just have some kind of image covering the in-game stage instead or a black background. The two methods above I use in GMOSSE MK-VII and seems to cover the spectrum though, and the way I've put it in the scripts in GMOSSE mean that to some extent even the developer won't have to worry too much about it, just make sure that global.surfaces is set to something on Game Start.

Regarding version-specificness, I hope it isn't the case but won't know for sure until other people with the issue test it on GM version-specific examples. I'm an 8.0 Pro user myself but I think most people have gone to 8.1 or Studio by now.

I don't think resolution changing within GM itself will ever get fixed up short of a bit of complaining on the matter by large numbers of people and even then only get the fix for GM:Studio, but I know of some external DLLs that allow for similar functionality for the versions we use. Maybe that can help you there?
User avatar
eebrozgi
Posts: 178
Joined: Fri Nov 27, 2009 11:17 pm
Location: Finland
Contact:

Re: background/sprite_create_from_screen in Game Maker

Post by eebrozgi »

I came up with a completely different idea overnight on how to fill the pause screen without letting the player completely forget the game field, so I fortunately have no more need for the screen capturing methods. I understand that letting the player choose it is an option, but I feel it would unnecessarily complicate things for our game.

I haven't yet used a single external DLL in my game, but I guess it wouldn't hurt to hear you out on that.

On the subject of Game Maker, though: I could use an angry... no, relatively upset mob here. ;) I truly feel like I've paid for an unfinished product.
If watching the trailer of the game
makes you feel a certain way
I would be very happy if
you would give the game a try

~Daisuke Amaya, 2015

ZeroRanger - RELEASED!
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: background/sprite_create_from_screen in Game Maker

Post by BPzeBanshee »

Bit late, but for a DLL that changes Desktop Resolution without being an unstable piece of crap/moving icons around (apparently anyway) try this: http://gmc.yoyogames.com/index.php?show ... 7857&st=40

Seems the dev stopped supporting it and I can't find anything newer that does the same thing, but it was the one I was thinking of when I typed my above post.

You're not wrong about 8.1 getting put under the carpet real quick either. No wonder I never cared to pay a cent for GM: ever since Mark Overmars stopped being the main man it seemed like more of a moneygrab than it was actually fixing its issues.
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: background/sprite_create_from_screen in Game Maker

Post by BPzeBanshee »

Bit of heads-up: Kaiser (the one guy who had this issue) tells me he managed to get a driver update (which wasn't present before, so don't say he should've updated in the first place) and this allowed the internal GM function to work correctly. Seems ATI finally did something about their drivers.

I still say the functionality is good to have anyway in case, but it's good to hear that there's even less cases of it happening - perhaps it's truly a thing of the past. If anyone else does have a similar issue please do get a hold of me.
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: background/sprite_create_from_screen in Game Maker

Post by Rozyrg »

I remember people having similar problems with this back when I was using GM7. The workaround at the time was having the game wait for keyboard input (can't remember the exact command), which halted everything until you hit a key. That was problematic in plenty of other ways, though.
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: background/sprite_create_from_screen in Game Maker

Post by BPzeBanshee »

That method was the one Mark Overmars used a lot for 'pausing' in his tutorials. Frankly I felt it was a crude hack and didn't allow for complex menus like what we've been able to come up with in our games. I hear pretty much all of the methods we use now are deprecated but there's going to be some other kind of pause system implemented soon? Do you know anything about it?
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: background/sprite_create_from_screen in Game Maker

Post by Rozyrg »

Hack sums it up alright, even displaying a sprite or text that says "PAUSE" required way more effort than it should've that way, much less trying to do full menus.

As for a new way to do it: I'm back into update fear/avoidance mode after the last GMS one broke a big chunk of my scripts, so unless it's already in there, I probably won't be finding out anytime soon. >_>

instance_deactivate_all() always worked fine for me for pausing, personally. Being able to see everything while paused in order to properly plot your next move seems it'd be more vital for puzzle and strategy games; but I can understand the convenience of having it (and the fun challenge of trying to implement it.)
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: background/sprite_create_from_screen in Game Maker

Post by BPzeBanshee »

Well, considering your abuse of the script system I'm not too surprised you're having issues. And you call me the Dark GML Magic master. :P

I *might* get GMS eventually, but I just blew $500 on a J360 and two games for it, and I still need a new computer case/overall upgrade, so it may have to wait.
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: background/sprite_create_from_screen in Game Maker

Post by Rozyrg »

Dark Magicians of GM would be a great fake company (or demo group) name. I might just start using that to refer to yall from now on :lol:

Yeah, I wouldn't recommend dropping that much cash on it until you have a better reason to, I still use GM8 all the time. OUYA export is really cool and all; but not quite $300+ cool (yet.)
User avatar
n0rtygames
Posts: 1001
Joined: Thu Mar 15, 2012 11:46 pm
Contact:

Re: background/sprite_create_from_screen in Game Maker

Post by n0rtygames »

Rozyrg wrote:Dark Magicians of GM
When God himself refers to you as a Dark Magician... it's either time to get flattered, or get holy.

(Sorry, it's been a while since we annoyed you with flattery)
facebook: Facebook
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: background/sprite_create_from_screen in Game Maker

Post by BPzeBanshee »

My main interest was the YoYo Compiler but it looks like they're milking all the cash they can get, making it another $200 module rather than just making it part of the game like they should've done at the beginning.

Shaders look cool: I could do some interesting title screens with that, but performance would no doubt suck. And I'm interested to see what they've done with the sound system. If it does OGG and looping with loop points + pause it'll be the only thing anyone ever needs for sound.
User avatar
Kaleb Parham
Posts: 44
Joined: Wed Jul 18, 2012 6:26 pm
Location: United States
Contact:

Re: background/sprite_create_from_screen in Game Maker

Post by Kaleb Parham »

Are you using GM studio? Some commands got changed or deleted entirely.
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: background/sprite_create_from_screen in Game Maker

Post by BPzeBanshee »

No, I'm not. GM8.0. Do you know if this particular function got modified/removed? It's been listed as deprecated since at least the mess that was GM:HTML5.
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: background/sprite_create_from_screen in Game Maker

Post by Rozyrg »

It's actually still in the manual as background_create_from_screen ; but with a stipulation to use background_delete to remove it from memory afterwards (that might've already been there before.)

Keep in mind that my copy is out of date; but not by more than a few months.
Post Reply