This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:orx:reference:object:snippets [2014/11/27 22:10 (11 years ago)] – OrxOBox and orxVector snippits added. sausage | en:orx:reference:object:snippets [2018/01/21 10:53 (8 years ago)] (current) – Content moved. Deleted. sausage | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Object: Code Snippets ====== | ||
| - | |||
| - | ===== OrxFrame ===== | ||
| - | |||
| - | |||
| - | ===== OrxFX ===== | ||
| - | |||
| - | < | ||
| - | orxObject_AddFX(heroObject, | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | [HitPowerPill] | ||
| - | SlotList = ColorFlash | ||
| - | |||
| - | [ColorFlash] | ||
| - | Type = color | ||
| - | StartTime | ||
| - | EndTime | ||
| - | Curve = sine | ||
| - | Absolute | ||
| - | Period = 0.5 | ||
| - | EndValue | ||
| - | StartValue | ||
| - | </ | ||
| - | |||
| - | ===== OrxFXPointer ===== | ||
| - | |||
| - | |||
| - | ===== OrxObject ===== | ||
| - | |||
| - | ==== OrxObject_Create ==== | ||
| - | |||
| - | orxOBJECT *heroObject = orxObject_CreateFromConfig(" | ||
| - | orxVECTOR pointA = {500, | ||
| - | orxObject_SetPosition(heroObject, | ||
| - | |||
| - | ==== OrxObject_SetPosition ==== | ||
| - | |||
| - | orxVECTOR tilePos; | ||
| - | orxVector_Set(& | ||
| - | orxObject_SetPosition(tile, | ||
| - | |||
| - | orxVECTOR pos; | ||
| - | orxObject_GetPosition(player, | ||
| - | pos.fX = -pos.fX; | ||
| - | orxObject_SetPosition(player, | ||
| - | |||
| - | ==== orxObject_SetRotation ==== | ||
| - | |||
| - | Rotation is set in radians. Zero rad vector is equivalent to (1, 0) vector in screen coordinates. In other words it is a horizontal line pointing from left to right. | ||
| - | |||
| - | Positive rotation is set in clockwise direction. If vector origin was in the center of the screen, then 1 rad would point to the bottom right corner of the screen. | ||
| - | ==== orxObject_SetAngularVelocity ==== | ||
| - | |||
| - | Set angular velocity changes object rotation value over time. Setting positive value make object rotate clockwise. | ||
| - | |||
| - | TBD: What's the unit of measure? | ||
| - | |||
| - | By default object starts with zero rotation angle which points horizontally from left to right. As object rotates a full circle its rotation angle value will not reset to zero. Instead it will continue to grow in positive or negative direction according to angular velocity value. | ||
| - | |||
| - | Thus after one full circle the object rotation value will satisfy the condition: | ||
| - | < | ||
| - | orxMath_Abs(orxObject_GetRotation(obj)) >= orxMATH_KF_2_PI | ||
| - | </ | ||
| - | ==== orxObject_GetWorldRotation and orxObject_GetRotation ==== | ||
| - | |||
| - | Returns current object rotation value in rad. The value returned can be any floating value. | ||
| - | |||
| - | See orxObject_SetRotation for coordinate system reference. | ||
| - | See orxObject_SetAngularVelocity for discussion of continuous rotation. | ||
| - | ==== orxObject_CreateNeighborList and orxObject_DeleteNeighborList ==== | ||
| - | |||
| - | Use it to obtain objects within the specified bounding box. | ||
| - | |||
| - | <code c> | ||
| - | orxOBJECT *obj; // comes from mouse click event or in some other way | ||
| - | orxVECTOR pos, size; | ||
| - | orxFLOAT range = orx2F(250.f); | ||
| - | orxOBOX box; | ||
| - | | ||
| - | orxObject_GetWorldPosition(obj, | ||
| - | orxVector_Set(& | ||
| - | orxOBox_2DSet(& | ||
| - | |||
| - | orxBANK *neighbors = orxObject_CreateNeighborList(box); | ||
| - | void* cell = orxNULL; | ||
| - | while ((cell = orxBank_GetNext(neighbors, | ||
| - | orxOBJECT **n = cell; | ||
| - | orxLOG(" | ||
| - | } | ||
| - | orxObject_DeleteNeighborList(neighbors); | ||
| - | </ | ||
| - | ==== object traversing ==== | ||
| - | |||
| - | [[en: | ||
| - | |||
| - | ===== OrxOBox ===== | ||
| - | |||
| - | Function to return an object within a boxed area: | ||
| - | |||
| - | orxOBJECT* GetObjectInTheArea(){ | ||
| - | |||
| - | orxVECTOR objectPickVector; | ||
| - | objectPickVector.fX = 878; | ||
| - | objectPickVector.fY = 1185; | ||
| - | objectPickVector.fZ = -1.0; | ||
| - | |||
| - | orxOBOX objectBoxArea; | ||
| - | |||
| - | orxVECTOR pivot = {0, 0, 0}; | ||
| - | |||
| - | orxVECTOR position; | ||
| - | position.fX = 834; | ||
| - | position.fY = 1150; | ||
| - | position.fZ = -0.1; | ||
| - | |||
| - | orxVECTOR size; | ||
| - | size.fX = 21; | ||
| - | size.fY = 160; | ||
| - | size.fZ = 1; | ||
| - | |||
| - | orxOBox_2DSet(& | ||
| - | |||
| - | orxU32 objectGroupID = orxCamera_GetGroupID(pstCamera, | ||
| - | |||
| - | orxOBJECT *objectToFind = orxObject_BoxPick(& | ||
| - | return objectToFind; | ||
| - | |||
| - | } | ||
| - | |||
| - | ===== OrxSpawner ===== | ||
| - | |||
| - | orxSTRUCTURE *structure = orxStructure_GetFirst(orxSTRUCTURE_ID_SPAWNER ); | ||
| - | while (structure != orxNULL){ | ||
| - | orxSPAWNER *spawn = orxSPAWNER(structure); | ||
| - | if (orxString_Compare(orxSpawner_GetName(spawn), | ||
| - | return spawn; | ||
| - | } else { | ||
| - | structure = orxStructure_GetNext(structure ); | ||
| - | } | ||
| - | } | ||
| - | ===== OrxStructure ===== | ||
| - | |||
| - | orxSTRUCTURE *structure = orxStructure_GetFirst(orxSTRUCTURE_ID_OBJECT); | ||
| - | while (structure != orxNULL){ | ||
| - | orxOBJECT *object = orxOBJECT(structure); | ||
| - | const orxSTRING objectName = orxObject_GetName(object); | ||
| - | orxSTRUCTURE *nextStructure = orxStructure_GetNext(structure); | ||
| - | if (orxString_Compare(objectName , " | ||
| - | orxObject_SetLifeTime(orxOBJECT(structure), | ||
| - | } | ||
| - | structure = nextStructure; | ||
| - | } | ||
| - | |||
| - | |||
| - | ===== OrxTimeLine ===== | ||
| - | |||
| - | < | ||
| - | orxOBJECT *dummy = orxObject_CreateFromConfig(" | ||
| - | orxObject_AddTimeLineTrack(dummy, | ||
| - | orxObject_EnableTimeLine(dummy, | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | [BringUpGameOverTimelineObject] | ||
| - | |||
| - | [BringUpGameOverTimeline] | ||
| - | 2.0 = " | ||
| - | </ | ||
| - | |||
| - | ===== OrxVector ===== | ||
| - | |||
| - | Some ways to initialise an empty orxVECTOR. | ||
| - | |||
| - | Avoid this: | ||
| - | orxVECTOR position; | ||
| - | |||
| - | Rather, do one of these: | ||
| - | |||
| - | orxVECTOR position = {0, 0, 0}; | ||
| - | |||
| - | orxVECTOR position = orxVECTOR_0; | ||
| - | |||
| - | orxVECTOR position; | ||
| - | position.fX = 0; | ||
| - | position.fY = 0; | ||
| - | position.fZ = 0; | ||
| - | |||
| - | Uninitialised orxVECTORs can create unintended consequences in your game. | ||