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

Object Outline , NO shader?

S

Stratos.la

Guest
I would like to have my enemies outlined when clicked on with the mouse. i have an outline shader but when i do click on the enemies ( i assume its because there are multiple in the room ( same enemy) ) the shader goes crazy jumping from instance to instace and the game drops to like 5 fps. is there a relatively easy way to do an outline??
 

FoxyOfJungle

Kazan Games
Just drawing the same sprites several times in different directions, which I consider slow in some cases, other than that, only with shader. Try using another shader, as it doesn't work.
 
It would be better if you try to understand where you're going wrong with the shader, but I suppose you could do something like this:

draw the same sprite at the same position, but make its image xscale / yscale to be a little bit larger and set the draw colour to black.

If its drawn underneath you should end up with a black outline
 

Slyddar

Member
If you wanted a black outline without shaders, you can do it like this in the draw event.
Code:
//set width
var _w = 1;
draw_sprite_ext(sprite_index, image_index, x + _w, y + _w, image_xscale, image_yscale, image_angle, c_black, image_alpha);
draw_sprite_ext(sprite_index, image_index, x + _w, y - _w, image_xscale, image_yscale, image_angle, c_black, image_alpha);
draw_sprite_ext(sprite_index, image_index, x - _w, y + _w, image_xscale, image_yscale, image_angle, c_black, image_alpha);
draw_sprite_ext(sprite_index, image_index, x - _w, y - _w, image_xscale, image_yscale, image_angle, c_black, image_alpha);
draw_sprite(sprite_index, image_index, x, y);
 

Nidoking

Member
It sounds to me like you're not accounting for the difference between objects and instances somewhere. Why is the shader applying to any instances other than the selected one?
 

kburkhart84

Firehammer Games
I would like to have my enemies outlined when clicked on with the mouse. i have an outline shader but when i do click on the enemies ( i assume its because there are multiple in the room ( same enemy) ) the shader goes crazy jumping from instance to instace and the game drops to like 5 fps. is there a relatively easy way to do an outline??
It sounds to me like you're not accounting for the difference between objects and instances somewhere. Why is the shader applying to any instances other than the selected one?
This was exactly my thought...it doesn't seem like a problem with the shader, rather that for whatever reason it is applying to multiple instances instead of just the one you are mousing over.
 

Fredrik

Member
you could always do it the hard way, and make a copy of your enemy sprite, but giving it an outline (which you can do in the sprite editor) and then just make it change sprite with sprite_index whenever you press the enemy or not.
 

Mert

Member
This is a performance tip

Instead of using shaders in every instance, use it in one single object and draw their respective sprites in it. Example
GML:
shader_set(sh_outline);
with(enemyObject) {
draw_sprite(sprite_index,image_index,x,y);
}
shader_reset();
 

NightFrost

Member
If you use an outline shader, note that the sprite must have empty pixels surrounding it. This is because the shader will, understandably, only draw to the same region as where the sprite is being drawn. So, if the sprite's pixels touch any of the edges, there is no "outside" where the shader could reach and draw the outline on those edges.

However, I'm reasonably sure that GMS, when building texture pages, will occasionally cut empty edges away from sprites to fit them better to a single page. This means that even though you may see empty edges on the sprite editor, they are not actually present on the texture page (they have only been restored to the editor view for your convenience). Since texture pages are the real source of the sprite images, if the edges have been cut, they cannot be part of the actual draw operation and there will be no space for the shader to draw the outline. (You'd have to touch the vertex shader side to resize things to create actual empty edges.)
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
However, I'm reasonably sure that GMS, when building texture pages, will occasionally cut empty edges away from sprites to fit them better to a single page. This means that even though you may see empty edges on the sprite editor, they are not actually present on the texture page (they have only been restored to the editor view for your convenience). Since texture pages are the real source of the sprite images, if the edges have been cut, they cannot be part of the actual draw operation and there will be no space for the shader to draw the outline. (You'd have to touch the vertex shader side to resize things to create actual empty edges.)
There is an option in the Texture Group editor to disable this functionality so that empty space is not cropped from sprites when texture pages are built.
 

NightFrost

Member
There is an option in the Texture Group editor to disable this functionality so that empty space is not cropped from sprites when texture pages are built.
Oh, that's handy. It appears to affect the entire texture page instead of specific sprites however, so one need to be careful about their empty sprite space when using that option.

(Or do some magic in vertex shader if texture packing is considered more important.)
 

kburkhart84

Firehammer Games
Oh, that's handy. It appears to affect the entire texture page instead of specific sprites however, so one need to be careful about their empty sprite space when using that option.

(Or do some magic in vertex shader if texture packing is considered more important.)
Its a "group" setting though, so you could put just the enemies that need the outline into it and the rest of the groups will still trim to save space.
 
Top