Timeline for Star Scrolling

edited November 2014 in General discussions
Just for fun, I did up a parallax star scrolling routine using Timeline tracks.

No graphics needed, just using Texture = pixel which creates a single pixel graphic. The config is:
[FastStarsObjectGroup]
TrackList	= FastStarsTrack

[MediumStarsObjectGroup]
TrackList	= MediumStarsTrack

[SlowStarsObjectGroup]
TrackList	= SlowStarsTrack


[FastStarObject]
Graphic = FastStarGraphic
Position = (0, 1, 0) ~ (0, 799, 0)
Speed		= (200, 0, 0)
TrackList = FastStarTrack

[MediumStarObject@FastStarObject]
Graphic = MediumStarGraphic
Speed		= (150, 0, 0)
TrackList = MediumStarTrack

[SlowStarObject@FastStarObject]
Graphic = SlowStarGraphic
Speed		= (100, 0, 0)
TrackList = SlowStarTrack


[FastStarGraphic]
Texture = pixel
Color   = (200, 200, 200) ~ (255, 255, 255)

[MediumStarGraphic]
Texture = pixel
Color   = (100, 100, 100) ~ (200, 200, 200)

[SlowStarGraphic]
Texture = pixel
Color   = (50, 50, 50) ~ (100, 100, 100)


[FastStarsTrack]
.05 = Object.Create FastStarObject
Loop = true

[MediumStarsTrack]
.03 = Object.Create MediumStarObject
Loop = true

[SlowStarsTrack]
.01 = Object.Create SlowStarObject
Loop = true

[FastStarTrack]
4 = Object.SetLifeTime ^ 0

[MediumStarTrack]
6 = Object.SetLifeTime ^ 0

[SlowStarTrack]
8 = Object.SetLifeTime ^ 0

And the code to create the three star groups:
orxObject_CreateFromConfig("FastStarsObjectGroup");
orxObject_CreateFromConfig("MediumStarsObjectGroup");
orxObject_CreateFromConfig("SlowStarsObjectGroup");

No doubt that could be more efficient, but it works well. The result looks something like this:

stars.png

Three groups of stars are constantly created every few milliseconds, and scroll at different speeds, with slightly different colours, giving the impression of depth. They are destroyed after they leave the screen area.

It performs well but I wonder if a more optimised real-world method would be to create tens of pre-rendered "tiles" of stars, rather than thousands of single pixel objects.

I haven't measured it to find out.

Anyway, a bit of fun. Enjoy.
stars 3.5K

Comments

  • edited November 2014
    Not speaking of optimizations per se, but I would slightly simplify two things:
    - I wouldn't use a track to set the lifetime of the objects, I'd simply use the LifeTime property (it is also more efficient, but I don't know by how much)
    - I'd group all the 3 planes into a same object hierarchy:
    [Starfield]
    ChildList = FastStarsObjectGroup # MediumStarsObjectGroup # SlowStarsObjectGroup
    
    and
    orxObject_CreateFromConfig("Starfield");
    
  • edited November 2014
    It could actually even be simplified to something like this, but it's more of a matter of personal taste, (not mentioning that spawners are probably more adapted for this exercise ;)).
    [Starfield] 
    TrackList = FastStarsTrack # MediumStarsTrack # SlowStarsTrack
    
  • edited November 2014
    Ah yep... why would I be adding LifeTime to the track when I can just add it to the Object. That's true. Added some tweaks, and the config becomes:
    [StarField]
    ChildList = #FastStarsObjectGroup #MediumStarsObjectGroup #SlowStarsObjectGroup
    
    [FastStarsObjectGroup]
    TrackList	= FastStarsTrack
    
    [MediumStarsObjectGroup]
    TrackList	= MediumStarsTrack
    
    [SlowStarsObjectGroup]
    TrackList	= SlowStarsTrack
    
    [FastStarObject]
    Graphic 	= FastStarGraphic
    Position 	= (0, 1, 0) ~ (0, 799, 0)
    Speed		= (200, 0, 0)
    LifeTime 	= 4
    Scale = (2, 1, 1)
    
    [MediumStarObject@FastStarObject]
    Graphic 	= MediumStarGraphic
    Speed		= (150, 0, 0)
    LifeTime 	= 6
    
    [SlowStarObject@FastStarObject]
    Graphic 	= SlowStarGraphic
    Speed		= (100, 0, 0)
    LifeTime 	= 8
    
    [FastStarGraphic]
    Texture = pixel
    Color   = (220, 220, 220) ~ (255, 255, 255)
    
    [MediumStarGraphic]
    Texture = pixel
    Color   = (180, 180, 180) ~ (220, 220, 220)
    
    [SlowStarGraphic]
    Texture = pixel
    Color   = (100, 100, 100) ~ (180, 180, 180)
    
    [FastStarsTrack]
    .05 = Object.Create FastStarObject
    Loop = true
    
    [MediumStarsTrack]
    .03 = Object.Create MediumStarObject
    Loop = true
    
    [SlowStarsTrack]
    .01 = Object.Create SlowStarObject
    Loop = true
    

    But quite right.... this job is much better done by a spawner.
  • edited November 2014
    And here is the spawner version, which is cleaner and much easier to set up:
    [StarField]
    Spawner   = Spawner
    Position  = (1, 1, 0)
    
    [Spawner]
    Object      = FastStarObject #MediumStarObject #SlowStarObject
    WaveSize    = 1
    WaveDelay   = 0.01
    
    [FastStarObject]
    Graphic 	= FastStarGraphic
    Position 	= (0, 1, 0) ~ (0, 799, 0)
    Speed		= (200, 0, 0)
    LifeTime 	= 4
    Scale 		= (2, 1, 1)
    
    [MediumStarObject@FastStarObject]
    Graphic 	= MediumStarGraphic
    Speed		= (150, 0, 0)
    LifeTime 	= 6
    
    [SlowStarObject@FastStarObject]
    Graphic 	= SlowStarGraphic
    Speed		= (100, 0, 0)
    LifeTime 	= 8
    
    [FastStarGraphic]
    Texture = pixel
    Color   = (220, 220, 220) ~ (255, 255, 255)
    
    [MediumStarGraphic]
    Texture = pixel
    Color   = (180, 180, 180) ~ (220, 220, 220)
    
    [SlowStarGraphic]
    Texture = pixel
    Color   = (100, 100, 100) ~ (180, 180, 180)
    
Sign In or Register to comment.