skip to content
Orx Learning
User Tools
Admin
Log In
Site Tools
Search
Tools
Show page
Old revisions
Export to PDF
Backlinks
Recent Changes
Media Manager
Sitemap
Log In
>
Recent Changes
Media Manager
Sitemap
Trace:
Welcome
Beginner's Guide
Config
Examples
Tutorials
en:examples:orx_scroll:scrollobject_start_position
====== ScrollObject Start Position ====== While an object can simply be given a starting position using the ''Position'' [[en:orx:config:settings_structure:orxobject|property in config]]. The position can even be a [[en:examples:spawners:spawning_random_objects|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. <code=c> 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); } </code>
en/examples/orx_scroll/scrollobject_start_position.txt
ยท Last modified: 2025/09/30 17:26 (9 months ago) by
127.0.0.1
Page Tools
Show page
Old revisions
Backlinks
Export to PDF
Rename Page
Back to top