• 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 Drawing Scale

Imperial

Member
can you help me with drawing the sprites/texts, when I scale up or down the sprites/texts gets bigger

I want them to be Fixed please using the Draw Event, not Draw GUI
 

FrostyCat

Redemption Seeker
If you aren't willing to do it properly and use Draw GUI, your only solution is to draw these sprites and strings at a scale inversely proportional to the zoom (e.g. half the size for a 2x zoom). Look up how to use functions such as draw_sprite_ext() and draw_text_transformed().
 

GMWolf

aka fel666
As frostryCat (GameGeisha..? Is that you?) said, i strongly recomend you use the draw_gui though.
Drawing in the normal draw event may seem like a good idea now, but you are probably shlpting yourself in the foot.
(There are ocasions where drawing in the GUI event is not an option, but given how you asked about a simple scaling question, i doubt the problem you are solving is such an ocasion).

Seriously though, @FrostyCat, its you, isnt it?
 

Imperial

Member
I Tried this but It's not correct
Code:
draw_sprite_ext(spr_gui_background,1,view_xview[view_current]+view_wview[view_current]-sprite_get_width(spr_gui_background),view_yview[view_current]+view_hview[view_current]-sprite_get_height(spr_gui_background),view_wview/1280,view_hview/720,0,-1,1);
 
I Tried this but It's not correct
Code:
draw_sprite_ext(spr_gui_background,1,view_xview[view_current]+view_wview[view_current]-sprite_get_width(spr_gui_background),view_yview[view_current]+view_hview[view_current]-sprite_get_height(spr_gui_background),view_wview/1280,view_hview/720,0,-1,1);
How is it not correct? We need to know what you want to do with the sprite and its origin.
 

GMWolf

aka fel666
First transform coordinates from screen space to world space:
Code:
var wx = sx + view_xview; //sx is the x position on screen
var wy = sy + view_yview; //sy is y pos on screen.
Then scale:
Code:
var scale = view_wview/640;
//change 640 with another constant to change the scale.
//assumes a a constant aspect ratio.
Then draw like any other sprites using the variable calculated above.

[edit]
updated code below. I was tired when i wrote this :D
 
Last edited:

Imperial

Member
Code:
xx = view_xview[view_current]+view_wview[view_current]-sprite_get_width(spr_gui_background);
yy = view_yview[view_current]+view_hview[view_current]-sprite_get_height(spr_gui_background);
wx = xx + view_xview;
wy = yy + view_yview;
draw_sprite_ext(spr_gui_background,1,wx,wy,view_wview/1280,view_hview/720,0,-1,1);
nothing happens
 
Code:
xx = view_xview[view_current]+view_wview[view_current]-sprite_get_width(spr_gui_background);
yy = view_yview[view_current]+view_hview[view_current]-sprite_get_height(spr_gui_background);
wx = xx + view_xview;
wy = yy + view_yview;
draw_sprite_ext(spr_gui_background,1,wx,wy,view_wview/1280,view_hview/720,0,-1,1);
nothing happens
Are you trying to center it or keep the original position?
 
What I think Fel666 was implying,

Code:
var scale = view_hview/720;

xx = view_wview[view_current ]- (sprite_get_width( spr_gui_background) )*scale;
yy = view_hview[view_current] - (sprite_get_height( spr_gui_background) )*scale;
wx = xx + view_xview;
wy = yy + view_yview;
draw_sprite_ext( spr_gui_background, 1, wx, wy, scale, scale, 0, -1, 1);
 

Imperial

Member
What I think Fel666 was implying,

Code:
var scale = view_hview/720;

xx = view_wview[view_current ]- (sprite_get_width( spr_gui_background) )*scale;
yy = view_hview[view_current] - (sprite_get_height( spr_gui_background) )*scale;
wx = xx + view_xview;
wy = yy + view_yview;
draw_sprite_ext( spr_gui_background, 1, wx, wy, scale, scale, 0, -1, 1);
can you Fix the Pretenses
 

GMWolf

aka fel666
When I turn on my PC I'll work on some all purpose code that should work in any situation. But know that using the gui layer would be more correct, yeild better performance and reduce any artifacts due to scaling.

[edit]
here you go:
draw_sprite_fixed(sprite, index, xport, yport, scale):
Code:
///draw_sprite_fixed(sprite, index, xport, yport, scale);
var sprite = argument0;
var index = argument1;
var x_in_view = argument2 / view_wport[view_current];
var y_in_view = argument3 / view_wport[view_current]; //coordinates to draw in view (0 - 1)
var scale = argument4; //size of object

var x_in_room = (x_in_view * view_wview[view_current]) + view_xview[view_current];
var y_in_room = (y_in_view * view_hview[view_current]) + view_yview[view_current];

var xscale = scale * view_wview[view_current] / view_wport[view_current];
var yscale = scale * view_hview[view_current] / view_hport[view_current];
var rotation = -view_angle[view_current];

draw_sprite_ext(sprite, index, x_in_room, y_in_room, xscale, yscale, rotation, c_white, 1.0);
 
Last edited:
Top