This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:guides:beginners:collision_events [2018/02/14 04:47 (8 years ago)] – ↷ Links adapted because of a move operation iarwain | en:guides:beginners:collision_events [2025/09/30 17:26 (4 weeks ago)] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| In order for the game to be won by the hero by collecting the star, we need to create a Physics Event Handler in code to check for, and to process a collision between those two objects. | In order for the game to be won by the hero by collecting the star, we need to create a Physics Event Handler in code to check for, and to process a collision between those two objects. | ||
| - | We can declare one at the bottom of the Init() function: | + | We can declare one at the bottom of the '' |
| + | |||
| + | < | ||
| + | orxViewport_CreateFromConfig(" | ||
| - | < | ||
| orxEvent_AddHandler(orxEVENT_TYPE_PHYSICS, | orxEvent_AddHandler(orxEVENT_TYPE_PHYSICS, | ||
| </ | </ | ||
| - | What this means is, every time there is a physics event like a collision, execute the PhysicsEventHandler function. We don't have one of these, so you can add one: | + | What this means is, every time there is a physics event like a collision, execute the |
| < | < | ||
| Line 19: | Line 21: | ||
| </ | </ | ||
| - | The type of event we are interested in for collisions is the orxPHYSICS_EVENT_CONTACT_ADD. | + | The type of event we are interested in for collisions is the '' |
| Add this code inside the new function: | Add this code inside the new function: | ||
| < | < | ||
| - | if (_pstEvent-> | + | orxSTATUS orxFASTCALL PhysicsEventHandler(const orxEVENT *_pstEvent) |
| + | { | ||
| + | | ||
| orxOBJECT *pstRecipientObject, | orxOBJECT *pstRecipientObject, | ||
| Line 40: | Line 44: | ||
| //do something | //do something | ||
| } | } | ||
| + | } | ||
| + | return orxSTATUS_SUCCESS; | ||
| } | } | ||
| </ | </ | ||
| Line 49: | Line 55: | ||
| Replace the "do something" | Replace the "do something" | ||
| - | < | + | < |
| if (orxString_Compare(senderObjectName, | if (orxString_Compare(senderObjectName, | ||
| orxObject_SetLifeTime(pstSenderObject, | orxObject_SetLifeTime(pstSenderObject, | ||
| Line 61: | Line 67: | ||
| The one last thing to add to ensure the collision between the star and the hero works, is to add " | The one last thing to add to ensure the collision between the star and the hero works, is to add " | ||
| - | < | + | < |
| [HeroBodyPart] | [HeroBodyPart] | ||
| Type = box | Type = box | ||