This is an old revision of the document!
This is a follow-on from UseParentSpace for Relative Object Positioning and Scaling.
In the same way that child Objects can use the
UseParentSpace property to operate within a Parent's relative position and scale… spawners can benefit from the same functionality.
To help you work through this tutorial, first create a new blank project using the init script.
In general when specifying what object to spawn, the object is given screen co-ordinates like:
Position = (35, 100, 0.0)
With relative positioning, the object that is spawned will be positioned relative to the Parent Object (the one that has a spawner attached).
That can be confusing. Let's view it as a tree:
It is the Object to Spawn, that will use the
But before we get there, lets start the usual screen coordinate way.
Let's start by making a rain cloud that spawns raindrops. Here's a cloud for you to use:
Cloud object in config:
[Cloud] Spawner = RainSpawner Pivot = center Graphic = @ Texture = cloud.png Position = (0.0, -200.0, -0.1)
Then change the
Cloud in the create line in the code:
This will give a cloud object a little up from the centre of the screen. We haven't provided a spawner yet so it doesn't do anything. Define the spawner, and object to swap with:
[RainSpawner] Object = RainDrop TotalObject = 0 ActiveObject = 1000 WaveSize = 5 WaveDelay = 0.005 ~ 0.03 ObjectSpeed = (-400, 800) [RainDrop] Graphic = @ Texture = pixel Size = (1,20) ~ (1,40) Alpha = 0.3 ~ 0.8 Color = (255,255,255) Pivot = top AutoScroll = both DepthScale = true LifeTime = 1.0 Smoothing = true Rotation = 22.5 Position = (-50.0, 00.0, 0.0) ~ (90.0, 00.0, 0.5)
In the spawner config above, make it spawn
RainDrop objects, lots of them, in a fast down-right direction.
RainDrop objects themselves, vary their alpha transparency, their stretched size and their starting position on screen between X = -50.0 to 90.
There is no image for the raindrops, we're just using a stretched pixel that is rotated 22 degrees to match the direction. That will do nicely.
The last step is to convert the positioning to be relative to the Cloud's size. This means changing the
Position property of the
RainDrop and setting
UseParentSpace to both:
[RainDrop] Graphic = @ Texture = pixel Size = (1,20) ~ (1,40) Alpha = 0.3 ~ 0.8 Color = (255,255,255) Pivot = top AutoScroll = both DepthScale = true LifeTime = 1.0 Smoothing = true Rotation = 22.5 Position = (-0.3, 00.0, 0.0) ~ (0.45, 00.0, 0.5) UseParentSpace = both
Because the pivot of the
Cloud is centred, the coordinate range is (-0.5, -0.5) to (0.5, 0.5). I've adjusted the X positions to between -0.3 and 0.45 to bring the positions in a little to work nicer with the cloud itself.
The result should be the same: