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

help with mask_index

pgvago

Member
hello from italy;

i have been looking around and i was not able to find a thread with this very simple problem.
if there is one already please point me to it.

i have an object that bounces of a wall, but i would like to set a mask_index on the wall so that the collision does not happen on the touching the first pixels.
i have set up a mask_index on thw wall's sprite, but i simply don't understand how to code the bouncing object on using the mask_index instead of the full sprite.

i tried:
mask_index = spr_wall;
but when when i check the content of mask_index it is always equal to 0.

thanks, pietro.
 
spr_wall is the first sprite in the sprite directory. It will have an actual value of zero, as the various indexes (sprites / paths etc) start from zero and are all treated in the same numerical fashion. When there is no mask_index at all, it has a value of -1.

That will either be because there is no sprite set to the instance, or because you have manually set this value to be -1 yourself (no collision), or using precise collision checking / a modified mask also gives this value. The mask_index, in your case, will show as zero too - as it shares the same information spr_wall has.

The difference between the various directories comes from GMS knowing what they are classed as, rather than the value each part of the property is given. Sprite_index = 0 / 1 / 2 / 3 / 4 and so on, path = 0 / 1 / 2 / 3 / 4 and so on.

You should note that using spr_wall as the mask index is unnecessary if the object already has that sprite set to it's sprite_index. The mask is automatically set under those conditions, unless you tell GMS otherwise.

To get a smaller mask for spr_wall you would want to go into Modify Mask, and then manually set the bounding box properties to be smaller than the sprite.
 
Last edited:

pgvago

Member
thank you dude!

i completely understood what you wrote but unfortunately i still cannot seem to get things right (my fault for sure).
i have modified the mask to a smaller size but when i check to see with place_free i am always returned a 0.

what i am trying to do is have an abject bounce off a wall, so when i hit a collision i check to see if the object can me moved at (x-5, y-5).
unfortunately i am always returned a 0 because (x-5, y-5) is still on the colliding sprite. it is out of the mask, but it is still on the colliding sprite.
only if i do (x-50, y-50) that takes me out of the sprite i am returned a 1.

should i use another system to check if a place is free?

i hope i made sense..

pietro.
 
The mask is what the collision events use, so as far as I'm aware it shouldn't still be going on the sprites dimensions. I am not sure if using a manually altered bounding box counts as "precise", and would maybe require using precise collision checking in any collision events.

If it did require that, then it's possible you're seeing a standard bounding box being used instead. Which would be the size of the sprite. I'll have to test this out, as I'm not 100 sure.

EDIT:
I don't know why this isn't working for you. I made a quick project where an instance had a manual bounding box.

Another instance used place_free to see if it could move, and it only registered collision at the expected point. This was inside the sprite of the other instance, which showed that the mask was taken as much smaller. It stopped moving at this point, and that proved it worked.
 
Last edited:

pgvago

Member
i have honestly tried for hours, but i still can't get it to work.

i am trying to see if i am colliding on the x axis, so in a collide event i have added these lines of code but they always return 0.

if (place_free (x + hspeed, y)) {
direction -= 90;
}

so my question is:
when an object triggers a collide evnt is it because it is already colliding? if it is already colliding does object "enter" the colldingo object or does it stop on the pixel before is collides?

thanks, pietro.
 
D

Danei

Guest
when an object triggers a collide evnt is it because it is already colliding?
Yes gamemaker collision events happen in any frame during which the instance masks are overlapping at least one pixel, so the collision event won't occur until one instance has entered the other. If you need to anticipate the collision before it happens, you can use collision functions in e.g. the step event for that.
 
Top