• 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 [Closed] "sprite_create_from_surface" question... a weird question.

U

Uberpink

Guest
im using "sprite_create_from_surface" and "sprite_add_from_surface", then saving the sprite to disk.
(almost like screen capturing a portion of the screen to a sprite)

Weird question is.... i dont want to show what im "capturing" , is it possible to capture -anything- that is outside view but still in room? tries but get transparent sprite even if i have placed needed graphic outside view

(-i have an icon of the game and want to put the score on it (for sharing image on social media), then capture it for saving to disk, but as above, i dont want to show this so i was trying to do it outside the view)

if this aint possible, is it a way to just paste the score onto an eksisting sprite instead? maybe using sprite_merge? the score is made of drawn sprites, not tekst
 
U

Uberpink

Guest
Just create a new surface, and draw everything you want on to this surface.
can that be done outside view? (dont want player to see that it happens) sorry ive never used surfaces before so im abit lamer on that:)
 

CMAllen

Member
can that be done outside view? (dont want player to see that it happens) sorry ive never used surfaces before so im abit lamer on that:)
Yes. Surfaces exist independently of viewports. They also have their own coordinate space. When you draw to views, what's happening behind the scenes is you are drawing to a surface, and the drawing coordinates are adjusted by the viewport's position (and viewport scaling) within the active room.

If you create a surface the size of your viewport, then drawing to 0,0 will draw that sprite, primitive, etc in the upper-left corner of the surface. Drawing something at surface_get_width(), surface_get_height() will draw whatever it is at the lower-right corner of the surface.
 
U

Uberpink

Guest
ok i tried making a surface, not sure if i did it correct.. here is code... however my saved sprite is still transparent

-if left mousebutton release:

// view[0] is active and is 400x640,.. the gamescreen..., want to copy from something that is placed outside view /outside this gamescreen

surf=surface_create(400,750)
surface_set_target(surf)
instance_create(0,700,test) //big sprite placed outside view at the bottom beneath view that i want to capture


spr_custom = sprite_create_from_surface(surf, 0, 700, 200, 50, false, false, 0, 0);

sprite_save(spr_custom, 0,"kukspriten.png");
show_message("captured")

surface_reset_target()
with test instance_destroy()
 
Last edited by a moderator:

CMAllen

Member
Because nothing was actually drawn to the surface. If you don't draw it, it won't be there. From this code, you created a surface, created an instance, then promptly destroyed both of them without doing anything with either.

draw_sprite(0,0,0,0) will draw sub-image 0 of the top-most sprite on your resource list, in the upper-left corner of whatever surface is currently active. Unless you change to a different surface, that surface is going to be the application_surface, which will be the size of your viewport or camera (if you're using them) or the size of the first room the game loads. When objects use a draw() call (any of them), the x,y coordinates that they are drawn at is actually their x,y minus the camera's or viewport's x,y. The room-space coordinates are always remapped to screen-space coordinates.

Also, after you draw to a surface, you can draw that surface to the application surface to see what was actually done to it. Conversely, you can draw the application surface to another active surface to copy it or apply shader effects to the entire application surface (which is a common usage of surfaces).
 
U

Uberpink

Guest
thats one nice eksplanation, ill investigate it..thanks!! .so nothing is drawn only by having an object with a sprite there? sprite has to be drawn using the draw command?
 
U

Uberpink

Guest
it works! thanks alot!! had a little problem tho,,,i draw the background, then draw the score ontop of it, then capture it,,, the score fonts have a alpha gradient,, sort of glow, which is cool,, but where this glow is, the image get transparent (u can see the checkered photoshop pattern around the fonts...

is it a way to avoid that?
 

Attachments

CMAllen

Member
Yes, and no. Yes, you can after a fashion *IF* the alpha value of the pixels already drawn are fully opaque. You just disable drawing to the surfaces alpha channel, which essentially tells the GPU to ignore alpha values outside of color blending. This is how the application surface functions, because it has no alpha channel. What's happening is that the alpha value of the destination pixel and the alpha value of the source pixel are being multiplied together -- if the source is 1 (fully opaque) and the destination is 1 (fully opaque), then the result is 1.

For a more comprehensive breakdown of how the GPU sees color channels (which the alpha channel is):
Explaining Blend Modes: Part1
Explaining Blend Modes: Part2
 
U

Uberpink

Guest
thanks: used draw_set_blend_mode(bm_zero) and set it back to bm_normal again after drawing the stuff, that worked:):)
 
Top