SOLVED Draw text relative to object

V

VansiusProductions

Guest
Hi guys,
I want to draw text under an object and keeps a distance that is constant no matter how big the object is.
Like this:

So here's my draw code (the red line is 18 pixels long):
Code:
draw_text(x,y + ((sprite_height * image_yscale) / 2) + 18,string(name) + "#" + string(diameter) + string(unit))
the image_yscale and xscale are changed with the mouse wheel. And this is what happened:

it flashes (real quick, this gif is actually at a lower fps than my game), im not scrollling though
I don't know why this is happening!
 
L

Lars Karlsson

Guest
You can use:

Code:
[Draw Event]

draw_self();

draw_set_halign(fa_center);
draw_text(x, bbox_bottom + 18, "My Text");
draw_set_halign(fa_left);
For the flickering of the size, I don't know.
 
V

VansiusProductions

Guest
You can use:

Code:
[Draw Event]

draw_self();

draw_set_halign(fa_center);
draw_text(x, bbox_bottom + 18, "My Text");
draw_set_halign(fa_left);
For the flickering of the size, I don't know.
Using your code didn't change anything. And it is still flickering at a rate of 60 fps(my game's fps), I've been trying hard to record this but still either the quality is too low for you to see the flickering, or the framerate is too low.
 
L

Lars Karlsson

Guest
The flickering is not due to how you are drawing the text. It has to be somewhere in your step_event.
If you'd post the step_event, I'm sure we could figure the flickering out.
 
V

VansiusProductions

Guest
The flickering is not due to how you are drawing the text. It has to be somewhere in your step_event.
If you'd post the step_event, I'm sure we could figure the flickering out.
Code:
if mouse_wheel_up() {
    global.scale += 0.5
    global.callRender = 1
}
if mouse_wheel_down() {
    global.scale -= 0.5
    global.callRender = 1
}
//limit
if (global.scale<0.05) {global.scale = 0.05}
image_xscale = global.scale*diameter/sprite_width
image_yscale = global.scale*diameter/sprite_height
Each object has a diameter assigned so it scales according to it
 
L

Lars Karlsson

Guest
The problem is the 'global.scale*diameter/sprite_width' part. More specifically, the part in red.
When you change the image_xscale, you also change the 'sprite_width'. So you might want to set that
to the value the original size is.
Could just store it in a startWidth and startHeight var in the create event.

Then do:
Code:
[Create Event]
startWidth = sprite_width;
startHeight = sprite_height;

[Step Event]
image_xscale = global.scale*diameter/startWidth;
image_yscale = global.scale*diameter/startHeight;
Should do the trick.
 
Last edited by a moderator:
V

VansiusProductions

Guest
The problem is the 'global.scale*diameter/sprite_width' part. More specifically, the part in red.
When you change the image_xscale, you also change the 'sprite_width'. So you might want to set that
to the value the original size is.
Could just store it in a startWidth and startHeight var in the create event.

Then do:
Code:
[Create Event]
startWidth = sprite_width;
startHeight = sprite_height;

[Step Event]
image_xscale = global.scale*diameter/startWidth;
image_yscale = global.scale*diameter/startHeight;
Should do the trick.
Thanks! now the flickering is gone
BUT there are now 2 copies of the object, watch this:
 
L

Lars Karlsson

Guest
Are you 100% sure there arent two objects on-top of each other? Looks like the 'bottom' one is of another object, since it doesnt grow and shrink.
 
L

Lars Karlsson

Guest
Actually, looking at it now. It looks like the bottom object has the draw_text event, with the 18px offset. And the top object is getting the scroll input.
Seems really odd.
 
V

VansiusProductions

Guest
Actually, looking at it now. It looks like the bottom object has the draw_text event, with the 18px offset. And the top object is getting the scroll input.
Seems really odd.
OH YES THAT's IT, i solved it! now i see you're right! THANKS A LOT!
 
Top