How to find a sprite on large canvas?

Pfap

Member
I have a character sprite and then I have separate items the character can equip. The character is on a 64X64 canvas. Lets say I have spr_hat, currently to draw the character with the hat on I just draw the spr_hat onto the spr_character. Which works well, but it also means that I am drawing the hat on a 64x64 canvas and at the exact position on that canvas, so that it lines up perfectly with the character sprite.

Maybe there is a better way to do the above?

Now for my specific question, how can I find where the sprite on that canvas is so that when I draw the hat independently of the character it doesn't look like an invisible character is wearing it?

My current solution is to have 2 sprites for each item. spr_hat_on and spr_hat_off, where the _off sprite is placed on the canvas for drawing to a selection menu instead of the character.

I guess my problem would be solved if I could find the center of the actual content and not the center of the canvas.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
GameMaker will automatically clip empty space in texture pages, so larger canvases do not actually "cost" you anything at runtime
 

Pfap

Member
GameMaker will automatically clip empty space in texture pages, so larger canvases do not actually "cost" you anything at runtime
That's good to know, I'm more so looking at it as a human efficiency thing as making a duplicate sprite for each item and dragging the origin point seems like a waste of clicks. Maybe, it's the best way though. I think I remember there being a function called sprite_get_pixel(), but I can't seem to find it in the manual.
 
D

dannyjenn

Guest
There is no sprite_get_pixel(), as far as I'm aware. There is a draw_getpixel(), but I'm not sure it'll be all that helpful here since it's slow and there are probably better ways of doing what you want anyway.

The best way is probably just to change the origin.

If you don't want to do it in the sprite editor, what you could probably do is call sprite_set_bbox_mode() to change the bounding box to automatic. That should put the bounding box around only the character (not the entire canvas). Then you could use sprite_get_bbox_top(), sprite_get_bbox_bottom(), sprite_get_bbox_right, and sprite_get_bbox_left() to figure out the center of the character. Then you could use sprite_set_origin() to set the origin to that center point (or to however many pixels above the center you want).
 
Top