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 revision Previous revision
en:guides:beginners:shooting_and_spawners [2018/02/14 04:47 (5 months ago)]
iarwain ↷ Links adapted because of a move operation
en:guides:beginners:shooting_and_spawners [2018/06/28 12:15 (3 weeks ago)] (current)
sausage In line with init projects
Line 3: Line 3:
 Time for our hero to defend himself in the quest to reach the prize. He needs to shoot his gun. Time for our hero to defend himself in the quest to reach the prize. He needs to shoot his gun.
  
-What will we use for a bullet? There a few choices, but we'll go for particle.png in the data/object folder:+What will we use for a bullet? There a few choices, but we'll go for ''​particle.png'' ​in the ''​orx/​tutorial/​data/object''​ in the Orx project. And copy this to our ''​data/​texture'' ​folder.
  
 {{ :​guides:​beginners:​particle2.png?​nolink&​100 |}} {{ :​guides:​beginners:​particle2.png?​nolink&​100 |}}
  
-Define ​it in the config:+Once copied, define ​it in the config:
  
 <​code=ini>​ <​code=ini>​
Line 20: Line 20:
 </​code>​ </​code>​
  
-Any BulletObject that is created will be scaled down a little, sent flying off to to the right, and can only exist for 1 second before auto-destroying.+Any BulletObject that is created will be scaled down a little, sent flying off to to the right, and can only exist for 1 second before ​being auto-destroyed.
  
-What is the best way to get our hero to shoot lots of these [BulletObject]s? A spawner is the thing to use.+What is the best way to get our hero to shoot lots of these ''​BulletObject''​s? A spawner is the thing to use.
  
-A spawner can be attached to an object (like our hero) and it can be told to spawn a specific type of object (like a bullet). Let's take this approach to start with. It won't be perfect, but we can always improve it later.+A spawner can be attached to an object (like our hero). And it can be told to spawn a specific type of object (like a bullet). Let's take this approach to start with. It won't be perfect, but we can always improve it later.
  
 Create a spawner for the hero: Create a spawner for the hero:
Line 36: Line 36:
 </​code>​ </​code>​
  
-Some words on the above. This spawner can shoot BulletObjects. It can shoot one at a time with 0.1 seconds between shots.+Some words on the above. 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>​
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 only command ​that is available to us for this purpose is: orxObject_Enable()+Great so that's working for us. Nowhow 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 dissapear. Not quite what is expected.+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.
  
 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 62: Line 62:
 What if the HeroObject had a single empty child object? And what if that child object had the spawner? Because it would be invisible, it wouldn'​t matter if it was turned on or off. What if the HeroObject had a single empty child object? And what if that child object had the spawner? Because it would be invisible, it wouldn'​t matter if it was turned on or off.
  
-Define ​it as the hero's gun:+Define ​an empty object ​as the hero's gun:
  
 <​code=ini>​ <​code=ini>​
 [HerosGun] [HerosGun]
 Spawner ​        = BulletSpawner Spawner ​        = BulletSpawner
-Position ​       = (10-7, 0)+Position ​       = (00, 0)
 </​code>​ </​code>​
  
-Remove the spawner from the hero object. Make HerosGun a child of HeroObject:+Remove the spawner from the hero object, and make ''​HerosGun'' ​a child of ''​HeroObject''​:
  
 <​code=ini>​ <​code=ini>​
 [HeroObject] [HeroObject]
 Graphic ​     = HeroGraphic Graphic ​     = HeroGraphic
-Position ​    = (50400, 0)+Position ​    = (-350100, 0)
 Scale        = 2 Scale        = 2
 AnimationSet = HeroAnimationSet AnimationSet = HeroAnimationSet
Line 99: Line 99:
 </​code>​ </​code>​
  
-Now that you have the reference, turn off the object at the bottom of the Init() function:+Now that you have the reference, turn off the ''​herosGun''​ immediately after creating it:
  
 <​code=cpp>​ <​code=cpp>​
Line 120: Line 120:
 Compile and run. Compile and run.
  
-Hmmm... his bullets don't go left when the hero faces left. Change the spawner:+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>​
Line 132: Line 132:
 </​code>​ </​code>​
  
-The ObjectSpeed property overrides the Speed property in the BulletObject (no it's not really needed anymore) and the UseRelativeSpeed means the ObjectSpeed with be applied relative to the direction of the spawner.+The ''​ObjectSpeed'' ​property overrides the ''​Speed'' ​property in the ''​BulletObject'' ​(no it's not really needed anymore) and the ''​UseRelativeSpeed'' ​means the ''​ObjectSpeed'' ​with be applied relative to the direction of the spawner.
  
 Compile and Run. Compile and Run.
en/guides/beginners/shooting_and_spawners.txt · Last modified: 2018/06/28 12:15 (3 weeks ago) by sausage