Skip to content

Conversation

@ezacharyk
Copy link

Modifying FlxStarfield and FlxStarfield2D to Utilize a 0 speed for static starfield.

I needed a version of Starfield with stationary stars. So I modified Starfield and Starfield2d to accommodate for a static field by setting the starspeed to 0, specifically, the max speed.

When creating a new Starfield2D, just set the speed to 0:
var stars = new FlxStarField2D(); stars.setStarSpeed(0,0);

The FlxStarfield and FlxStarfield2D then check if the speed is 0 and if so, it does not move the stars. It retains the ability for the stars to twinkle by setting a FlxG.random.float(0,1) in the FlxStarfield.draw function when assigning the colorIndex.

@Vortex2Oblivion
Copy link
Contributor

What are these classes even used for-

@ezacharyk
Copy link
Author

ezacharyk commented Aug 22, 2025

What are these classes even used for-

These classes create an animated starfield background for your game. The 2d one, makes the stars fly in a horizontal or vertical direction. The 3d one makes the stars fly like when Star Wars ships start up hyperspace.

Here is an example with the 2D starfield:
https://heroofdermwood.itch.io/bgp-planets

@Vortex2Oblivion
Copy link
Contributor

I feel like it would be a good idea to say what they do in a comment or something then since they don't have any descriptions right now.

@ezacharyk
Copy link
Author

I feel like it would be a good idea to say what they do in a comment or something then since they don't have any descriptions right now.

Good point. I have added comments to the classes to provide those descriptions

@ezacharyk
Copy link
Author

Realized I missed a step in the Code Review Process. Here is a public repo with a running test of the FlxStarfield2D class with the above changes:
https://github.com/ezacharyk/flixel-test-projects/tree/main/StarFieldTest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants