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:tutorials:orxscroll:access_scrollclass_from_scrollobjects
====== Accessing the Scroll class from a ScrollObject ====== Being able to access common functions in the Scroll class is pretty essential in a Orx/Scroll based game. The ''Scroll'' class provides a singleton which can be accessed from anywhere in a ''ScrollObject'' class: ''MyClass::GetInstance()'' Imagine for a second that you had a function in your ''Scroll'' class to update a score. Collisions using ''OnCollide'' in the various instances of ScrollObject(s) might all need to update the score with different values. Let's say the score function looks like this in the ''MyGame'' ''Scroll'' class: <code c> void MyGame::AddToScore(int points) { score += points; } </code> And say we had a Hero ''ScrollObject'' class which happened to collide with a Coin ''ScrollObject'' class: <code c> orxBOOL Hero::OnCollide(ScrollObject *_poCollider, orxBODY_PART *_pstPart, orxBODY_PART *_pstColliderPart, const orxVECTOR &_rvPosition, const orxVECTOR &_rvNormal) { if (_poCollider == orxNULL) { return; } const orxSTRING colliderName = _poCollider->GetName(); if (orxString_Compare(colliderName, "Coin") == 0) { MyGame::GetInstance().AddToScore(100); } return orxTRUE; } </code> The main point is that once the collision is detected, we can update the score in the Scroll class using the singleton: <code c> MyGame::GetInstance().AddToScore(100); </code> That's all there is to it.
en/tutorials/orxscroll/access_scrollclass_from_scrollobjects.txt
ยท Last modified: 2025/09/30 17:26 (14 months ago) by
127.0.0.1
Page Tools
Show page
Old revisions
Backlinks
Export to PDF
Rename Page
Back to top