public FlxConsole() : base() { bg = new FlxSprite(80, 40); bg.makeGraphic((uint)FlxS.GraphicsDevice.Viewport.Width - 160, (uint)FlxS.GraphicsDevice.Viewport.Height - 80, FlxColor.WHITE * 0.45f); bg.Alpha = 0.5f; add(bg); ScrollFactor.X = ScrollFactor.Y = 0; Visible = false; //text = new FlxText(100, 60, FlxS.GraphicsDevice.Viewport.Width - 160, "internal console is a work in progress", FlxG.defaultFont); //text.setFormat(FlxColor.WHITE); text.Alpha = 0.75f; add(text); }
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() { // Background color FlxG.bgColor = (FlxColor.GREEN); FlxG.worldBounds = new FlxRect(0, 0, 320, 240); //Design your platformer level with 1s and 0s (at 40x30 to fill 320x240 screen) int[] data = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; //Create a new tilemap using our level data level = new FlxTilemap (); level.loadMap (FlxTilemap.arrayToCSV (data, 40), FlxTilemap.ImgAuto, 0, 0, FlxTilemap.AUTO); add (level); //Create the level exit, a dark gray box that is hidden at first exit = new FlxSprite (35 * 8 + 1, 25 * 8); exit.makeGraphic (14, 16, FlxColor.BLUE); exit.Exists = false; add (exit); //Create coins to collect (see createCoin() function below for more info) coins = new FlxGroup (); //Top left coins createCoin (18, 4); createCoin (12, 4); createCoin (9, 4); createCoin (8, 11); createCoin (1, 7); createCoin (3, 4); createCoin (5, 2); createCoin (15, 11); createCoin (16, 11); //Bottom left coins createCoin (3, 16); createCoin (4, 16); createCoin (1, 23); createCoin (2, 23); createCoin (3, 23); createCoin (4, 23); createCoin (5, 23); createCoin (12, 26); createCoin (13, 26); createCoin (17, 20); createCoin (18, 20); //Top right coins createCoin (21, 4); createCoin (26, 2); createCoin (29, 2); createCoin (31, 5); createCoin (34, 5); createCoin (36, 8); createCoin (33, 11); createCoin (31, 11); createCoin (29, 11); createCoin (27, 11); createCoin (25, 11); createCoin (36, 14); //Bottom right coins createCoin (38, 17); createCoin (33, 17); createCoin (28, 19); createCoin (25, 20); createCoin (18, 26); createCoin (22, 26); createCoin (26, 26); createCoin (30, 26); add (coins); //Create player (a red box) player = new FlxSprite (FlxG.width / 2 - 5); player.makeGraphic (10, 12, FlxColor.RED); player.MaxVelocity.X = 80; player.MaxVelocity.Y = 200; player.Acceleration.Y = 200; player.Drag.X = player.MaxVelocity.X * 4; add (player); score = new FlxText (2, 2, 80, "SCORE: "); //score.setShadow(FlxColor.BLACK); score.text = "SCORE: " + (coins.CountDead () * 100); add (score); status = new FlxText (FlxG.width - 160 - 2, 2, 160); //status.setShadow(0xff000000); //status.setAlignment("right"); switch (FlxG.score) { case 0: status.text = "Collect coins."; break; case 1: status.text = "Aww, you died!"; break; } add (status); }
//creates a new coin located on the specified tile public void createCoin (int X, int Y) { FlxSprite coin = new FlxSprite (X * 8 + 3, Y * 8 + 2); coin.makeGraphic (2, 4, FlxColor.YELLOW); coins.add (coin); }
/// <summary> /// Instantiates a new camera at the specified location, with the specified size and zoom level. /// </summary> /// <param name="x">X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param> /// <param name="y">Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param> /// <param name="width">The width of the camera display in pixels.</param> /// <param name="height">The height of the camera display in pixels.</param> /// <param name="zoom">The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.</param> public FlxCamera(float x, float y, int width, int height, float zoom = 0) : base() { X = x; Y = y; Width = width; Height = height; Target = null; Deadzone = null; Scroll = new FlxPoint(); _point = new FlxPoint(); Bounds = null; screen = new FlxSprite(); screen.makeGraphic((uint) width, (uint) height, new Color(0, 0, 0, 0)); screen.setOriginToCorner(); //Buffer = (RenderTarget2D)screen.Pixels; BgColor = FlxG.bgColor; _color = Color.White; /* _flashBitmap = new Bitmap(buffer); _flashBitmap.x = -width*0.5; _flashBitmap.y = -height*0.5; _flashSprite = new Sprite(); */ zoom = Zoom; //sets the scale of flash sprite, which in turn loads flashoffset values /* _flashOffsetX = width*0.5*zoom; _flashOffsetY = height*0.5*zoom; _flashSprite.x = x + _flashOffsetX; _flashSprite.y = y + _flashOffsetY; _flashSprite.addChild(_flashBitmap); _flashRect = new Rectangle(0,0,width,height); _flashPoint = new Point(); */ fxFlashColor = Color.Black; fxFlashDuration = 0.0f; fxFlashComplete = null; fxFlashAlpha = 0.0f; fxFadeColor = Color.Black; fxFadeDuration = 0.0f; fxFadeComplete = null; fxFadeAlpha = 0.0f; fxShakeIntensity = 0.0f; fxShakeDuration = 0.0f; fxShakeComplete = null; fxShakeOffset = new FlxPoint(); fxShakeDirection = 0; //_fill = new BitmapData(width,height,true,0); // flx# //DefaultZoom = 1.0f; rotating = 0.0f; Zoom = zoom; FlashSprite = new FlxObject(); //BgColor = Color.Black; _fxHelperTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); _fxHelperTexture.SetData(new[] { Color.White }); _fillTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); _fillTexture.SetData(new[] { Color.White }); UpdateHelpers(); }
/// <summary> /// Instantiates a new camera at the specified location, with the specified size and zoom level. /// </summary> /// <param name="x">X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param> /// <param name="y">Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param> /// <param name="width">The width of the camera display in pixels.</param> /// <param name="height">The height of the camera display in pixels.</param> /// <param name="zoom">The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.</param> public FlxCamera(float x, float y, int width, int height, float zoom = 0) : base() { X = x; Y = y; Width = width; Height = height; Target = null; Deadzone = null; Scroll = new FlxPoint(); _point = new FlxPoint(); Bounds = null; screen = new FlxSprite(); screen.makeGraphic((uint)width, (uint)height, new Color(0, 0, 0, 0)); screen.setOriginToCorner(); //Buffer = (RenderTarget2D)screen.Pixels; BgColor = FlxG.bgColor; _color = Color.White; /* * _flashBitmap = new Bitmap(buffer); * _flashBitmap.x = -width*0.5; * _flashBitmap.y = -height*0.5; * _flashSprite = new Sprite(); */ zoom = Zoom; //sets the scale of flash sprite, which in turn loads flashoffset values /* * _flashOffsetX = width*0.5*zoom; * _flashOffsetY = height*0.5*zoom; * _flashSprite.x = x + _flashOffsetX; * _flashSprite.y = y + _flashOffsetY; * _flashSprite.addChild(_flashBitmap); * _flashRect = new Rectangle(0,0,width,height); * _flashPoint = new Point(); */ fxFlashColor = Color.Black; fxFlashDuration = 0.0f; fxFlashComplete = null; fxFlashAlpha = 0.0f; fxFadeColor = Color.Black; fxFadeDuration = 0.0f; fxFadeComplete = null; fxFadeAlpha = 0.0f; fxShakeIntensity = 0.0f; fxShakeDuration = 0.0f; fxShakeComplete = null; fxShakeOffset = new FlxPoint(); fxShakeDirection = 0; //_fill = new BitmapData(width,height,true,0); // flx# //DefaultZoom = 1.0f; rotating = 0.0f; Zoom = zoom; FlashSprite = new FlxObject(); //BgColor = Color.Black; _fxHelperTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); _fxHelperTexture.SetData(new[] { Color.White }); _fillTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); _fillTexture.SetData(new[] { Color.White }); UpdateHelpers(); }