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:tutorials:orxscroll:binding-orxscroll [2024/05/05 01:16 (19 months ago)] – Update to latest orx and Scroll revisions hcartyen:tutorials:orxscroll:binding-orxscroll [2025/11/30 14:33 (27 hours ago)] (current) – Update ini template to match latest orx, Scroll, and the linked repository hcarty
Line 42: Line 42:
 <hidden> <hidden>
 <code ini> <code ini>
-binding-of-objects - Template basic config file+BindingOfObjects - Template basic config file
  
 [Display] [Display]
 ; FullScreen = false + Decoration = false + no dimension -> Borderless FullScreen ; FullScreen = false + Decoration = false + no dimension -> Borderless FullScreen
 Title           = The Binding of Objects Title           = The Binding of Objects
 +IconList        = logo.webp
 FullScreen      = false FullScreen      = false
 Decoration      = false Decoration      = false
Line 57: Line 58:
  
 [Resource] [Resource]
-Texture         = bundle: # bundle:binding-of-objects.obr # ../data/texture +Texture         = bundle: # bundle:BindingOfObjects.obr # ../data/texture 
-Sound           = bundle: # bundle:binding-of-objects.obr # ../data/sound+Font            = bundle: # bundle:BindingOfObjects.obr # ../data/font 
 +Sound           = bundle: # bundle:BindingOfObjects.obr # ../data/sound 
 + 
 +[Bundle] 
 +ExcludeList     = BindingOfObjects 
 + 
 +[Clock] 
 +AllowSleep      = false 
 + 
 +[Config] 
 +DefaultParent   = Default 
 + 
 +[Default] 
 +KeepInCache     = true 
 +Pivot           = center
  
 [Input] [Input]
Line 66: Line 81:
 KEY_UP          = MoveUp KEY_UP          = MoveUp
 KEY_DOWN        = MoveDown KEY_DOWN        = MoveDown
 +
 +[Main]
 +ViewportList    = MainViewport
  
 [MainViewport] [MainViewport]
Line 72: Line 90:
  
 [MainCamera] [MainCamera]
-FrustumWidth    = 1280 +FrustumWidth    = 1920 
-FrustumHeight   720 +FrustumHeight   1080 
-FrustumFar      = 10+FrustumFar      = 2
 FrustumNear     = 0 FrustumNear     = 0
-Position        = (0, 0, -2)+Position        = -1 ; Objects with -1 <= Z <= 1 will be visible 
 +; Using a unique proxy object, sharing the same name 
 +OnCreate        = >> Camera.Get MainCamera, Camera.SetPosition < (0, 0), Camera.SetParent < ^, Set @ ID ^
  
 [Scene] [Scene]
Line 204: Line 224:
 { {
   // Set initial movement direction   // Set initial movement direction
-  m_direction = Direction::SOUTH;+  m_direction = SOUTH;
   // Get movement speed from config value   // Get movement speed from config value
   m_movementSpeed = orxConfig_GetFloat("MovementSpeed");   m_movementSpeed = orxConfig_GetFloat("MovementSpeed");
Line 261: Line 281:
     m_timeSinceDirectionChange = 0;     m_timeSinceDirectionChange = 0;
     // Pick random number between bounds of Direction enum     // Pick random number between bounds of Direction enum
-    orxU32 randomNum = orxMath_GetRandomU32(0, static_cast<orxU32>(Direction::LAST));+    orxU32 randomNum = orxMath_GetRandomU32(0, static_cast<orxU32>(LAST));
     // Update object's direction of movement     // Update object's direction of movement
     m_direction = static_cast<Direction>(randomNum);     m_direction = static_cast<Direction>(randomNum);
Line 297: Line 317:
 </code> </code>
  
-Add the following lines to ''binding_of_objects::BindObjects'' in ''binding-of-objects.cpp'' after the line for ''"Object"'':+Add the following lines to ''binding_of_objects::BindObjects'' in ''BindingOfObjects.cpp'' after the line for ''"Object"'':
  
 <code c> <code c>
Line 355: Line 375:
 void Hero::Update(const orxCLOCK_INFO &_rstInfo) void Hero::Update(const orxCLOCK_INFO &_rstInfo)
 { {
-  // Always initialize thy variables +  // Use movement input to initialize a vector to scale movement speed 
-  orxVECTOR speed = orxVECTOR_0;+  orxVECTOR speed = 
 +      // Vector's x component is right - left input strength. It will 
 +      // be 0.0 if the inputs are either inactive or both equally active. 
 +      orxInput_GetValue("MoveRight") - orxInput_GetValue("MoveLeft"), 
 +      // Vector's y component is down - up input strength. It will 
 +      // be 0.0 if the inputs are either inactive or both equally active. 
 +      orxInput_GetValue("MoveDown") - orxInput_GetValue("MoveUp"), 
 +      0.0};
  
-  if (orxInput_IsActive("MoveLeft"))+  // Normalize the input vector if it has a length > 1 
 +  if (orxVector_GetSquareSize(&speed> 1.0)
   {   {
-    speed.fX = -m_movementSpeed; +    orxVector_Normalize(&speed, &speed);
-  } +
-  else if (orxInput_IsActive("MoveUp")) +
-  { +
-    speed.fY = -m_movementSpeed; +
-  } +
-  else if (orxInput_IsActive("MoveRight")) +
-  { +
-    speed.fX = m_movementSpeed; +
-  } +
-  else if (orxInput_IsActive("MoveDown")+
-  { +
-    speed.fY = m_movementSpeed;+
   }   }
 +
 +  // Scale the raw input vector by the our movement speed
 +  orxVector_Mulf(&speed, &speed, m_movementSpeed);
 +
 +  // Update our speed
   SetSpeed(speed, false);   SetSpeed(speed, false);
 } }
Line 386: Line 407:
 The code should be almost self-explanatory. The hero's movement speed will be pulled from its config value. The update function (called every frame) sets the speed of the character based on what keyboard arrow is pressed. The ''OnCollide'' function adds a "flash" effect to the character. The code should be almost self-explanatory. The hero's movement speed will be pulled from its config value. The update function (called every frame) sets the speed of the character based on what keyboard arrow is pressed. The ''OnCollide'' function adds a "flash" effect to the character.
  
-You have to modify the ''binding_of_objects::BindObjects'' function to make it bind the new ''Hero'' class to the ''O-Hero'' object. Otherwise, the Hero will not be bound to its class and will just stand still in the middle of the screen!+You have to modify the ''BindingOfObjects::BindObjects'' function to make it bind the new ''Hero'' class to the ''O-Hero'' object. Otherwise, the Hero will not be bound to its class and will just stand still in the middle of the screen!
  
 Try to do those things yourself. If you need help, though, here are the lines to add: Try to do those things yourself. If you need help, though, here are the lines to add:
en/tutorials/orxscroll/binding-orxscroll.1714871760.txt.gz · Last modified: 2025/09/30 17:26 (2 months ago) (external edit)