While an object can simply be given a starting position using the Position
property in config. The position can even be a range of random positions. This could be enough, however you may wish to customise the position, for example to ensure that the object only appears on the edges of the screen, and nowhere else.
This can achieved by changing the object position using the ScrollObject's OnCreate
function.
void Enemy::OnCreate() { orxConfig_SetBool("IsObject", orxTRUE); int directionChoice = orxMath_GetRandomFloat(0, 4); orxFLOAT maxX = 300; orxFLOAT maxY = 200; orxVECTOR thisPosition = {}; this->GetPosition(thisPosition, orxFALSE); switch(directionChoice) { case 0: //top thisPosition = { orxMath_GetRandomFloat(-maxX, maxX), -maxY }; break; case 1: //right thisPosition = { maxX, orxMath_GetRandomFloat(-maxY, maxY) }; break; case 2: //bottom thisPosition = { orxMath_GetRandomFloat(-maxX, maxX), maxY }; break; case 3: //left thisPosition = { -maxX, orxMath_GetRandomFloat(-maxY, maxY) }; break; } this->SetPosition(thisPosition, orxFALSE); }