User Tools

Site Tools


en:tutorials:orxscroll:binding-orxscroll

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:orx:tutorials:community:acksys:scroll1 [2012/05/28 18:11 (12 years ago)] – [Giving the Bugs a Brain (Deriving the ScrollObject Class)] acksysen:tutorials:orxscroll:binding-orxscroll [2021/02/17 09:06 (3 years ago)] (current) iarwain
Line 1: Line 1:
-====== The Binding of Objects ======+====== The Binding of Objects in orx/Scroll ======
  
 I keep a github repository for the code in this tutorial at https://github.com/fmahnke/OrxScroll-ObjectBinding. I like to keep the coding social, so please feel free to fork off my repo and create your own interesting projects! I keep a github repository for the code in this tutorial at https://github.com/fmahnke/OrxScroll-ObjectBinding. I like to keep the coding social, so please feel free to fork off my repo and create your own interesting projects!
Line 7: Line 7:
 When we refer to "Object Binding" in this sense, we're describing "hooking up" a game object to a C++ class defining behaviors of the object. When we refer to "Object Binding" in this sense, we're describing "hooking up" a game object to a C++ class defining behaviors of the object.
  
-This means when an Orx/Scroll Object is created, it can automatically be set to use a C++ of choice for its implementation. This makes it easy to implement behavior that is specific to certain object types.+This means when an Orx/Scroll Object is created, it can automatically be set to use a C++ class of choice for its implementation. This makes it easy to implement behavior that is specific to certain object types.
  
 For instance, you want game objects to do certain things every frame. You want enemies to move on a path, or possibly attack. You want the player's character to be moved based on user input. For instance, you want game objects to do certain things every frame. You want enemies to move on a path, or possibly attack. You want the player's character to be moved based on user input.
  
 Additionally, binding objects to classes makes it easy to handle Orx events on an object-specific basis. For example, each type of object can have its own OnCreate function which is called whenever an object of that type is created. OnDelete is called when the object is deleted, etc. Additionally, binding objects to classes makes it easy to handle Orx events on an object-specific basis. For example, each type of object can have its own OnCreate function which is called whenever an object of that type is created. OnDelete is called when the object is deleted, etc.
 +
 +{{:tutorials:orxscroll:character_boy.png?nolink|}} {{:tutorials:orxscroll:enemy_bug.png?nolink|}}
  
 In this tutorial, we're going to create a small game with two specific examples of object binding. We'll create an Enemy Bug object and a Hero object and bind them to classes. Our enemy bugs will move semi-randomly across the screen. Our Hero will be controlled by the player. He'll flash red if he collides with an enemy bug, showing that he's hurt. In this tutorial, we're going to create a small game with two specific examples of object binding. We'll create an Enemy Bug object and a Hero object and bind them to classes. Our enemy bugs will move semi-randomly across the screen. Our Hero will be controlled by the player. He'll flash red if he collides with an enemy bug, showing that he's hurt.
Line 25: Line 27:
 ===== Create a new Scroll Project ===== ===== Create a new Scroll Project =====
  
-Before you begin this tutorial, you need a basic Orx/Scroll project ready. For details on doing this, see the previous tutorial, [[en:orx:tutorials:community:acksys:scroll0|An Introduction to Scroll]].+Before you begin this tutorial, you need a basic Orx/Scroll project ready. For details on doing this, see the previous tutorial, [[en:tutorials:orxscroll:introduction-orxscroll|An Introduction to Scroll]].
  
 This tutorial assumes you've made a new Orx/Scroll project by following the instructions in the previously tutorial exactly! This tutorial assumes you've made a new Orx/Scroll project by following the instructions in the previously tutorial exactly!
Line 33: Line 35:
 You'll need to download these textures ((Thanks to Daniel Cook of www.lostgarden.com for the great prototyping graphics)) for use in your config: You'll need to download these textures ((Thanks to Daniel Cook of www.lostgarden.com for the great prototyping graphics)) for use in your config:
  
-{{http://acksys.orx-project.org/images/Character_Boy.png}} +{{tutorials:orxscroll:character_boy.png}} 
-{{http://acksys.orx-project.org/images/Enemy_Bug.png}}+{{tutorials:orxscroll:enemy_bug.png}}
  
 Then, you'll need to prepare this config in your main Orx .ini file for use with this tutorial: Then, you'll need to prepare this config in your main Orx .ini file for use with this tutorial:
Line 274: Line 276:
   * This class makes use of the SetRotation, SetFlip, and SetSpeed functions defined in the ScrollObject base class.   * This class makes use of the SetRotation, SetFlip, and SetSpeed functions defined in the ScrollObject base class.
   * OnCreate is called when the object is first created. We didn't define a constructor, so data members must be initialized here.   * OnCreate is called when the object is first created. We didn't define a constructor, so data members must be initialized here.
 +  * In OnCreate, we query values in config without pushing the object's section first. That's okay, because Scroll pushes the binding Orx object's config section as a convenience before calling OnCreate.
   * We initialize our class members using the "custom" values we defined in config. While not strictly necessary, this is good data-driven design. It means we can adjust these variables and run again without recompiling.   * We initialize our class members using the "custom" values we defined in config. While not strictly necessary, this is good data-driven design. It means we can adjust these variables and run again without recompiling.
   * OnDelete is called when the object is deleted. We must provide a body for the function, but it does nothing in our case.   * OnDelete is called when the object is deleted. We must provide a body for the function, but it does nothing in our case.
Line 326: Line 329:
     virtual orxBOOL OnCollide (ScrollObject *_poCollider,     virtual orxBOOL OnCollide (ScrollObject *_poCollider,
         const orxSTRING _zPartName,         const orxSTRING _zPartName,
 +        const orxSTRING _zColliderPartName,
         const orxVECTOR &_rvPosition,         const orxVECTOR &_rvPosition,
         const orxVECTOR &_rvNormal);         const orxVECTOR &_rvNormal);
Line 343: Line 347:
 void Hero::OnCreate () void Hero::OnCreate ()
 { {
-    // Push class config section 
-    orxConfig_PushSection ("O-Hero"); 
     // Get movement speed from config value     // Get movement speed from config value
     m_movementSpeed = orxConfig_GetFloat ("MovementSpeed");     m_movementSpeed = orxConfig_GetFloat ("MovementSpeed");
-    // Pop class config section 
-    orxConfig_PopSection (); 
 } }
  
Line 382: Line 382:
 orxBOOL Hero::OnCollide(ScrollObject *_poCollider, orxBOOL Hero::OnCollide(ScrollObject *_poCollider,
        const orxSTRING _zPartName,        const orxSTRING _zPartName,
 +       const orxSTRING _zColliderPartName,
        const orxVECTOR &_rvPosition,        const orxVECTOR &_rvPosition,
        const orxVECTOR &_rvNormal)        const orxVECTOR &_rvNormal)
Line 425: Line 426:
 When you run the game, you'll be able to control the hero with the arrow keys. Be careful, the bugs will bite him if he gets too close and the OnCollision callback will make him "flash" red. When you run the game, you'll be able to control the hero with the arrow keys. Be careful, the bugs will bite him if he gets too close and the OnCollision callback will make him "flash" red.
  
-{{http://i.imgur.com/YmnW1.png?500}}+{{ :tutorials:orxscroll:binding-orxscroll-screenshot.png?nolink&500 |}}
  
 ===== What Now? ===== ===== What Now? =====
en/tutorials/orxscroll/binding-orxscroll.1338253887.txt.gz · Last modified: 2017/05/30 00:50 (7 years ago) (external edit)