public override void create () { FlxG.debug = true; // The grass background FlxSprite grass = new FlxSprite (0, 0).loadGraphic (ImgGrass, false, false, FlxG.width, FlxG.height); add (grass); add (_bunnies = new FlxGroup ()); // Text display add (_bunnyCounter = new FlxText (0, FlxG.height - 20, FlxG.width).setFormat (null, 8, Color.White, "right", Color.Black)); add (_memoryUsage = new FlxText (5, FlxG.height - 20, 200).setFormat (null, 8, Color.White, "left", Color.Black)); // Buttons Left side float leftBtnY = 20; add (new FlxButton (leftBtnY, 25, "+" + INITIAL_AMOUNT, addBunnies)); add (new FlxButton (leftBtnY, 50, "-" + INITIAL_AMOUNT, removeBunnies)); // Buttons right side float rightBtnX = FlxG.width - 100; add (_complexityButton = new FlxButton (rightBtnX, 25, "Complex", ComplexityCallback)); add (_collisionButton = new FlxButton (rightBtnX, 65, "Collision ON", CollisionCallback)); // Finally create the bunnies addBunnies (); // Force GC GC.Collect (); // Timer to update the memory usage _memoryTimer = new FlxTimer (); updateMemoryUsage (); // Show mouse pointer FlxG.mouse.show (); }
override public void create() { FlxG.Framerate = 50; //FlxG.flashFramerate = 50; // Creates a new tilemap with no arguments collisionMap = new FlxTilemap(); /* * FlxTilemaps are created using strings of comma seperated values (csv) * This string ends up looking something like this: * * 0,0,0,0,0,0,0,0,0,0, * 0,0,0,0,0,0,0,0,0,0, * 0,0,0,0,0,0,1,1,1,0, * 0,0,1,1,1,0,0,0,0,0, * ... * * Each '0' stands for an empty tile, and each '1' stands for * a solid tile * * When using the auto map generation, the '1's are converted into the corresponding frame * in the tileset. */ // Initializes the map using the generated string, the tile images, and the tile size collisionMap.loadMapFile(default_auto, auto_tiles, (int)TILE_WIDTH, (int)TILE_HEIGHT, FlxTilemap.AUTO); add(collisionMap); highlightBox = new FlxObject(0, 0, TILE_WIDTH, TILE_HEIGHT); setupPlayer(); // When switching between modes here, the map is reloaded with it's own data, so the positions of tiles are kept the same // Notice that different tilesets are used when the auto mode is switched autoAltBtn = new FlxButton(4, FlxG.height - 24, "AUTO", altButtonFunc); add(autoAltBtn); resetBtn = new FlxButton(8 + autoAltBtn.Width, FlxG.height - 24, "Reset", resetButtonFunc); add(resetBtn); quitBtn = new FlxButton(FlxG.width - resetBtn.Width - 4, FlxG.height - 24, "Quit", onQuit); add(quitBtn); helperTxt = new FlxText(5, 5, 150, "Click to place tiles. Shift-Click to remove tiles\nArrow keys to move"); add(helperTxt); // Show mouse pointer FlxG.mouse.show(); }
public override void create() { FlxG.debug = true; // The grass background FlxSprite grass = new FlxSprite(0, 0).loadGraphic(ImgGrass, false, false, FlxG.width, FlxG.height); add(grass); add(_bunnies = new FlxGroup()); // Text display add(_bunnyCounter = new FlxText(0, FlxG.height - 20, FlxG.width).setFormat(null, 8, Color.White, "right", Color.Black)); add(_memoryUsage = new FlxText(5, FlxG.height - 20, 200).setFormat(null, 8, Color.White, "left", Color.Black)); // Buttons Left side float leftBtnY = 20; add(new FlxButton(leftBtnY, 25, "+" + INITIAL_AMOUNT, addBunnies)); add(new FlxButton(leftBtnY, 50, "-" + INITIAL_AMOUNT, removeBunnies)); // Buttons right side float rightBtnX = FlxG.width - 100; add(_complexityButton = new FlxButton(rightBtnX, 25, "Complex", ComplexityCallback)); add(_collisionButton = new FlxButton(rightBtnX, 65, "Collision ON", CollisionCallback)); // Finally create the bunnies addBunnies(); // Force GC GC.Collect(); // Timer to update the memory usage _memoryTimer = new FlxTimer(); updateMemoryUsage(); // Show mouse pointer FlxG.mouse.show(); }
override public void create () { FlxG.Framerate = 50; //FlxG.flashFramerate = 50; // Creates a new tilemap with no arguments collisionMap = new FlxTilemap (); /* * FlxTilemaps are created using strings of comma seperated values (csv) * This string ends up looking something like this: * * 0,0,0,0,0,0,0,0,0,0, * 0,0,0,0,0,0,0,0,0,0, * 0,0,0,0,0,0,1,1,1,0, * 0,0,1,1,1,0,0,0,0,0, * ... * * Each '0' stands for an empty tile, and each '1' stands for * a solid tile * * When using the auto map generation, the '1's are converted into the corresponding frame * in the tileset. */ // Initializes the map using the generated string, the tile images, and the tile size collisionMap.loadMapFile (default_auto, auto_tiles, (int)TILE_WIDTH, (int)TILE_HEIGHT, FlxTilemap.AUTO); add (collisionMap); highlightBox = new FlxObject (0, 0, TILE_WIDTH, TILE_HEIGHT); setupPlayer (); // When switching between modes here, the map is reloaded with it's own data, so the positions of tiles are kept the same // Notice that different tilesets are used when the auto mode is switched autoAltBtn = new FlxButton (4, FlxG.height - 24, "AUTO", altButtonFunc); add (autoAltBtn); resetBtn = new FlxButton (8 + autoAltBtn.Width, FlxG.height - 24, "Reset", resetButtonFunc); add (resetBtn); quitBtn = new FlxButton (FlxG.width - resetBtn.Width - 4, FlxG.height - 24, "Quit", onQuit); add (quitBtn); helperTxt = new FlxText (5, 5, 150, "Click to place tiles. Shift-Click to remove tiles\nArrow keys to move"); add (helperTxt); // Show mouse pointer FlxG.mouse.show (); }
override public void create() { FlxG.Framerate = 60; //FlxG.flashFramerate = 60; //Here we actually initialize out emitter //The parameters are X Y Size (Maximum number of particles the emitter can store) theEmitter = new FlxEmitter(10, FlxG.height / 2, 200); //Now by default the emitter is going to have some properties set on it and can be used immediately //but we're going to change a few things. //First this emitter is on the side of the screen, and we want to show off the movement of the particles //so lets make them launch to the right. theEmitter.setXSpeed(100, 200); //and lets funnel it a tad theEmitter.setYSpeed(-50, 50); //Let's also make our pixels rebound off surfaces theEmitter.bounce = 0.8f; //Now let's add the emitter to the state. add(theEmitter); //Now it's almost ready to use, but first we need to give it some pixels to spit out! //Lets fill the emitter with some white pixels for (int i = 0; i < theEmitter.maxSize / 2; i++) { whitePixel = new FlxParticle(); whitePixel.makeGraphic(2, 2, new Color(0xFF, 0xFF, 0xFF)); whitePixel.Visible = false; //Make sure the particle doesn't show up at (0, 0) theEmitter.add(whitePixel); whitePixel = new FlxParticle(); whitePixel.makeGraphic(1, 1, new Color(0xFF, 0xFF, 0xFF)); whitePixel.Visible = false; theEmitter.add(whitePixel); } //Now let's setup some buttons for messing with the emitter. collisionButton = new FlxButton(0, FlxG.height - 22, "Collision", onCollision); add(collisionButton); gravityButton = new FlxButton(80, FlxG.height - 22, "Gravity", onGravity); add(gravityButton); quitButton = new FlxButton(FlxG.width - 80, FlxG.height - 22, "Quit", onQuit); add(quitButton); //I'll just leave this here topText = new FlxText(0, 2, FlxG.width, "Welcome"); topText.setAlignment("center"); add(topText); //Lets setup some walls for our pixels to collide against collisionGroup = new FlxGroup(); wall = new FlxSprite(100, (FlxG.height / 2) - 50); wall.makeGraphic(10, 100, new Color(0xFF, 0xFF, 0xFF, 0x50)); //Make it darker - easier on the eyes :) wall.Visible = wall.Solid = false; //Set both the visibility AND the solidity to false, in one go wall.Immovable = true; //Lets make sure the pixels don't push out wall away! (though it does look funny) collisionGroup.add(wall); //Duplicate our wall but this time it's a floor to catch gravity affected particles floor = new FlxSprite(10, 267); floor.makeGraphic((uint)FlxG.width - 20, 10, new Color(0xFF, 0xFF, 0xFF, 0x50)); floor.Visible = floor.Solid = false; floor.Immovable = true; collisionGroup.add(floor); //Please note that this demo makes the walls themselves not collide, for the sake of simplicity. //Normally you would make the particles have solid = true or false to make them collide or not on creation, //because in a normal environment your particles probably aren't going to change solidity at a mouse //click. If they did, you would probably be better suited with emitter.setAll("solid", true) //I just don't feel that setAll is applicable here(Since I would still have to toggle the walls anyways) //Don't forget to add the group to the state(Like I did :P) add(collisionGroup); //Now lets set our emitter free. //Params: Explode, Particle Lifespan, Emit rate(in seconds) theEmitter.start(false, 3, .01f); //Let's re show the cursors FlxG.mouse.show(); //Mouse.hide(); }
public override void create() { //Kick the framerate back up FlxG.Framerate = 60; //FlxG.flashFramerate = 60; //Let's setup our elevator, for some wonderful crate bashing goodness elevator = new FlxSprite((FlxG.width / 2) - 100, 250, elevatorPNG); //Make it able to collide, and make sure it's not tossed around elevator.Solid = elevator.Immovable = true; //And add it to the state add(elevator); //Now lets get some crates to smash around, normally I would use an emitter for this //kind of scene, but for this demo I wanted to use regular sprites //(See ParticlesDemo for an example of an emitter with colliding particles) //We'll need a group to place everything in - this helps a lot with collisions crateStormGroup = new FlxGroup(); for (int i = 0; i < numCrates; i++) { crate = new FlxSprite((FlxG.random() * 200) + 100, 20); crate.loadRotatedGraphic(cratePNG, 16, 0); //This loads in a graphic, and 'bakes' some rotations in so we don't waste resources computing real rotations later crate.AngularVelocity = FlxG.random() * 50-150; //Make it spin a tad crate.Acceleration.Y = 300; //Gravity crate.Acceleration.X = -50; //Some wind for good measure crate.MaxVelocity.Y = 500; //Don't fall at 235986mph crate.MaxVelocity.X = 200; //" fly " " crate.Elasticity = FlxG.random(); //Let's make them all bounce a little bit differently crateStormGroup.add(crate); } add(crateStormGroup); //And another group, this time - Red crates crateStormGroup2 = new FlxGroup(); for (int i = 0; i < numCrates; i++) { crate = new FlxSprite((FlxG.random() * 200) + 100, 20); crate.loadRotatedGraphic(cratePNG, 16, 1); crate.AngularVelocity = FlxG.random() * 50-150; crate.Acceleration.Y = 300; crate.Acceleration.X = 50; crate.MaxVelocity.Y = 500; crate.MaxVelocity.X = 200; crate.Elasticity = FlxG.random(); crateStormGroup2.add(crate); } add(crateStormGroup2); //Now what we're going to do here is add both of those groups to a new containter group //This is useful if you had something like, coins, enemies, special tiles, etc.. that would all need //to check for overlaps with something like a player. crateStormMegaGroup = new FlxGroup (); crateStormMegaGroup.add(crateStormGroup); crateStormMegaGroup.add(crateStormGroup2); //Cute little flixel logo that will ride the elevator flixelRider = new FlxSprite((FlxG.width / 2) - 13, 0, flixelRiderPNG); flixelRider.Solid = flixelRider.Visible = flixelRider.Exists = false; //But we don't want him on screen just yet... flixelRider.Acceleration.Y = 800; add(flixelRider); //This is for the text at the top of the screen topText = new FlxText(0, 2, FlxG.width, "Welcome"); topText.setAlignment("center"); add(topText); //Lets make a bunch of buttons! YEAH!!! crateStorm = new FlxButton(2, FlxG.height - 22, "Crate Storm", onCrateStorm); add(crateStorm); flxRiderButton = new FlxButton(82, FlxG.height - 22, "Flixel Rider", onFlixelRider); add(flxRiderButton); crateStormG1 = new FlxButton(162, FlxG.height - 22, "Blue Group", onBlue); add(crateStormG1); crateStormG2 = new FlxButton(242, FlxG.height - 22, "Red Group", onRed); add(crateStormG2); groupCollision = new FlxButton(202, FlxG.height - 42, "Collide Groups", onCollideGroups); add(groupCollision); quitButton = new FlxButton(320, FlxG.height - 22, "Quit", onQuit); add(quitButton); //And lets get the flixel cursor visible again FlxG.mouse.show(); //Mouse.hide(); }
override public void create() { FlxG.Framerate = 60; //FlxG.flashFramerate = 60; //Here we actually initialize out emitter //The parameters are X Y Size (Maximum number of particles the emitter can store) theEmitter = new FlxEmitter(10, FlxG.height / 2, 200); //Now by default the emitter is going to have some properties set on it and can be used immediately //but we're going to change a few things. //First this emitter is on the side of the screen, and we want to show off the movement of the particles //so lets make them launch to the right. theEmitter.setXSpeed(100, 200); //and lets funnel it a tad theEmitter.setYSpeed( -50, 50); //Let's also make our pixels rebound off surfaces theEmitter.bounce = 0.8f; //Now let's add the emitter to the state. add(theEmitter); //Now it's almost ready to use, but first we need to give it some pixels to spit out! //Lets fill the emitter with some white pixels for (int i = 0; i < theEmitter.maxSize/2; i++) { whitePixel = new FlxParticle(); whitePixel.makeGraphic(2, 2, new Color(0xFF,0xFF,0xFF)); whitePixel.Visible = false; //Make sure the particle doesn't show up at (0, 0) theEmitter.add(whitePixel); whitePixel = new FlxParticle(); whitePixel.makeGraphic(1, 1, new Color(0xFF,0xFF,0xFF)); whitePixel.Visible = false; theEmitter.add(whitePixel); } //Now let's setup some buttons for messing with the emitter. collisionButton = new FlxButton(0, FlxG.height - 22, "Collision", onCollision); add(collisionButton); gravityButton = new FlxButton(80, FlxG.height - 22, "Gravity", onGravity); add(gravityButton); quitButton = new FlxButton(FlxG.width-80, FlxG.height - 22, "Quit", onQuit); add(quitButton); //I'll just leave this here topText = new FlxText(0, 2, FlxG.width, "Welcome"); topText.setAlignment("center"); add(topText); //Lets setup some walls for our pixels to collide against collisionGroup = new FlxGroup(); wall= new FlxSprite(100, (FlxG.height/2)-50); wall.makeGraphic(10, 100, new Color(0xFF,0xFF,0xFF,0x50));//Make it darker - easier on the eyes :) wall.Visible = wall.Solid = false;//Set both the visibility AND the solidity to false, in one go wall.Immovable = true;//Lets make sure the pixels don't push out wall away! (though it does look funny) collisionGroup.add(wall); //Duplicate our wall but this time it's a floor to catch gravity affected particles floor = new FlxSprite(10, 267); floor.makeGraphic((uint)FlxG.width - 20, 10, new Color(0xFF,0xFF,0xFF,0x50)); floor.Visible = floor.Solid = false; floor.Immovable = true; collisionGroup.add(floor); //Please note that this demo makes the walls themselves not collide, for the sake of simplicity. //Normally you would make the particles have solid = true or false to make them collide or not on creation, //because in a normal environment your particles probably aren't going to change solidity at a mouse //click. If they did, you would probably be better suited with emitter.setAll("solid", true) //I just don't feel that setAll is applicable here(Since I would still have to toggle the walls anyways) //Don't forget to add the group to the state(Like I did :P) add(collisionGroup); //Now lets set our emitter free. //Params: Explode, Particle Lifespan, Emit rate(in seconds) theEmitter.start(false, 3, .01f); //Let's re show the cursors FlxG.mouse.show(); //Mouse.hide(); }
public override void create() { //Kick the framerate back up FlxG.Framerate = 60; //FlxG.flashFramerate = 60; //Let's setup our elevator, for some wonderful crate bashing goodness elevator = new FlxSprite((FlxG.width / 2) - 100, 250, elevatorPNG); //Make it able to collide, and make sure it's not tossed around elevator.Solid = elevator.Immovable = true; //And add it to the state add(elevator); //Now lets get some crates to smash around, normally I would use an emitter for this //kind of scene, but for this demo I wanted to use regular sprites //(See ParticlesDemo for an example of an emitter with colliding particles) //We'll need a group to place everything in - this helps a lot with collisions crateStormGroup = new FlxGroup(); for (int i = 0; i < numCrates; i++) { crate = new FlxSprite((FlxG.random() * 200) + 100, 20); crate.loadRotatedGraphic(cratePNG, 16, 0); //This loads in a graphic, and 'bakes' some rotations in so we don't waste resources computing real rotations later crate.AngularVelocity = FlxG.random() * 50 - 150; //Make it spin a tad crate.Acceleration.Y = 300; //Gravity crate.Acceleration.X = -50; //Some wind for good measure crate.MaxVelocity.Y = 500; //Don't fall at 235986mph crate.MaxVelocity.X = 200; //" fly " " crate.Elasticity = FlxG.random(); //Let's make them all bounce a little bit differently crateStormGroup.add(crate); } add(crateStormGroup); //And another group, this time - Red crates crateStormGroup2 = new FlxGroup(); for (int i = 0; i < numCrates; i++) { crate = new FlxSprite((FlxG.random() * 200) + 100, 20); crate.loadRotatedGraphic(cratePNG, 16, 1); crate.AngularVelocity = FlxG.random() * 50 - 150; crate.Acceleration.Y = 300; crate.Acceleration.X = 50; crate.MaxVelocity.Y = 500; crate.MaxVelocity.X = 200; crate.Elasticity = FlxG.random(); crateStormGroup2.add(crate); } add(crateStormGroup2); //Now what we're going to do here is add both of those groups to a new containter group //This is useful if you had something like, coins, enemies, special tiles, etc.. that would all need //to check for overlaps with something like a player. crateStormMegaGroup = new FlxGroup(); crateStormMegaGroup.add(crateStormGroup); crateStormMegaGroup.add(crateStormGroup2); //Cute little flixel logo that will ride the elevator flixelRider = new FlxSprite((FlxG.width / 2) - 13, 0, flixelRiderPNG); flixelRider.Solid = flixelRider.Visible = flixelRider.Exists = false; //But we don't want him on screen just yet... flixelRider.Acceleration.Y = 800; add(flixelRider); //This is for the text at the top of the screen topText = new FlxText(0, 2, FlxG.width, "Welcome"); topText.setAlignment("center"); add(topText); //Lets make a bunch of buttons! YEAH!!! crateStorm = new FlxButton(2, FlxG.height - 22, "Crate Storm", onCrateStorm); add(crateStorm); flxRiderButton = new FlxButton(82, FlxG.height - 22, "Flixel Rider", onFlixelRider); add(flxRiderButton); crateStormG1 = new FlxButton(162, FlxG.height - 22, "Blue Group", onBlue); add(crateStormG1); crateStormG2 = new FlxButton(242, FlxG.height - 22, "Red Group", onRed); add(crateStormG2); groupCollision = new FlxButton(202, FlxG.height - 42, "Collide Groups", onCollideGroups); add(groupCollision); quitButton = new FlxButton(320, FlxG.height - 22, "Quit", onQuit); add(quitButton); //And lets get the flixel cursor visible again FlxG.mouse.show(); //Mouse.hide(); }