GML [SOLVED] Can infinite sprites cause lag? (changing opacity)

Dr_Nomz

Member
So I have a code that changes one objects sprite from normal, to transparent.

Thing is, is it drawing a NEW sprite every time the code is activated? Or does it delete the first sprite? OR does it just change the current one, instead of drawing a new one?
Draw event:
Code:
  if alpha = true{
  draw_set_alpha(0.8);
  draw_sprite(spr_Inventory_5,0,x2-250,y1+150);
  draw_set_alpha(1);
  }
  if alpha = false{
  draw_sprite(spr_Inventory_5,0,x2-250,y1+150);
  draw_set_alpha(1);
  }
I ask because if it IS creating lot's of sprites without ever deleting them, will that cause lag?
 

kupo15

Member
So I have a code that changes one objects sprite from normal, to transparent.

Thing is, is it drawing a NEW sprite every time the code is activated? Or does it delete the first sprite? OR does it just change the current one, instead of drawing a new one?
Draw event:
Code:
  if alpha = true{
  draw_set_alpha(0.8);
  draw_sprite(spr_Inventory_5,0,x2-250,y1+150);
  draw_set_alpha(1);
  }
  if alpha = false{
  draw_sprite(spr_Inventory_5,0,x2-250,y1+150);
  draw_set_alpha(1);
  }
I ask because if it IS creating lot's of sprites without ever deleting them, will that cause lag?
This isn't creating sprites, this is simply drawing a single sprite every frame which is what needs to happen if you want it drawn. Nothing is wrong with this.

It could be condensed so you aren't repeating code if you want

Draw event:
Code:
  var set_alpha = 1;
  if alpha = true
  set_alpha = 0.8;

  draw_set_alpha(set_alpha);
  draw_sprite(spr_Inventory_5,0,x2-250,y1+150);
  draw_set_alpha(1);
or you could be even more condensed

Draw event:
Code:
  var set_alpha = 1-(0.2*alpha);

  draw_set_alpha(set_alpha);
  draw_sprite(spr_Inventory_5,0,x2-250,y1+150);
  draw_set_alpha(1);
 
Last edited:

Dr_Nomz

Member
Huh, thanks that's pretty cool.

Also that draw event explanation makes a lot of sense, thanks for clearing that up!
 

TsukaYuriko

☄️
Forum Staff
Moderator
Drawing a sprite does not create a sprite, just like placing instances of objects into a room does not create objects. There is a fundamental difference between sprites, which are in your resource tree, and pixels, which are drawn to your screen - or more specifically, to the application surface, or any surface currently defined as the drawing target.

Imagine the application surface as a canvas you can draw anything to. Every step, the contents of this canvas are overwritten, for example by any defined backgrounds, followed by drawing tiles, sprites, particles and so on. What remains after this is a canvas containing a static amount of pixels, the color of which can change over the course of their lifetime. At no point during this process can a sprite which was drawn to the screen be interacted with in any way - for example, they can not be "removed", as you called it - only overwritten, as drawing it merely changes the color of pixels at specific locations.

The parts that require performance are drawing sprites to the surface, and the surface to the screen. After that, all that remains are pixels.
 
Top