Jump to content


Photo

sprite_collision_mask( ) description is wrong


  • Please log in to reply
1 reply to this topic

#1 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 5216 posts
  • Version:GM8

Posted 13 January 2012 - 08:13 PM

I was trying to figure out why sprite_collision_mask() works some of the time and not all of the time, even on sprites currently active in the room. Throughout Game Maker, Mark coded rectangular scripts in the order of LEFT-TOP-RIGHT-BOTTOM. However, sprite_collision_mask( ) is coded in the order of LEFT-RIGHT-TOP-BOTTOM. I remember well the first time I read the manual about sprite_collision_mask( ) and thought, "That's odd, Mark always specified TOP before RIGHT. Maybe it's a typo in the manual." Then I looked at the function description in Game Maker itself and even there it listed RIGHT before TOP.

And the function never worked if the sprite was currently in use by an active instance. But it does! If you set it to Automatic or Full bounding -- the options that make LEFT-RIGHT-TOP-BOTTOM moot, the function works just fine. I was like, "What the deuce?" It finally dawned on me: The manual says sprite_collision_mask( ) doesn't always work right because Mark never debugged it! There's a typo in the description, so Mark and anyone that may have helped him work on GM thought there was a bug in the script itself, but it was in the description.

The proper format for sprite_collision_mask( ) is:

sprite_collision_mask(
sprite_index ,
precise ,
bbtype ,/*(0=Automatic, 1=Full, 2=Manual)*/
bbleft ,
bbtop ,
bbright ,
bbbottom ,
bbshape , /*Box Shape (0=Precise, 1=Rectangle, 2=Disk, 3=Diamond)*/
tolerance
)

You may still need to use sprite_index=sprite_index to reset the sprite, but I didn't need to when I used sprite_collision_mask() in Debug Mode.

I don't know if this was ever fixed in Game Maker 8.1, but for anyone using the older versions, you'll need to remember Mark's order of direction was LEFT-TOP-RIGHT-BOTTOM (except in angles, which went right-top-left-bottom... ).


Update
Ok, so sprite_index=sprite_index (which simply resets the sprite) is necessary. The reason I didn't notice it at first was because the instance I tested it with was always moving. The sprite gets updated every time an instance is moved. If an instance doesn't move, its sprite stays the same. Bet ya didn't know that. Neither did I. Live and learn. So if you use sprite_collision_mask() on an instance that doesn't move every step, you need to use sprite_index=sprite_index. Also keep in mind an animated sprite will not automatically update the bounding box. The instance itself must move. (If you can prove me wrong, though, be sure to post here or let me know.)

Edited by TheouAegis, 16 January 2012 - 09:37 AM.

  • 0

#2 Gym Leader Brock

Gym Leader Brock

    GMC Member

  • New Member
  • 1 posts
  • Version:GM8

Posted 10 June 2012 - 08:08 AM

THANK YOU sooo much =D

I was having this exact problem and couldn't figure out why my collisions weren't working.


Thanks a bunch man! internets+=1;
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users