/// <summary> /// Helper function, just copies the values from the specified rectangle. /// </summary> /// <param name="rect">Any <code>FlxRect</code>.</param> /// <returns>A reference to itself.</returns> public FlxRect copyFrom(FlxRect rect) { X = rect.X; Y = rect.Y; Width = rect.Width; Height = rect.Height; return(this); }
/// <summary> /// Specify the boundaries of the level or where the camera is allowed to move. /// </summary> /// <param name="x">The smallest X value of your level (usually 0).</param> /// <param name="y">The smallest Y value of your level (usually 0).</param> /// <param name="width">The largest X value of your level (usually the level width).</param> /// <param name="height">The largest Y value of your level (usually the level height).</param> /// <param name="updateWorld">Whether the global quad-tree's dimensions should be updated to match (default: false).</param> public void setBounds(float x = 0, float y = 0, float width = 0, float height = 0, Boolean updateWorld = false) { if (Bounds == null) { Bounds = new FlxRect(); } Bounds.make(x, y, width, height); if (updateWorld) { FlxG.worldBounds.copyFrom(Bounds); } update(); }
public override void destroy() { // flx# - can animations in _animations be null? /* * if(_animations != null) * { * FlxAnim a; * int i = 0; * int l = _animations.Count; * while(i < l) * { * a = _animations[i++]; * if(a != null) * a.destroy(); * } * _animations = null; * } */ if (_animations != null) { foreach (FlxAnim animation in _animations) { animation.destroy(); } } _flashPoint = null; _flashRect = null; _flashRect2 = null; _flashPointZero = null; Offset = null; Origin = null; Scale = null; _curAnim = null; //_matrix = null; // flx# - matrix is a struct _callback = null; //_framePixels = null; // flx# - unused }
/// <summary> /// Clean up memory. /// </summary> public override void destroy() { screen.destroy(); screen = null; Target = null; Scroll = null; Deadzone = null; Bounds = null; Buffer = null; //_flashBitmap = null; //_flashRect = null; //_flashPoint = null; fxFlashComplete = null; fxFadeComplete = null; fxShakeComplete = null; fxShakeOffset = null; //_fill = null; base.destroy(); }
public override void destroy() { // flx# - can animations in _animations be null? /* if(_animations != null) { FlxAnim a; int i = 0; int l = _animations.Count; while(i < l) { a = _animations[i++]; if(a != null) a.destroy(); } _animations = null; } */ if (_animations != null) { foreach (FlxAnim animation in _animations) { animation.destroy(); } } _flashPoint = null; _flashRect = null; _flashRect2 = null; _flashPointZero = null; Offset = null; Origin = null; Scale = null; _curAnim = null; //_matrix = null; // flx# - matrix is a struct _callback = null; //_framePixels = null; // flx# - unused }
/// <summary> /// Creates a white 8x8 square <code>FlxSprite</code> at the specified position. /// Optionally can load a simple, one-frame graphic instead. /// </summary> /// <param name="x">The initial X position of the sprite.</param> /// <param name="y">The initial Y position of the sprite.</param> /// <param name="graphic">The graphic you want to display (OPTIONAL - for simple stuff only, do NOT use for animated images!).</param> public FlxSprite(float x = 0, float y = 0, Texture2D graphic = null) : base(x, y) { Health = 1; _flashPoint = new FlxPoint(); _flashRect = new FlxRect(); _flashRect2 = new FlxRect(); _flashPointZero = new FlxPoint(0, 0); Offset = new FlxPoint(); Origin = new FlxPoint(); Scale = new FlxPoint(1, 1); Alpha = 1; Color = Color.White; Blend = null; AntiAliasing = false; Cameras = null; Finished = false; _facing = Right; _animations = new List<FlxAnim>(); _flipped = 0; _curAnim = null; _curFrame = 0; _curIndex = 0; _frameTimer = 0; _matrix = new Matrix(); _callback = null; if (graphic == null) { graphic = ImgDefault; } loadGraphic(graphic); // flx# stuff Angle = 0f; camX = camY = 0; oX = x; oY = y; moving = false; /* Scale = new FlxPoint(1.0f, 1.0f); Offset = new FlxPoint(); Origin = new FlxPoint(); alpha = 1.0f; _color = Color.White * alpha; _animations = new List<FlxAnim>(); _animated = false; Finished = false; _facing = Right; _flipped = 0; _curAnim = null; _curFrame = 0; _curIndex = 0; _frameTimer = 0; _callback = null; _matrix = new Matrix(); if (graphic == null) graphic = ImgDefault; loadGraphic(graphic); Angle = 0f; camX = camY = 0; oX = x; oY = y; moving = false; */ }
/// <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 = screen.Pixels; BgColor = FlxG.bgColor; _color = Color.White; //_color = 0xffffffff; /* * _flashBitmap = new Bitmap(buffer); * _flashBitmap.x = -width*0.5; * _flashBitmap.y = -height*0.5; * _flashSprite = new Sprite(); */ // flx# - ? // 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> /// Copy the bounds, focus object, and deadzone info from an existing camera. /// </summary> /// <param name="camera">The camera you want to copy from.</param> /// <returns>A reference to this <code>FlxCamera</code> object.</returns> public FlxCamera copyFrom(FlxCamera camera) { if (camera.Bounds == null) { this.Bounds = null; } else { if (this.Bounds == null) { this.Bounds = new FlxRect(); } this.Bounds.copyFrom(camera.Bounds); } this.Target = camera.Target; if (this.Target != null) { if (camera.Deadzone == null) { this.Deadzone = null; } else { if (this.Deadzone == null) { this.Deadzone = new FlxRect(); } this.Deadzone.copyFrom(camera.Deadzone); } } return this; }
/// <summary> /// Helper function, just copies the values from the specified rectangle. /// </summary> /// <param name="rect">Any <code>FlxRect</code>.</param> /// <returns>A reference to itself.</returns> public FlxRect copyFrom(FlxRect rect) { X = rect.X; Y = rect.Y; Width = rect.Width; Height = rect.Height; return this; }
/// <summary> /// Load an image from an embedded graphic file. /// </summary> /// <param name="graphic">The image you want to use.</param> /// <param name="animated">Whether the Graphic parameter is a single sprite or a row of sprites.</param> /// <param name="reverse">Whether you need this class to generate horizontally flipped versions of the animation frames.</param> /// <param name="width">Optional, specify the width of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).</param> /// <param name="height">Optional, specify the height of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).</param> /// <param name="unique">Optional, whether the graphic should be a unique instance in the graphics cache. Default is false.</param> /// <returns></returns> public FlxSprite loadGraphic(Texture2D graphic, Boolean animated = false, Boolean reverse = false, float width = 0, float height = 0, bool unique = false) { if (unique || reverse) { throw new NotSupportedException(); } _bakedRotation = 0; // flx# - if reversed, addBitmap doubles the texture width and draws // a flipped image beside the original one. thus all these * 2 / 2 // calculations below //_pixels = FlxG.addBitmap(graphic, reverse, unique); _pixels = graphic; if (reverse) { _flipped = (uint)_pixels.Width >> 1; } else { _flipped = 0; } if (width == 0) { if (animated) { width = _pixels.Width; } else if (_flipped > 0) { width = _pixels.Width * 0.5f; } else { width = _pixels.Width; } } Width = width; FrameWidth = width; if (height == 0) { if (animated) { height = width; } else { height = _pixels.Height; } } Height = height; FrameHeight = height; resetHelpers(); // flx# stuff drawSourceRect = new Rectangle(0, 0, (int)Width, (int)Height); _animated = animated; texture = graphic; sourceRect = new FlxRect(0, 0, width, height); return(this); }
/// <summary> /// Creates a white 8x8 square <code>FlxSprite</code> at the specified position. /// Optionally can load a simple, one-frame graphic instead. /// </summary> /// <param name="x">The initial X position of the sprite.</param> /// <param name="y">The initial Y position of the sprite.</param> /// <param name="graphic">The graphic you want to display (OPTIONAL - for simple stuff only, do NOT use for animated images!).</param> public FlxSprite(float x = 0, float y = 0, Texture2D graphic = null) : base(x, y) { Health = 1; _flashPoint = new FlxPoint(); _flashRect = new FlxRect(); _flashRect2 = new FlxRect(); _flashPointZero = new FlxPoint(0, 0); Offset = new FlxPoint(); Origin = new FlxPoint(); Scale = new FlxPoint(1, 1); Alpha = 1; Color = Color.White; Blend = null; AntiAliasing = false; Cameras = null; Finished = false; _facing = Right; _animations = new List <FlxAnim>(); _flipped = 0; _curAnim = null; _curFrame = 0; _curIndex = 0; _frameTimer = 0; _matrix = new Matrix(); _callback = null; if (graphic == null) { graphic = ImgDefault; } loadGraphic(graphic); // flx# stuff Angle = 0f; camX = camY = 0; oX = x; oY = y; moving = false; /* * Scale = new FlxPoint(1.0f, 1.0f); * Offset = new FlxPoint(); * Origin = new FlxPoint(); * alpha = 1.0f; * _color = Color.White * alpha; * * _animations = new List<FlxAnim>(); * _animated = false; * * Finished = false; * _facing = Right; * _flipped = 0; * _curAnim = null; * _curFrame = 0; * _curIndex = 0; * _frameTimer = 0; * * _callback = null; * _matrix = new Matrix(); * * if (graphic == null) * graphic = ImgDefault; * loadGraphic(graphic); * * Angle = 0f; * * camX = camY = 0; * oX = x; * oY = y; * * moving = false; */ }
/// <summary> /// Tells this camera object what <code>FlxObject</code> to track. /// </summary> /// <param name="target">The object you want the camera to track. Set to null to not follow anything.</param> /// <param name="style">Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling <code>follow()</code>.</param> public void follow(FlxObject target, uint style = StyleLockon) { Target = target; float helper; switch (style) { case StylePlatformer: float w = Width / 8; float h = Height / 3; Deadzone = new FlxRect((Width - w) / 2, (Height - h) / 2 - h * 0.25f, w, h); break; case StyleTopdown: helper = FlxU.max(Width, Height) / 4; Deadzone = new FlxRect((Width - helper) / 2, (Height - helper) / 2, helper, helper); break; case StyleTopdownTight: helper = FlxU.max(Width, Height) / 8; Deadzone = new FlxRect((Width - helper) / 2, (Height - helper) / 2, helper, helper); break; case StyleLockon: break; case StyleLoose: Deadzone = new FlxRect(0, 0, Width, Height); break; default: Deadzone = null; break; } }
/// <summary> /// Load an image from an embedded graphic file. /// </summary> /// <param name="graphic">The image you want to use.</param> /// <param name="animated">Whether the Graphic parameter is a single sprite or a row of sprites.</param> /// <param name="reverse">Whether you need this class to generate horizontally flipped versions of the animation frames.</param> /// <param name="width">Optional, specify the width of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).</param> /// <param name="height">Optional, specify the height of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).</param> /// <param name="unique">Optional, whether the graphic should be a unique instance in the graphics cache. Default is false.</param> /// <returns></returns> public FlxSprite loadGraphic(Texture2D graphic, Boolean animated = false, Boolean reverse = false, float width = 0, float height = 0, bool unique = false) { if (unique || reverse) { throw new NotSupportedException(); } _bakedRotation = 0; // flx# - if reversed, addBitmap doubles the texture width and draws // a flipped image beside the original one. thus all these * 2 / 2 // calculations below //_pixels = FlxG.addBitmap(graphic, reverse, unique); _pixels = graphic; if (reverse) { _flipped = (uint)_pixels.Width >> 1; } else { _flipped = 0; } if (width == 0) { if (animated) { width = _pixels.Width; } else if (_flipped > 0) { width = _pixels.Width * 0.5f; } else { width = _pixels.Width; } } Width = width; FrameWidth = width; if (height == 0) { if (animated) { height = width; } else { height = _pixels.Height; } } Height = height; FrameHeight = height; resetHelpers(); // flx# stuff drawSourceRect = new Rectangle(0, 0, (int)Width, (int)Height); _animated = animated; texture = graphic; sourceRect = new FlxRect(0, 0, width, height); return this; }
/// <summary> /// Helper function, just copies the values from this rectangle to the specified rectangle. /// </summary> /// <param name="rect">Any <code>FlxRect</code>.</param> /// <returns>A reference to the altered rectangle parameter.</returns> public FlxRect copyTo(FlxRect rect) { rect.X = X; rect.Y = Y; rect.Width = Width; rect.Height = Height; return this; }
/// <summary> /// This function creates a flat colored square image dynamically. /// </summary> /// <param name="width">The width of the sprite you want to generate.</param> /// <param name="height">The height of the sprite you want to generate.</param> /// <param name="color">Specifies the color of the generated block.</param> /// <param name="unique">Whether the graphic should be a unique instance in the graphics cache. Default is false.</param> /// <param name="key">Optional parameter - specify a string key to identify this graphic in the cache. Trumps Unique flag.</param> /// <returns></returns> public FlxSprite makeGraphic(uint width, uint height, Color color, bool unique = false, string key = null) { if (unique || !string.IsNullOrEmpty(key)) { throw new NotSupportedException(); } _bakedRotation = 0; _pixels = FlxG.createBitmap(width, height, color, unique, key); Width = width; FrameWidth = width; Height = height; FrameHeight = height; resetHelpers(); // flx# stuff drawSourceRect = new Rectangle(0, 0, (int)width, (int)height); texture = _pixels; sourceRect = new FlxRect(0, 0, width, height); return this; }
/// <summary> /// Checks to see if some <code>FlxRect</code> object overlaps this <code>FlxRect</code> object. /// </summary> /// <param name="rect">The rectangle being tested.</param> /// <returns>Whether or not the two rectangles overlap.</returns> public Boolean overlaps(FlxRect rect) { return (rect.X + rect.Width > X) && (rect.X < X + Width) && (rect.Y + rect.Height > Y) && (rect.Y < Y + Height); }
/// <summary> /// Checks to see if some <code>FlxRect</code> object overlaps this <code>FlxRect</code> object. /// </summary> /// <param name="rect">The rectangle being tested.</param> /// <returns>Whether or not the two rectangles overlap.</returns> public Boolean overlaps(FlxRect rect) { return((rect.X + rect.Width > X) && (rect.X < X + Width) && (rect.Y + rect.Height > Y) && (rect.Y < Y + Height)); }
/// <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 = screen.Pixels; BgColor = FlxG.bgColor; _color = Color.White; //_color = 0xffffffff; /* _flashBitmap = new Bitmap(buffer); _flashBitmap.x = -width*0.5; _flashBitmap.y = -height*0.5; _flashSprite = new Sprite(); */ // flx# - ? // 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(); }