User Tools

Site Tools


en:tutorials:access_scrollclass_from_scrollobjects

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:tutorials:access_scrollclass_from_scrollobjects [2017/12/10 10:19 (2 years ago)]
sausage created
en:tutorials:access_scrollclass_from_scrollobjects [2018/02/14 08:46 (2 years ago)]
Line 1: Line 1:
-====== 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,​ 
- const orxSTRING _zPartName, 
- const orxSTRING _zColliderPartName,​ 
- const orxVECTOR &​_rvPosition,​ 
- const orxVECTOR &​_rvNormal) 
-{ 
- const orxSTRING colliderName = _poCollider->​GetModelName();​ 
- 
- 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/access_scrollclass_from_scrollobjects.txt ยท Last modified: 2018/02/14 08:46 (2 years ago) (external edit)