SOLVED Why can't I change my included file sprite's origin to middle centre?

otterZ

Member
I'm externally loading a sprite from an included file and want the origin set to Middle Centre, but it is drawing with the origin set to Top Left (0,0) ???

Here is the code in the Create Event:

GML:
exe = sprite_add(working_directory + "Exercises/spr_resting_strip60.png",60,0,0,sprite_width/2,sprite_height/2); //setting origin to middle centre

x = room_width/2;
y = room_height/2;
And here is the code in the Draw Event:

GML:
draw_sprite(exe,image_index,x,y);
I'm no doubt missing something obvious here . . . I set the origin to be middle centre in sprite_add but still stubbornly draws the origin at top left. I've been staring at this for a while now and I can't see what I'm missing. Can you see what I can't see? Thanks for taking the time to read this post.
 

HayManMarc

Member
My guess is that you're using sprite_width in an object that doesn't have a sprite already assigned to it, so it returns the value 0.

I think you would need to find the width of the incoming sprite by some other means.

Again, I'm just speculating. I may be wrong.
 

otterZ

Member
My guess is that you're using sprite_width in an object that doesn't have a sprite already assigned to it, so it returns the value 0.

I think you would need to find the width of the incoming sprite by some other means.

Again, I'm just speculating. I may be wrong.
Good point HayManMarc, I couldn't - or don't know yet, how to assign a sprite to an object that is from an included file.

I tried doing this manually and it worked, as in:

GML:
exe = sprite_add(working_directory + "Exercises/spr_resting_strip60.png",60,0,0,50,100);
And it works just fine now.

Maybe we can't add an included file sprite to an object as it needs to be loaded when the game is in actual play and not before? I'd guess.

Thank you HayManMac :)
 

FoxyOfJungle

Kazan Games
Hey @otterZ !
You can also load the sprite at offset position 0 and after that get the size of it, and then set the origin using sprite_set_offset()

GML:
exe = sprite_add(working_directory + "Exercises/spr_resting_strip60.png",60,0,0,0,0);
sprite_set_offset(exe, sprite_get_width(exe)/2, sprite_get_height(exe)/2);
 
Top