Author Topic: Collision Detection  (Read 1728 times)

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Collision Detection
« on: 2009-01-26, 05:55:04 AM »
Just having trouble with the collision detection between two sprites.

What I'm doing is having a rule in one of the sprites,
Code: [Select]
Do TestCollisionMask
Target: ParentLayer.m_SpriteCategories.Cursor
Output To: Counter.ButtonCollide.CurrentValue

What I assumed from the hint given in the yellow text area,
Quote
Determine whether the sprite's collision mask is overlapping part of any sprite in the specified category. Return the index of the sprite within the category if a collision is occurring, otherwise return -1.
that I simply link it to a counter, then make a rule
if ButtonCollide = 0
do...
If ButtonCollide = 1
do...
If ButtonCollide = 2
do...

(all for different sprites in the category)

but it appears the counters cannot go below 0, so the -1 that's supposed to be being outputted is actually rounding to 0, which is the index of the sprite in the category I'm trying to detect collisions with, so I cannot differ between not touching and touching. What am I doing wrong here?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Collision Detection
« Reply #1 on: 2009-01-26, 06:33:05 AM »
Use some temporary variable or create a sprite parameter to hold the result if you don't have one.

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: Collision Detection
« Reply #2 on: 2009-01-26, 07:30:32 AM »
What's a temporary variable and how do I make/use one?

Thanks, the sprite parameter worked.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Collision Detection
« Reply #3 on: 2009-01-26, 06:15:25 PM »
I think if you're using the plan editor, there's a temporary variable called "sharedTemp1" or something.  Basically, you can manually declare any variable you want in the code editor in PlanBase or SpriteBase, and then use it in the rule editor.  I think PlanBase has one already set up.  But a sprite parameter is easier.