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/13 20:47 (7 years ago)] – ↷ Page moved from guides:beginners:collision_events to en:guides:beginners:collision_events iarwain | en:guides:beginners:collision_events [2024/11/19 02:24 (4 months ago)] (current) – Highlights sausage | ||
---|---|---|---|
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 | ||
Line 77: | Line 83: | ||
---- | ---- | ||
- | Next: [[guides: | + | Next: [[en:guides: |
- | {{section> | + | {{section> |