Legacy GM [SOLVED] Player meters leave behind image when view moves

A

AtomicToilet

Guest
Howdy folks.
My issue involves two on-screen meters; one for the player switching between modes (Energy bars) and the other as a counter (that counts down when enemies are destroyed). They both function as they should, HOWEVER, they also both leave behind an image once the game view moves, like so [click to see full size images]





I've cobbled together code from two different sources

(
and
)

My resulting code is as follows:
-------------------------
Code:
Information about object: obj_energy_gui
Sprite: spr_energy_bars
Solid: false
Visible: true
Depth: -10000
Persistent: true
Parent:
Children:
Mask:

No Physics Object
Create Event:

execute code:

image_speed = 0;
image_index = 0;

Step Event:

execute code:

if (keyboard_check_pressed (ord('1')))
{
image_index = 0;
}

if (keyboard_check_pressed (ord('2')))
{
image_index = 1;
}

if (keyboard_check_pressed (ord('3')))
{
image_index = 2;
}

if (keyboard_check_pressed (ord('4')))
{
image_index = 3;
}

if (!instance_exists(obj_rex_mouse))
{
image_alpha = 0;
}

Draw GUI Event:

execute code:

draw_self();
Code:
Information about object: obj_energy_bars
Sprite:
Solid: false
Visible: true
Depth: -5000
Persistent: true
Parent:
Children:
Mask:

No Physics Object
Draw GUI Event:

execute code:

if instance_exists(obj_rex_mouse)
{
draw_sprite(spr_energy_bars_border,1,7,8);
draw_sprite_ext(spr_energy_blue,1,7,8,obj_rex_mouse.blue/100,1,0,c_white,1);
draw_sprite_ext(spr_energy_green,1,7,8,obj_rex_mouse.green/100,1,0,c_white,1);
draw_sprite_ext(spr_energy_purple,1,7,8,obj_rex_mouse.purple/100,1,0,c_white,1);
draw_sprite_ext(spr_energy_red,1,7,8,obj_rex_mouse.red/100,1,0,c_white,1);
}
-----------------------------------------------------------------------------------

Code:
Information about object: obj_asteroid_meter
Sprite: spr_asteroids_meter
Solid: false
Visible: true
Depth: -10000
Persistent: true
Parent:
Children:
Mask:

No Physics Object
Create Event:

execute code:

global.asteroids = 50;

Step Event:

execute code:

if (!instance_exists(obj_rex_mouse))
{
instance_destroy();
}

Draw GUI Event:

execute code:

draw_self();
draw_set_halign(fa_right);
draw_set_valign(fa_top);
draw_set_font(fnt_rocks);
draw_set_color(c_white);
draw_text(975,55," " + string (global.asteroids));
-------------------------------------------------------

nb. I know the bars and overlay for obj_energy_gui aren't lined up; still tweaking this :)

I have no idea why both gui elements leave images behind once the view moves. If it's really obvious how to fix it, pretend I'm normally a lot smarter ;)

Thanks, GM hivemind!
 

YoSniper

Member
If the meters are their own object(s) then you need to set the objects' x and y values relative to view_xview and view_yview at the end of every step (recommended in the End Step Event.)

If instead the meters are just drawn on top of everything, same kind of deal. Set them relative to view_xview and view_yview in the Draw Event.

Hope this helps.
 
A

AtomicToilet

Guest
Thanks for the reply, YoSniper! I haven't touched GM in quite a few months so I'm effectively re-learning stuff - would you be able to suggest the actual code I'd need to do as you suggested...? I get why it should/would work, I just can't think how to implement it. Cheers again!
 
Based on the code an information you've provided, I'd say the problem revolves around the fact that your instances have a sprite attached to them, but you're using the Draw GUI Event to draw your meters. However, you've left the normal Draw Event blank, so Studio is drawing the instance sprite by default, thus the doubling and why it follows the view. To solve this, just plop an empty piece of code in the normal Draw Event.
 
Top