Skip to content
Browse files

added paralax scroll

  • Loading branch information...
1 parent 4667669 commit b06d55d294dcb43b659dc0ef2bf2ab8756cb92fa @bmac committed
Showing with 69 additions and 2 deletions.
  1. +1 −1 Pocket Universe.as3proj
  2. BIN assets/star.png
  3. +27 −1 src/Level.as
  4. +41 −0 src/Star.as
View
2 Pocket Universe.as3proj
@@ -82,7 +82,7 @@
<postBuildCommand alwaysRun="False" />
<!-- Other project options -->
<options>
- <option showHiddenPaths="False" />
+ <option showHiddenPaths="True" />
<option testMovie="Default" />
</options>
<!-- Plugin storage -->
View
BIN assets/star.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
28 src/Level.as
@@ -12,6 +12,7 @@ package
private var planets:FlxGroup = new FlxGroup();
protected var player:Player;
private var obstacles:FlxGroup;
+ private var starfield:FlxGroup;
private var music:MusicController;
//camera options
@@ -43,12 +44,37 @@ package
music = new MusicController();
- add(new FlxSprite(0,0,bg));
+ //add(new FlxSprite(0,0,bg));
// add all to the world
add(planets);
//add(obstacles);
add(player);
+
+ FlxG.bgColor = 0xff181818;
+
+ starfield = new FlxGroup();
+ add(starfield);
+
+ for (var i:int = 0; i < 150; i++)
+ {
+ var s:Star = new Star();
+ s.spawn(Math.random() * FlxG.camera.screen.width, Math.random() * FlxG.camera.screen.height - 10);
+ s.scrollFactor = new FlxPoint(-0.05, -0.05);
+ starfield.add(s);
+
+ }
+ for (var i:int = 0; i < 150; i++)
+ {
+ s = new Star();
+ s.spawn(Math.random() * FlxG.camera.screen.width, Math.random() * FlxG.camera.screen.height - 10);
+ s.scrollFactor = new FlxPoint(-0.025, -0.025);
+ starfield.add(s);
+
+ }
+
+
+
}
override public function update():void
View
41 src/Star.as
@@ -0,0 +1,41 @@
+package
+{
+ import org.flixel.*;
+
+ public class Star extends FlxSprite
+ {
+
+ [Embed(source="../assets/star.png")]private var star_img:Class;
+
+ public function Star()
+ {
+ super();
+ loadGraphic(star_img, true, false, 8, 8);
+ }
+
+ // Instead of using the constructor to position the stars we'll do it separately
+ public function spawn(x:int, y:int) : void
+ {
+ this.x = x;
+ this.y = y;
+ frame = Math.random() * 3; // Choose a random frame
+
+ // The downwards velocity is based on the size
+ //velocity.y = (frame * 10) + 20 + Math.random() * 0;
+ // Random transparency
+ alpha = 0.25 * Math.random() + 0.25;
+ }
+
+ override public function update():void
+ {
+ // Respawn it when it goes offscreen
+ if (y > FlxG.height)
+ {
+ y = -8;
+ spawn(Math.random() * FlxG.width, -8);
+ }
+ super.update();
+ }
+
+ }
+}

0 comments on commit b06d55d

Please sign in to comment.
Something went wrong with that request. Please try again.