//This is run when you flip the collision private void onCollision() { isCollisionOn = !isCollisionOn; if (isCollisionOn) { if (isGravityOn) { floor.Solid = true; //Set the floor to the 'active' collision barrier floor.Visible = true; wall.Solid = false; wall.Visible = false; } else { floor.Solid = false; //Set the wall to the 'active' collision barrier floor.Visible = false; wall.Solid = true; wall.Visible = true; } topText.text = "Collision: ON"; } else { //Turn off the wall and floor, completely wall.Solid = floor.Solid = wall.Visible = floor.Visible = false; topText.text = "Collision: OFF"; } topText.Alpha = 1; FlxG.log("Toggle Collision"); }
override public void create() { FlxG.resetHud(); FlxG.showHud(); FlxG.backColor = Color.LightGray; base.create(); string levelData = FlxU.randomString(10); FlxG.log("levelData: " + levelData); makeCave(0.1f, Color.Black); makeCave(0.5f, new Color(0.98f, 1.0f, 0.95f)); makeCave2(1.0f, Color.Green); spaceShip = new FlxSprite(60, 60); spaceShip.loadGraphic(FlxG.Content.Load <Texture2D>("flixel/surt/spaceship_32x32"), true, false, 32, 32); spaceShip.addAnimation("Static", new int[] { 0 }, 36, true); spaceShip.addAnimation("Transform", new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 }, 36, false); spaceShip.play("Static"); spaceShip.setDrags(1100, 1100); add(spaceShip); FlxG.follow(spaceShip, 10.0f); FlxG.followBounds(0, 0, 50 * 16, 40 * 16); }
/// <summary> /// Plays an existing animation (e.g. "run"). /// If you call an animation that is already playing it will be ignored. /// </summary> /// <param name="animName">The string name of the animation you want to play.</param> /// <param name="force">Whether to force the animation to restart.</param> public void play(String animName, Boolean force = false) { if (!force && (_curAnim != null) && (animName == _curAnim.Name) && (_curAnim.Looped || !Finished)) { return; } _curFrame = 0; _curIndex = 0; _frameTimer = 0; foreach (FlxAnim animation in _animations) { if (animation.Name.Equals(animName)) { _curAnim = animation; if (_curAnim.Delay <= 0) { Finished = true; } else { Finished = false; } _curIndex = _curAnim.Frames[_curFrame]; Dirty = true; return; } } FlxG.log("WARNING: No animation called \"" + animName + "\""); }
/** * You can use this if you have a lot of text parameters to set instead of * the individual properties. * * @param Font The name of the font face for the text display. * @param Size The size of the font (in pixels essentially). * @param Color The color of the text in 0xRRGGBB format. * @param Alignment A string representing the desired alignment * ("left,"right" or "center"). * @param ShadowColor An int representing the desired text shadow color * 0xAARRGGBB format. * @param ShadowX The x-position of the shadow, default is 1. * @param ShadowY The y-position of the shadow, default is 1. * * @return This FlxText instance (nice for chaining stuff together, if * you're into that). */ public FlxText setFormat(String Font, float size, Color color, String Alignment, Color ShadowColor, float ShadowX = 1f, float ShadowY = 1f) { if (Font == null) { Font = _font; } _size = (int)FlxU.floor(size); if (Font != null && (!Font.Equals(_font) || size != _size)) { try { //_textField = new SpriteBatch(FlxG.loadFont(Font, FlxU.round(Size), _bitmapFontParameter)); //_textField = new SpriteBatch(GraphicsDevice); } catch (Exception e) { Console.WriteLine(e.Message); FlxG.log(e.Message); //_textField = new SpriteBatch(FlxG.loadFont("org/flixel/data/font/nokiafc.fnt", 22, _bitmapFontParameter)); } _font = Font; LoadedFont = FlxS.ContentManager.Load <SpriteFont> (_font); } Color = color; if (Alignment != null) { _alignment = (Alignment.ToUpper()); } _shadow = ShadowColor; _shadowX = ShadowX; _shadowY = ShadowY; calcFrame(); return(this); }
//This is run when you flip the gravity private void onGravity() { isGravityOn = !isGravityOn; if (isGravityOn) { theEmitter.gravity = 200; if (isCollisionOn) { floor.Visible = true; floor.Solid = true; wall.Visible = false; wall.Solid = false; } //Just for the sake of completeness let's go ahead and make this change happen //to all of the currently emitted particles as well. for (int i = 0; i < theEmitter.Members.Count; i++) { ((FlxParticle)theEmitter.Members[i]).Acceleration.Y = 200; //Cast the pixel from the emitter as a particle so we can use it } topText.text = "Gravity: ON"; } else { theEmitter.gravity = 0; if (isCollisionOn) { wall.Visible = true; wall.Solid = true; floor.Visible = false; floor.Solid = false; } for (int i = 0; i < theEmitter.Members.Count; i++) { ((FlxParticle)theEmitter.Members[i]).Acceleration.Y = 0; } topText.text = "Gravity: OFF"; } topText.Alpha = 1; FlxG.log("Toggle Gravity"); }