skip to content
Orx Learning
User Tools
Admin
Log In
Site Tools
Search
Tools
Show page
Old revisions
Export to PDF
Backlinks
Recent Changes
Media Manager
Sitemap
Log In
>
Recent Changes
Media Manager
Sitemap
Trace:
Welcome
Beginner's Guide
Config
Examples
Tutorials
en:tutorials:objects:lifetime
====== Object Lifetime ====== Objects have the concept of a lifetime. This is where you can specify a value in seconds, and the object will live only for that amount of time. This is perfect for spawned objects like bullets, or temporary objects. But you can also specify one or more literals to create lifetime situations that are a little richer. Before getting into that, let's [[en:tutorials:projects:creating_your_own_project|create a blank project using the init script]]. ===== Numeric Lifetime ===== Let's begin will the most straight forward example, a numeric lifetime. Add a lifetime of 5.0 to the ''Object'' section: <code ini> [Object] Graphic = @ Texture = logo.png SoundList = @ Sound = appear.ogg Pivot = center AngularVelocity = 18 FXList = FadeIn # ColorCycle LifeTime = 5.0 </code> Compile and run. The logo object will turn for 5 seconds and then disappear. It's dead. Completely gone. ===== FX Lifetime ===== The ''fx'' literal means that the object's life will only end after any fx that are attached end first. Change the object's lifetime to ''fx'': <code ini> [Object] Graphic = @ Texture = logo.png SoundList = @ Sound = appear.ogg Pivot = center AngularVelocity = 18 FXList = FadeIn # ColorCycle LifeTime = fx </code> The fx currently attached to the object is in a loop, so this condition will never be reached. Change the loop property on the ''ColorCycle'' fx to false: <code ini> [ColorCycle] Loop = false ... </code> Then run that. The logo will cycle its colour once and then its life will end. Nice. ===== Sound Lifetime ===== In this case, if there is a sound attached to the object which plays on object creation, the object will die once the sound finishes playing. This is a nice enhancement over time based lifetimes because if you decide to change the sound your object uses, you no longer need to be mindful of how long or short the sound goes for. <code ini> [Object] Graphic = @ Texture = logo.png SoundList = @ Sound = appear.ogg Pivot = center AngularVelocity = 18 FXList = FadeIn # ColorCycle LifeTime = sound </code> Run that and as soon as the appearance sound is finished, the object's life is over. ===== Anim Lifetime ===== For an object, using the ''anim'' literal means that when all animations have finished playing on your object, then the object will be destroyed. <code ini> [Object] Graphic = @ Texture = logo.png SoundList = @ Sound = appear.ogg Pivot = center AngularVelocity = 18 FXList = FadeIn # ColorCycle LifeTime = anim </code> Check out the [[en:tutorials:main#animation|animation tutorials]] to learn about the animation system and give the ''anim'' literal a try. ===== Child Lifetime ===== For the last three lifetime literal types, I won't go into any code examples. I'll leave that as an exercise for the reader, as they simply follow the same principle. <code ini> [Object] Graphic = @ Texture = logo.png SoundList = @ Sound = appear.ogg Pivot = center AngularVelocity = 18 FXList = FadeIn # ColorCycle LifeTime = child ChildList = Child1 # Child2 # Child3 </code> A ''child'' lifetime is one where the object's lifetime does not end unless the lifetime of its children ends first. For example, you might have a boss alien made up of many parts. Once all the parts are destroyed, the final parent object will finally be removed. ===== Spawn Lifetime ===== In a similar manner to the child lifetime literal, a ''spawn'' lifetime is one where the object's life does not end until it finishes spawning. <code ini> [Object] Graphic = @ Texture = logo.png SoundList = @ Sound = appear.ogg Pivot = center AngularVelocity = 18 FXList = FadeIn # ColorCycle LifeTime = spawn Spawner = MySpawner </code> This operates on the ''TotalObjects'' property of the spawner. Once the spawned objects are exhausted, the object will die. Clearly if the spawner is set to infinite spawning, the lifetime will not work. ===== Track Lifetime ===== Using this literal, the object's life will end when the attached track has finished it's job. <code ini> [Object] Graphic = @ Texture = logo.png SoundList = @ Sound = appear.ogg Pivot = center AngularVelocity = 18 FXList = FadeIn # ColorCycle LifeTime = track Track = MyTrack </code> ===== Multiple Lifetime literals ===== You can combine two or more literals. If you do this, the object's lifetime will not end until all of the conditions are exhausted. For example: <code ini> [Object] Graphic = @ Texture = logo.png SoundList = @ Sound = appear.ogg Pivot = center AngularVelocity = 18 FXList = FadeIn # ColorCycle LifeTime = sound fx </code> In this case, the sound will play and the fx will complete it's single cycle. Once both conditions are complete, it's curtains for the object. ==== Conclusion ==== There's a lot of combinations and scenarios that be covered with multiple lifetimes. I can see sound, fx and track being extremely useful. ===== See also ===== - [[en:examples:objects:kill_parent_object_when_children_die|Having a Parent Object die after all children have died]] - [[en:orx:config:settings_structure:orxobject|orxOBJECT structure]]
en/tutorials/objects/lifetime.txt
ยท Last modified: 2025/09/30 17:26 (14 months ago) by
127.0.0.1
Page Tools
Show page
Old revisions
Backlinks
Export to PDF
Rename Page
Back to top