User Tools

Site Tools


en:guides:beginners:shooting_and_spawners

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:guides:beginners:shooting_and_spawners [2018/06/28 05:15 (7 years ago)] – In line with init projects sausageen:guides:beginners:shooting_and_spawners [2024/11/18 05:08 (4 months ago)] (current) – Fix position and speed of the bullets sausage
Line 36: Line 36:
 </code> </code>
  
-Some words on the above. This spawner can shoot ''BulletObject''s. It can shoot one at a time with 0.1 seconds between shots.+This spawner can shoot ''BulletObject''s. It can shoot one at a time with 0.1 seconds between shots.
  
 Time to attach it to the ''HeroObject'': Time to attach it to the ''HeroObject'':
  
-<code=ini>+<code=ini [highlight_lines_extra="7"]>
 [HeroObject] [HeroObject]
 Graphic      = HeroGraphic Graphic      = HeroGraphic
-Position     = (50400, 0)+Position     = (-350100, 0)
 Scale        = 2 Scale        = 2
 AnimationSet = HeroAnimationSet AnimationSet = HeroAnimationSet
Line 54: Line 54:
 {{:guides:beginners:beginners-32-shooting.png?nolink|}} {{:guides:beginners:beginners-32-shooting.png?nolink|}}
  
-Great so that's working for us. Now, how to stop it from shooting. The function that is available to us for this purpose is: orxObject_Enable()+Greatso that's working for us. Now, how to stop it from shooting. The function that is available to us for this purpose is: orxObject_Enable()
  
-If we disabled our hero object, yes it would shop him from shooting, but it would also make him disappear. Not quite what is expected.+If we disabled our hero object, yes it would stop him from shooting, but it would also make him disappear. Not quite what is expected.
  
 There are a number of ways to solve this situation. Let's go with a simple one. There are a number of ways to solve this situation. Let's go with a simple one.
Line 72: Line 72:
 Remove the spawner from the hero object, and make ''HerosGun'' a child of ''HeroObject'': Remove the spawner from the hero object, and make ''HerosGun'' a child of ''HeroObject'':
  
-<code=ini>+<code=ini [highlight_lines_extra="7"]>
 [HeroObject] [HeroObject]
 Graphic      = HeroGraphic Graphic      = HeroGraphic
Line 82: Line 82:
 </code> </code>
  
-When you run this, you'll notice little difference. Our hero is still firing. But now we can turn his gun off at the bottom of the Init() function.+When you run this, you'll notice little difference. Our hero is still firing. But now we can turn his gun off at the bottom of the ''Init()'' function.
  
 But we need a reference to the gun in code, which we don't have yet because [HerosGun] was created automatically with HeroObject. But we need a reference to the gun in code, which we don't have yet because [HerosGun] was created automatically with HeroObject.
Line 88: Line 88:
 First declare the gun as a variable just like the hero object: First declare the gun as a variable just like the hero object:
  
-<code=cpp>+<code=cpp [highlight_lines_extra="2"]>
 orxOBJECT *hero; orxOBJECT *hero;
 orxOBJECT *herosGun; orxOBJECT *herosGun;
 </code> </code>
  
-Then, in the Init() function, get the child reference of the gun using the hero object:+Then, in the ''Init()'' function, get the child reference of the gun using the hero object:
  
-<code=cpp> +<code=cpp [highlight_lines_extra="2"]
-herosGun = (orxOBJECT*)orxObject_GetChild(hero);+  hero = orxObject_CreateFromConfig("HeroObject"); 
 +  herosGun = (orxOBJECT*)orxObject_GetChild(hero); 
 +  orxObject_CreateFromConfig("Scene");
 </code> </code>
  
 Now that you have the reference, turn off the ''herosGun'' immediately after creating it: Now that you have the reference, turn off the ''herosGun'' immediately after creating it:
  
-<code=cpp> +<code=cpp [highlight_lines_extra="3"]
-orxObject_Enable(herosGun, orxFALSE);+  hero = orxObject_CreateFromConfig("HeroObject"); 
 +  herosGun = (orxOBJECT*)orxObject_GetChild(hero); 
 +  orxObject_Enable(herosGun, orxFALSE); 
 +  orxObject_CreateFromConfig("Scene");
 </code> </code>
  
 Compile and run. Compile and run.
  
-Cool, he stopped shooting. The last thing, turn on, and off the shooting based on pressing the left control key:+Cool, he stopped shooting. The last thing, turn on, and off the shooting based on pressing the left control key in the ''Update()'':
  
 <code=cpp> <code=cpp>
Line 120: Line 125:
 Compile and run. Compile and run.
  
-Hmmm... his bullets don't go left when the hero faces left. Change the spawner by adding ''ObjectSpeed'' and ''USeRelativeSpeed'' properties:+Hmmm... His bullets don't go left when the hero faces left. Change the spawner by adding ''ObjectSpeed'' and ''UseRelativeSpeed'' properties:
  
-<code=ini>+<code=ini [highlight_lines_extra="5,6,7"]>
 [BulletSpawner] [BulletSpawner]
 Object           = BulletObject Object           = BulletObject
 WaveSize         = 1 WaveSize         = 1
 WaveDelay        = 0.1 WaveDelay        = 0.1
-Position         = (0, 0, 0) +Position         = (0, -6, 0) 
-ObjectSpeed      = (500, 0, 0)+ObjectSpeed      = (1500, 0, 0)
 UseRelativeSpeed = true UseRelativeSpeed = true
 </code> </code>
Line 136: Line 141:
 Compile and Run. Compile and Run.
  
-Fantastic! Our hero can now run, jump and shoot.+Fantastic! Our hero can now run, jumpand shoot.
  
 ---- ----
en/guides/beginners/shooting_and_spawners.1530188112.txt.gz · Last modified: 2018/06/28 08:15 (7 years ago) (external edit)