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

SOLVED Scaling a (NEW) sprite to screen size

C

Creo

Guest
Hi, so what I'm trying to do is make a new sprite in the game from the player's choice, and that works fine but the issue I'm having is when i set the sprite using some code to the object the size the object appears changes and I thought the size would automatically scale to the object's size but apparently not. I'm using sprite_add() to get the sprite in game and setting it to the object using sprite_index. Is there a way I can change the new image's scale to fit the screen? Thanks - Creo.
 

gnysek

Member
SPrite scale should be 1:1 with original size, except you changed image_xscale/image_xscale. Also, when using draw_sprite functions, scale might be set there. In my opinion - all is good in your case, as objects have no size in GameMaker.

To fit image into window size:

image_xscale = window_get_width() / sprite_get_width(sprite_index)
image_yscale = window_get_height() / sprite_get_height(sprite_index)
 
C

Creo

Guest
SPrite scale should be 1:1 with original size, except you changed image_xscale/image_xscale. Also, when using draw_sprite functions, scale might be set there. In my opinion - all is good in your case, as objects have no size in GameMaker.

To fit image into window size:

image_xscale = window_get_width() / sprite_get_width(sprite_index)
image_yscale = window_get_height() / sprite_get_height(sprite_index)
hmm it didn't work, i still have the same problem that i had before even after setting this code after i set the objects sprite to the new one, might there be something im missing?

Edit: I forgot to add, my game is in full screen if that affects anything.
 

Attachments

Last edited by a moderator:
C

Creo

Guest
Never mind I fixed it but the calculation was:
image_xscale = 1 * display_get_gui_width()/sprite_get_width(sprite_index)
image_yscale = 1 * display_get_gui_height()/sprite_get_height(sprite_index)
I don't know if this was because I had it full screen but at least it works, thanks for the help
 

Nidoking

Member
You can drop the 1 *. The number of times when you need to multiply something by a hardcoded one is close enough to zero that it should fall within even Game Maker's mysterious rounding error.
 

NightFrost

Member
I don't know if this was because I had it full screen but at least it works
There's various possible answers. One is that you're drawing in GUI event, so draw resolution is what you've set to GUI, and you've set it to different size. Another could be your view and application surface have different sizes so window size, which should equal display in fullscreen, was not the correct pixel size to use. It is a good idea to get a firm grasp on the display's pipe: how the image is created from room, to camera view, to application surface, to display backbuffer, and how GUI gets put on top if used.
 
Top