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; uint i = 0; uint l = (uint)_animations.Count; while (i < l) { if (_animations[(int)i].name == AnimName) { _curAnim = _animations[(int)i]; if (_curAnim.delay <= 0) { finished = true; } else { finished = false; } _curIndex = _curAnim.frames[_curFrame]; dirty = true; return; } i++; } FlxG.log("WARNING: No animation called \"" + AnimName + "\""); }
/** * Call this function to give this object a path to follow. * If the path does not have at least one node in it, this function * will log a warning message and return. * * @param Path The <code>FlxPath</code> you want this object to follow. * @param Speed How fast to travel along the path in pixels per second. * @param Mode Optional, controls the behavior of the object following the path using the path behavior constants. Can use multiple flags at once, for example PATH_YOYO|PATH_HORIZONTAL_ONLY will make an object move back and forth along the X axis of the path only. * @param AutoRotate Automatically point the object toward the next node. Assumes the graphic is pointing upward. Default behavior is false, or no automatic rotation. */ public void followPath(FlxPath Path, float Speed = 100, uint Mode = PATH_FORWARD, bool AutoRotate = false) { if (Path.nodes.Count <= 0) { FlxG.log("WARNING: Paths need at least one node in them to be followed."); return; } path = Path; pathSpeed = FlxU.abs(Speed); _pathMode = Mode; _pathRotate = AutoRotate; //get starting node if ((_pathMode == PATH_BACKWARD) || (_pathMode == PATH_LOOP_BACKWARD)) { _pathNodeIndex = path.nodes.Count - 1; _pathInc = -1; } else { _pathNodeIndex = 0; _pathInc = 1; } }
public override void update() { base.update(); if (scale.x < 1) { scale.x = 1; } if (scale.y < 1) { scale.y = 1; } if (flickering) { alpha = FlxG.random(); } if ((velocity.x != 0) || (velocity.y != 0)) { moving = true; } else { moving = false; } }
/// <summary> /// Initiate all the things needed by the engine /// </summary> internal static void init() { FlxG.defaultWholeScreenViewport = FlxG.viewport; FlxG.cameras = new List <FlxCamera>(); FlxG.viewports = new List <Viewport>(); //FlxG.width = FlxG.graphics.PreferredBackBufferWidth; //FlxG.height = FlxG.graphics.PreferredBackBufferHeight; FlxG.bgColor = Color.Black; FlxG.mute = false; FlxG.sounds = new FlxGroup(); FlxG.console = new FlxConsole(); FlxG.worldBounds = new FlxRect(); FlxG.defaultFont = FlxG.content.Load <SpriteFont>("ConsoleFont"); //FlxG.zoom = 1f; FlxG.rotation = 0f; FlxG.pad1 = new FlxGamepad(PlayerIndex.One); FlxG.pad2 = new FlxGamepad(PlayerIndex.Two); FlxG.pad3 = new FlxGamepad(PlayerIndex.Three); FlxG.pad4 = new FlxGamepad(PlayerIndex.Four); FlxG.keys = new FlxKeyboard(); FlxG.mouse = new FlxMouse(); FlxG.safeZone = new FlxRect(FlxG.graphicsDevice.Viewport.TitleSafeArea.X, FlxG.graphicsDevice.Viewport.TitleSafeArea.Y, FlxG.graphicsDevice.Viewport.TitleSafeArea.Width, FlxG.graphicsDevice.Viewport.TitleSafeArea.Height); FlxCamera defaultCam = new FlxCamera(0, 0, FlxG.width, FlxG.height, FlxG.zoom); FlxG.addCamera(defaultCam); //Thread tCreate = new Thread(FlxG.state.create); //tCreate.Start(); //create state last FlxG.state.create(); }
/// <summary> /// Simple Controller vibration /// </summary> /// <param name="Duration">The length in seconds the vibration should last</param> /// <param name="IntensityLeftMotor">The intensity of the Left Motor vibration</param> /// <param name="IntensityRightMotor">The intensity of the Right Motor vibration</param> /// <param name="ShakeScreen">Should the screen shake in unison with the controller vibration</param> public void vibrate(float Duration = 0.5f, float IntensityLeftMotor = 0.15f, float IntensityRightMotor = 0.15f, bool ShakeScreen = false) { vibeDuration = Duration; leftVibe = IntensityLeftMotor; rightVibe = IntensityRightMotor; if (ShakeScreen) { FlxG.shake(IntensityLeftMotor / 20, Duration); } }
/// <summary> /// Required XNA initialization along with some FlxG initializations. /// </summary> protected override void Initialize() { base.Initialize(); spriteBatch = new SpriteBatch(GraphicsDevice); // Basic FlxG inits that we need before we can call FlxG.init() FlxG.graphicsDevice = GraphicsDevice; FlxG.graphics = graphics; FlxG.content = Content; FlxG.spriteBatch = spriteBatch; FlxG.viewport = FlxG.graphicsDevice.Viewport; FlxG.width = graphics.PreferredBackBufferWidth; FlxG.height = graphics.PreferredBackBufferHeight; //Thread tInit = new Thread(FlxG.init); //tInit.Start(); FlxG.init(); }
static private FlxSound loadSound(SoundEffect EmbeddedSound, float Volume, bool Looped, bool AutoDestroy, bool AutoPlay) { if (EmbeddedSound == null) { FlxG.log("WARNING: FlxG.loadSound() requires an embedded sound to work."); return(null); } FlxSound sound = new FlxSound(); if (EmbeddedSound != null) { sound.loadEmbedded(EmbeddedSound, Looped, AutoDestroy); } sound.volume = Volume; if (AutoPlay) { sound.play(); } return(sound); }
/** * This function can be used both internally and externally to emit the next particle. */ public void emitParticle() { FlxPoint t = target.getMidpoint(); FlxParticle particle = recycle(typeof(FlxBasic)) as FlxParticle; particle.minSpeed = minParticleSpeed; particle.maxSpeed = maxParticleSpeed; particle.lifespan = lifespan; particle.elasticity = bounce; if (target != null) { particle.reset(t.x, t.y); } else { particle.reset(x - (Convert.ToInt32(particle.width) >> 1) + FlxG.random() * width, y - (Convert.ToInt32(particle.height) >> 1) + FlxG.random() * height); } particle.visible = true; particle.drag.x = particleDrag.x; particle.drag.y = particleDrag.y; particle.onEmit(); }
/// <summary> /// Update FlxG which updates important mechanics such as cameras and time elapsed. /// </summary> protected override void Update(GameTime gameTime) { base.Update(gameTime); //FlxG.gametime(gameTime); FlxG.update(gameTime); }
// update camera scroll in here // make sure it stays within bounds public override void update() { //zooming = FlxG.zoom; //rotating = FlxG.rotation; //follow closely or check deadzones if (target != null) { if (deadzone == null) { focusOn(target.getMidpoint()); //add getMidpoint() for FlxObjects } else { //FlxG.log("deadzone is not null"); float edge; float targetX = FlxU.ceil(target.x + ((target.x > 0) ? 0.0000001f : -0.0000001f)); float targetY = FlxU.ceil(target.y + ((target.y > 0) ? 0.0000001f : -0.0000001f)); edge = targetX - deadzone.x; if (scroll.x > edge) { scroll.x = edge; } edge = targetX + target.width - deadzone.x - deadzone.width; if (scroll.x < edge) { scroll.x = edge; } edge = targetY - deadzone.y; if (scroll.y > edge) { scroll.y = edge; } edge = targetY + target.height - deadzone.y - deadzone.height; if (scroll.y < edge) { scroll.y = edge; } //SHAKE } } //make sure we didnt go outside camera's bounds if (bounds != null) { //FlxG.log("bounds is not null"); if (scroll.x < bounds.left) { scroll.x = bounds.left; } if (scroll.x > bounds.right - width) { scroll.x = bounds.right - width; } if (scroll.y < bounds.top) { scroll.y = bounds.top; } if (scroll.y > bounds.bottom - height) { scroll.y = bounds.bottom - height; } } //update effects //shake if (_fxShakeDuration > 0) { _fxShakeDuration -= FlxG.elapsed; if (_fxShakeDuration <= 0) { _fxShakeOffset.make(); if (_fxShakeComplete != null) { _fxShakeComplete(); } } else { if ((_fxShakeDirection == SHAKE_BOTH_AXES) || (_fxShakeDirection == SHAKE_HORIZONTAL_ONLY)) { _fxShakeOffset.x = (FlxG.random() * _fxShakeIntensity * width * 2 - _fxShakeIntensity * width) * _zoom; } if ((_fxShakeDirection == SHAKE_BOTH_AXES) || (_fxShakeDirection == SHAKE_VERTICAL_ONLY)) { _fxShakeOffset.y = (FlxG.random() * _fxShakeIntensity * height * 2 - _fxShakeIntensity * height) * _zoom; } } } scroll.x -= _fxShakeOffset.x; scroll.y -= _fxShakeOffset.y; if (zooming < 1) { zooming = 1; } }
/// <summary> /// Play a sound, not with FlxSound but with SoundEffect from the XNA framework because the sound is disposed of /// properly by the xbox itself. /// /// CURRENTLY NOT WORKING /// /// The sound starts but cuts off in about half of a second. /// </summary> /// <param name="EmbeddedSound"></param> /// <param name="Volume"></param> /// <param name="Looped"></param> /// <returns></returns> static public FlxSound play(SoundEffect EmbeddedSound, float Volume = 1.0f, bool Looped = false) { return(FlxG.loadSound(EmbeddedSound, Volume, Looped, (Looped)?false:true, true)); }