How do I know where a sprite collision is assigned when its different size from actual spr (solved)

E

electricstix

Guest
In the create event of my sprite (width 80, height 140) I use the following.

mask_index = spr_col;

spr_col is a small rectangle (width 40, height 40).

Gamemaker assigns it correctly and since I am using it for collision it does work. Except, where is it assigne to
exactly on my main sprite. So for example it is 40x40 is it assigned at x = 0, y = 0 or where and how can I change that to be at a different position.
I'm using it to create a small collision area at the feet of the player, so when the player reaches an edge, the collision is when the players foot collides. Otherwise for example the players head stops at the bottom of a table.
 

pipebkOT

Member
each sprite already has a collision mask that you can modify in the sprite editor, you don't need to use mask_index , so why not use the sprite mask of the player sprite for the player object instead?

the same goes for the sprite point of origin, it always should be middle centered
 
Last edited:
E

electricstix

Guest
Let me explain. If I have a sprite that is a player standing let's say 40x80 then I want the collision to be at the foot of the player. So that would be a 40x10 rectangle at the bottom of the 40x80 sprite. So I want it to be at x = 0, y = 90 on the sprite.
If the player walks up to the top edge of the background it's the edge of a cliff. If the collision is not setup like that, then the player will stop when his head reaches the edge. I want his feet all the way up at the edge. Kind of like forced perspective.
I set it up exactly like that and it works great. Except, I did not purposly place the collision at the foot. It went there by default and I want to adjust it. How do I know where it is set by default?
 

pipebkOT

Member
@electricstix open the sprite in the sprite editor , there you would see the collision mask and edit it selecting manual, and changing the left, right top and bottom values,
or simply clicking the sprite to draw the collision


gms 1.4:




gms2 and click, "preview mask"




the black shaded part of the sprite is the collision mask
 
E

electricstix

Guest
Hi, everyone, that was not it. I got it to work, thanks for helping, but I think I did not clearly explain the problem. The sprite editor can not be used because I assigned the mask_index a sprite. So the custom collision mask is another sprite. I did find out that the position of the origin of the collision sprite is relative to to origin of the sprite I am assigning it to. So it works great and I understand it now. I hope that makes sense now. btw - thanks again. I really am going to like this forum.
 
E

electricstix

Guest
Ok, I aplogize. pipebkOT - that's the best solution. That worked much better than what I was thinking of doing.
 
Ok, I aplogize. pipebkOT - that's the best solution. That worked much better than what I was thinking of doing.
Something I noticed when I was a new programmer was that it's easy to find yourself overthinking things or coming up with some tedious solution. It all takes practice, and the advice of others, but you will get used to it and be able to come up with better, more efficient ideas in the long run. :)

the same goes for the sprite point of origin, it always should be middle centered
Not necessarily. If you wanted to draw something at a specific spot of an instance, such as their shadow, then it would be better to set their sprite origin to their feet rather than dead center, so that you don't have to adjust any code when doing the actual drawing...

With origin set at their feet:
Code:
draw_sprite(spr_example,1,x,y); //draw at player instance's feet
With origin set dead center:
Code:
draw_sprite(spr_example,1,x,y+10); //draw at player instance's feet
You see what I mean? For special situations, it's easier to set the origin to a specific spot to avoid having to trial-and-error your way through the correct amount to add to the x or y value to achieve what you want. But for MOST occasions, yes, it is good to keep the origin dead center. :)
 
Top