/// <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(); }
public void follow(FlxCamera Camera = null, int Border = 0, Boolean UpdateWorld = false) { if (Camera == null) { Camera = FlxG.camera; } Camera.setBounds(x + Border * tileSize, y + Border * tileSize, width - Border * tileSize * 2, height - Border * tileSize * 2, UpdateWorld); }
/// <summary> /// Check to see if this object is currently on the screen /// </summary> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns>bool</returns> public virtual bool onScreen(FlxCamera Camera = null) { if (Camera == null) { Camera = FlxG.camera; } getScreenXY(_point, Camera); return((_point.x + width > 0) && (_point.x < Camera.width) && (_point.y + height > 0) && (_point.y < Camera.height)); }
static public FlxCamera addCamera(FlxCamera NewCamera) { FlxG.camera = NewCamera; FlxG.cameras.Add(NewCamera); Viewport v = new Viewport((int)NewCamera.x, (int)NewCamera.y, (int)NewCamera.width, (int)NewCamera.height); //FlxG.log("camera is at x: " + NewCamera.x + " y: " + NewCamera.y + " width: " + NewCamera.width + " height " + NewCamera.height); //FlxG.log("camera count: " + FlxG.cameras.Count); FlxG.viewports.Add(v); return(NewCamera); }
/// <summary> /// Not yet implemented /// </summary> /// <param name="Camera">Which Camera - currently only one exists</param> public override void drawDebug(FlxCamera Camera = null) { if (Camera == null) { Camera = FlxG.camera; } //get bounding box coordinates float boundingBoxX = x - (int)(Camera.scroll.x * scrollFactor.x); //copied from getScreenXY() float boundingBoxY = y - (int)(Camera.scroll.y * scrollFactor.y); boundingBoxX = (int)(boundingBoxX + ((boundingBoxX > 0)?0.0000001f:-0.0000001f)); boundingBoxY = (int)(boundingBoxY + ((boundingBoxY > 0)?0.0000001f:-0.0000001f)); int boundingBoxWidth = (int)((width != (int)(width)) ? width : width - 1f); int boundingBoxHeight = (int)((height != (int)(height)) ?height : height - 1f); ////fill static graphics object with square shape //var gfx:Graphics = FlxG.flashGfx; //gfx.clear(); //gfx.moveTo(boundingBoxX,boundingBoxY); Color boundingBoxColor; if (Convert.ToBoolean(allowCollisions)) { if (allowCollisions != ANY) { boundingBoxColor = FlxColor.PINK; } if (immovable) { boundingBoxColor = FlxColor.GREEN; } else { boundingBoxColor = FlxColor.RED; } } else { boundingBoxColor = FlxColor.BLUE; } //gfx.lineStyle(1,boundingBoxColor,0.5); //gfx.lineTo(boundingBoxX+boundingBoxWidth,boundingBoxY); //gfx.lineTo(boundingBoxX+boundingBoxWidth,boundingBoxY+boundingBoxHeight); //gfx.lineTo(boundingBoxX,boundingBoxY+boundingBoxHeight); //gfx.lineTo(boundingBoxX,boundingBoxY); ////draw graphics shape to camera buffer //Camera.buffer.draw(FlxG.flashGfxSprite); }
/// <summary> /// Call this to figure out the on-screen position of the object /// </summary> /// <param name="Point">Take a FlxPoint object and assign the post-scrolled X and Y values of this object to it</param> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns></returns> public FlxPoint getScreenXY(FlxPoint Point = null, FlxCamera Camera = null) { if (Point == null) { Point = new FlxPoint(); } if (Camera == null) { Camera = FlxG.camera; } Point.x = x - (Camera.scroll.x * scrollFactor.x); Point.y = y - (Camera.scroll.y * scrollFactor.y); Point.x += (Point.x > 0)?0.0000001f:-0.0000001f; Point.y += (Point.y > 0)?0.0000001f:-0.0000001f; return(Point); }
public override void draw() { if (dirty) { calcFrame(); } if (cameras == null) { cameras = FlxG.cameras; } FlxCamera camera = FlxG.camera; int i = 0; int l = cameras.Count; while (i < l) { camera = cameras[i++]; //camera = FlxG.camera; if (!onScreen(camera)) { continue; } _point.x = x - (int)(camera.scroll.x * scrollFactor.x) - offset.x; _point.y = y - (int)(camera.scroll.y * scrollFactor.y) - offset.y; _point.x += (_point.x > 0) ? 0.0000001f : -0.0000001f; _point.y += (_point.y > 0) ? 0.0000001f : -0.0000001f; if (visible) { base.draw(); if (texture != null) { //if the sprite is animated then the sourceRect needs to be changed to be the correct frame if (_animated) { sourceRect = new FlxRect(frameWidth * _curIndex, 0, frameWidth, frameHeight); } Rectangle rect = new Rectangle((int)sourceRect.x, (int)sourceRect.y, (int)sourceRect.width, (int)sourceRect.height); FlxG.spriteBatch.Draw(texture, getVec2(), rect, _color * alpha, angle, new Vector2(), scale.getVec2(), SpriteEffects.None, 0f); } } } }
override public bool onScreen(FlxCamera Camera = null) { if (Camera == null) { Camera = FlxG.camera; } getScreenXY(_point, Camera); _point.x = _point.x - offset.x; _point.y = _point.y - offset.y; float halfWidth = frameWidth / 2; float halfHeight = frameHeight / 2; float absScaleX = (scale.x > 0) ? scale.x : -scale.x; float absScaleY = (scale.y > 0) ? scale.y : -scale.y; float radius = (float)Math.Sqrt(halfWidth * halfWidth + halfHeight * halfHeight) * ((absScaleX >= absScaleY) ? absScaleX : absScaleY); _point.x += halfWidth; _point.y += halfHeight; return((_point.x + radius > 0) && (_point.x - radius < Camera.width) && (_point.y + radius > 0) && (_point.y - radius < Camera.height)); }
protected void drawTilemap(FlxCamera Camera) { //no need because draw() actually renders the tilemap }
/// <summary> /// Checks to see if this FlxObject were located at the given position /// </summary> /// <param name="X">X position you want to check</param> /// <param name="Y">Y position you want to check</param> /// <param name="ObjectOrGroup">The object or group being tested</param> /// <param name="InScreenSpace">Whether to take scroll factors into account.</param> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns></returns> public virtual bool overlapsAt(float X, float Y, FlxBasic ObjectOrGroup, bool InScreenSpace = false, FlxCamera Camera = null) { if (ObjectOrGroup is FlxGroup) { bool results = false; int i = 0;List<FlxBasic> members = new List<FlxBasic>(); members = (ObjectOrGroup as FlxGroup).members; uint length = (uint)members.Count; while (i < length) { if (overlapsAt(X, Y, members[i++], InScreenSpace, Camera)) results = true; } return results; } if (ObjectOrGroup is FlxTilemap) { FlxTilemap tilemap = ObjectOrGroup as FlxTilemap; return tilemap.overlapsAt(tilemap.x - (X - x), tilemap.y - (Y - y), this, InScreenSpace, Camera); } FlxObject Object = ObjectOrGroup as FlxObject; if(!InScreenSpace) { return (Object.x + Object.width > X) && (Object.x < X + width) && (Object.y + Object.height > Y) && (Object.y < Y + height); } if (Camera == null) Camera = FlxG.camera; FlxPoint objectScreenPos = Object.getScreenXY(null, Camera); _point.x = X - Camera.scroll.x * scrollFactor.x; _point.y = Y - Camera.scroll.y * scrollFactor.y; _point.x += (_point.x > 0) ? 0.0000001f : -0.0000001f; _point.y += (_point.y > 0) ? 0.0000001f : -0.0000001f; return (objectScreenPos.x + Object.width > _point.x) && (objectScreenPos.x < _point.x + width) && (objectScreenPos.y + Object.height > _point.y) && (objectScreenPos.y < _point.y + height); }
public override bool onScreen(FlxCamera Camera = null) { if (Camera == null) Camera = FlxG.camera; getScreenXY(_point, Camera); _point.x = _point.x - offset.x; _point.y = _point.y - offset.y; float halfWidth = frameWidth / 2; float halfHeight = frameHeight / 2; float absScaleX = (scale.x > 0) ? scale.x : -scale.x; float absScaleY = (scale.y > 0) ? scale.y : -scale.y; float radius = (float)Math.Sqrt(halfWidth * halfWidth + halfHeight * halfHeight) * ((absScaleX >= absScaleY) ? absScaleX : absScaleY); _point.x += halfWidth; _point.y += halfHeight; return ((_point.x + radius > 0) && (_point.x - radius < Camera.width) && (_point.y + radius > 0) && (_point.y - radius < Camera.height)); }
/// <summary> /// Not yet implemented /// </summary> /// <param name="Camera">Which Camera - currently only one exists</param> public override void drawDebug(FlxCamera Camera=null) { if(Camera == null) Camera = FlxG.camera; //get bounding box coordinates float boundingBoxX = x - (int)(Camera.scroll.x*scrollFactor.x); //copied from getScreenXY() float boundingBoxY = y - (int)(Camera.scroll.y*scrollFactor.y); boundingBoxX = (int)(boundingBoxX + ((boundingBoxX > 0)?0.0000001f:-0.0000001f)); boundingBoxY = (int)(boundingBoxY + ((boundingBoxY > 0)?0.0000001f:-0.0000001f)); int boundingBoxWidth = (int)((width != (int)(width)) ? width : width - 1f); int boundingBoxHeight = (int)((height != (int)(height)) ?height : height - 1f); ////fill static graphics object with square shape //var gfx:Graphics = FlxG.flashGfx; //gfx.clear(); //gfx.moveTo(boundingBoxX,boundingBoxY); Color boundingBoxColor; if(Convert.ToBoolean(allowCollisions)) { if(allowCollisions != ANY) boundingBoxColor = FlxColor.PINK; if(immovable) boundingBoxColor = FlxColor.GREEN; else boundingBoxColor = FlxColor.RED; } else boundingBoxColor = FlxColor.BLUE; //gfx.lineStyle(1,boundingBoxColor,0.5); //gfx.lineTo(boundingBoxX+boundingBoxWidth,boundingBoxY); //gfx.lineTo(boundingBoxX+boundingBoxWidth,boundingBoxY+boundingBoxHeight); //gfx.lineTo(boundingBoxX,boundingBoxY+boundingBoxHeight); //gfx.lineTo(boundingBoxX,boundingBoxY); ////draw graphics shape to camera buffer //Camera.buffer.draw(FlxG.flashGfxSprite); }
/// <summary> /// Check to see if this object is currently on the screen /// </summary> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns>bool</returns> public virtual bool onScreen(FlxCamera Camera=null) { if(Camera == null) Camera = FlxG.camera; getScreenXY(_point,Camera); return (_point.x + width > 0) && (_point.x < Camera.width) && (_point.y + height > 0) && (_point.y < Camera.height); }
/// <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> /// Checks to see if some FlxObject overlaps this FlxObject or FlxGroup. /// If the group has a LOT of things in it, it might be faster to use <code>FlxG.ovelaps()</code> /// </summary> /// <param name="ObjectOrGroup">The object or group being tested</param> /// <param name="InScreenSpace">Whether to take scroll factors into account.</param> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns></returns> public virtual bool overlaps(FlxBasic ObjectOrGroup, bool InScreenSpace = false, FlxCamera Camera = null) { if (ObjectOrGroup is FlxGroup) { bool results = false; int i = 0; List <FlxBasic> members = new List <FlxBasic>(); members = (ObjectOrGroup as FlxGroup).members; //uint l = (uint)(ObjectOrGroup as FlxGroup).length; uint length = (uint)members.Count; while (i < length) { if (overlaps(members[i++], InScreenSpace, Camera)) { results = true; } } return(results); } if (ObjectOrGroup is FlxTilemap) { //Since tilemap's have to be the caller, not the target, to do proper tile-based collisions, // we redirect the call to the tilemap overlap here. return((ObjectOrGroup as FlxTilemap).overlaps(this, InScreenSpace, Camera)); } FlxObject Object = ObjectOrGroup as FlxObject; if (!InScreenSpace) { return((Object.x + Object.width > x) && (Object.x < x + width) && (Object.y + Object.height > y) && (Object.y < y + height)); } if (Camera == null) { Camera = FlxG.camera; } FlxPoint objectScreenPos = Object.getScreenXY(null, Camera); getScreenXY(_point, Camera); return((objectScreenPos.x + Object.width > _point.x) && (objectScreenPos.x < _point.x + width) && (objectScreenPos.y + Object.height > _point.y) && (objectScreenPos.y < _point.y + height)); }
// getData // setDirty // findPath // simplifyPath // raySimplifyPath // computePathDistance // walkPath override public Boolean overlaps(FlxBasic ObjectOrGroup, Boolean InScreenSpace = false, FlxCamera Camera = null) { if (ObjectOrGroup is FlxGroup) { Boolean results = false; FlxBasic basic; int i = 0; List <FlxBasic> members = new List <FlxBasic>(); members = (ObjectOrGroup as FlxGroup).members; while (i < members.Count) { basic = members[i++] as FlxBasic; if (basic is FlxObject) { if (overlapsWithCallback(basic as FlxObject)) { results = true; } } else { if (overlaps(basic, InScreenSpace, Camera)) { results = true; } } } return(results); } else if (ObjectOrGroup is FlxObject) { return(overlapsWithCallback(ObjectOrGroup as FlxObject)); } return(false); }
/// <summary> /// Checks to see if this FlxObject were located at the given position /// </summary> /// <param name="X">X position you want to check</param> /// <param name="Y">Y position you want to check</param> /// <param name="ObjectOrGroup">The object or group being tested</param> /// <param name="InScreenSpace">Whether to take scroll factors into account.</param> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns></returns> public virtual bool overlapsAt(float X, float Y, FlxBasic ObjectOrGroup, bool InScreenSpace = false, FlxCamera Camera = null) { if (ObjectOrGroup is FlxGroup) { bool results = false; int i = 0; List <FlxBasic> members = new List <FlxBasic>(); members = (ObjectOrGroup as FlxGroup).members; uint length = (uint)members.Count; while (i < length) { if (overlapsAt(X, Y, members[i++], InScreenSpace, Camera)) { results = true; } } return(results); } if (ObjectOrGroup is FlxTilemap) { FlxTilemap tilemap = ObjectOrGroup as FlxTilemap; return(tilemap.overlapsAt(tilemap.x - (X - x), tilemap.y - (Y - y), this, InScreenSpace, Camera)); } FlxObject Object = ObjectOrGroup as FlxObject; if (!InScreenSpace) { return((Object.x + Object.width > X) && (Object.x < X + width) && (Object.y + Object.height > Y) && (Object.y < Y + height)); } if (Camera == null) { Camera = FlxG.camera; } FlxPoint objectScreenPos = Object.getScreenXY(null, Camera); _point.x = X - Camera.scroll.x * scrollFactor.x; _point.y = Y - Camera.scroll.y * scrollFactor.y; _point.x += (_point.x > 0) ? 0.0000001f : -0.0000001f; _point.y += (_point.y > 0) ? 0.0000001f : -0.0000001f; return((objectScreenPos.x + Object.width > _point.x) && (objectScreenPos.x < _point.x + width) && (objectScreenPos.y + Object.height > _point.y) && (objectScreenPos.y < _point.y + height)); }
/// <summary> /// Check to see if a point in 2D world space overlaps this FlxObject /// </summary> /// <param name="Point">The point in world space you want to check</param> /// <param name="InScreenSpace">Whether to take scroll factors into account.</param> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns></returns> public virtual bool overlapsPoint(FlxPoint Point, bool InScreenSpace = false, FlxCamera Camera = null) { if (!InScreenSpace) { return((Point.x > x) && (Point.x < x + width) && (Point.y > y) && (Point.y < y + height)); } if (Camera == null) { Camera = FlxG.camera; } float X = Point.x - Camera.scroll.x; float Y = Point.y - Camera.scroll.y; getScreenXY(_point, Camera); return((X > _point.x) && (X < _point.x + width) && (Y > _point.y) && (Y < _point.y + height)); }
// overlapsPoint override public Boolean overlapsPoint(FlxPoint Point, Boolean InScreenSpace = false, FlxCamera Camera = null) { if (!InScreenSpace) { return((_tileObjects[_data[(int)(((Point.y - y) / _tileHeight) * widthInTiles + (Point.x - x) / _tileWidth)]] as FlxTile).allowCollisions > 0); } if (Camera == null) { Camera = FlxG.camera; } Point.x = Point.x - Camera.scroll.x; Point.y = Point.y - Camera.scroll.y; getScreenXY(_point, Camera); return((_tileObjects[_data[(int)(((Point.y - _point.y) / _tileHeight) * widthInTiles + (Point.x - _point.x) / _tileWidth)]] as FlxTile).allowCollisions > 0); }
public void follow(FlxCamera Camera = null, int Border = 0, Boolean UpdateWorld = false) { if (Camera == null) Camera = FlxG.camera; Camera.setBounds(x + Border * tileSize, y + Border * tileSize, width - Border * tileSize * 2, height - Border * tileSize * 2, UpdateWorld); }
public static FlxCamera addCamera(FlxCamera NewCamera) { FlxG.camera = NewCamera; FlxG.cameras.Add(NewCamera); Viewport v = new Viewport((int)NewCamera.x, (int)NewCamera.y, (int)NewCamera.width, (int)NewCamera.height); //FlxG.log("camera is at x: " + NewCamera.x + " y: " + NewCamera.y + " width: " + NewCamera.width + " height " + NewCamera.height); //FlxG.log("camera count: " + FlxG.cameras.Count); FlxG.viewports.Add(v); return NewCamera; }
// getData // setDirty // findPath // simplifyPath // raySimplifyPath // computePathDistance // walkPath public override Boolean overlaps(FlxBasic ObjectOrGroup, Boolean InScreenSpace = false, FlxCamera Camera = null) { if (ObjectOrGroup is FlxGroup) { Boolean results = false; FlxBasic basic; int i = 0; List<FlxBasic> members = new List<FlxBasic>(); members = (ObjectOrGroup as FlxGroup).members; while (i < members.Count) { basic = members[i++] as FlxBasic; if (basic is FlxObject) { if (overlapsWithCallback(basic as FlxObject)) results = true; } else { if (overlaps(basic, InScreenSpace, Camera)) results = true; } } return results; } else if (ObjectOrGroup is FlxObject) { return overlapsWithCallback(ObjectOrGroup as FlxObject); } return false; }
/// <summary> /// Debugging, not yet implemented /// </summary> /// <param name="camera"></param> public virtual void drawDebug(FlxCamera camera = null) { }
// overlapsPoint public override Boolean overlapsPoint(FlxPoint Point, Boolean InScreenSpace = false, FlxCamera Camera = null) { if (!InScreenSpace) return (_tileObjects[_data[(int)(((Point.y - y) / _tileHeight) * widthInTiles + (Point.x - x) / _tileWidth)]] as FlxTile).allowCollisions > 0; if (Camera == null) Camera = FlxG.camera; Point.x = Point.x - Camera.scroll.x; Point.y = Point.y - Camera.scroll.y; getScreenXY(_point, Camera); return (_tileObjects[_data[(int)(((Point.y - _point.y) / _tileHeight) * widthInTiles + (Point.x - _point.x) / _tileWidth)]] as FlxTile).allowCollisions > 0; }
/// <summary> /// Call this to figure out the on-screen position of the object /// </summary> /// <param name="Point">Take a FlxPoint object and assign the post-scrolled X and Y values of this object to it</param> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns></returns> public FlxPoint getScreenXY(FlxPoint Point=null, FlxCamera Camera=null) { if(Point == null) Point = new FlxPoint(); if(Camera == null) Camera = FlxG.camera; Point.x = x - (Camera.scroll.x*scrollFactor.x); Point.y = y - (Camera.scroll.y*scrollFactor.y); Point.x += (Point.x > 0)?0.0000001f:-0.0000001f; Point.y += (Point.y > 0)?0.0000001f:-0.0000001f; return Point; }
/// <summary> /// Checks to see if some FlxObject overlaps this FlxObject or FlxGroup. /// If the group has a LOT of things in it, it might be faster to use <code>FlxG.ovelaps()</code> /// </summary> /// <param name="ObjectOrGroup">The object or group being tested</param> /// <param name="InScreenSpace">Whether to take scroll factors into account.</param> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns></returns> public virtual bool overlaps(FlxBasic ObjectOrGroup, bool InScreenSpace=false, FlxCamera Camera=null) { if(ObjectOrGroup is FlxGroup) { bool results = false; int i = 0; List<FlxBasic> members = new List<FlxBasic>(); members = (ObjectOrGroup as FlxGroup).members; //uint l = (uint)(ObjectOrGroup as FlxGroup).length; uint length = (uint)members.Count; while(i < length) { if(overlaps(members[i++],InScreenSpace,Camera)) results = true; } return results; } if (ObjectOrGroup is FlxTilemap) { //Since tilemap's have to be the caller, not the target, to do proper tile-based collisions, // we redirect the call to the tilemap overlap here. return (ObjectOrGroup as FlxTilemap).overlaps(this, InScreenSpace, Camera); } FlxObject Object = ObjectOrGroup as FlxObject; if(!InScreenSpace) { return (Object.x + Object.width > x) && (Object.x < x + width) && (Object.y + Object.height > y) && (Object.y < y + height); } if(Camera == null) Camera = FlxG.camera; FlxPoint objectScreenPos = Object.getScreenXY(null, Camera); getScreenXY(_point,Camera); return (objectScreenPos.x + Object.width > _point.x) && (objectScreenPos.x < _point.x + width) && (objectScreenPos.y + Object.height > _point.y) && (objectScreenPos.y < _point.y + height); }
/// <summary> /// Debugging, not yet implemented /// </summary> /// <param name="camera"></param> public virtual void drawDebug(FlxCamera camera=null) { }
/// <summary> /// Check to see if a point in 2D world space overlaps this FlxObject /// </summary> /// <param name="Point">The point in world space you want to check</param> /// <param name="InScreenSpace">Whether to take scroll factors into account.</param> /// <param name="Camera">Which Camera - currently only one exists</param> /// <returns></returns> public virtual bool overlapsPoint(FlxPoint Point, bool InScreenSpace = false, FlxCamera Camera = null) { if (!InScreenSpace) return (Point.x > x) && (Point.x < x + width) && (Point.y > y) && (Point.y < y + height); if (Camera == null) Camera = FlxG.camera; float X = Point.x - Camera.scroll.x; float Y = Point.y - Camera.scroll.y; getScreenXY(_point, Camera); return (X > _point.x) && (X < _point.x + width) && (Y > _point.y) && (Y < _point.y + height); }
// overlapsPoint override public Boolean overlapsPoint(FlxPoint point, Boolean inScreenSpace = false, FlxCamera camera = null) { if (!inScreenSpace) { return((_tileObjects[_data[(int)(((point.Y - Y) / _tileHeight) * widthInTiles + (point.X - X) / _tileWidth)]] as FlxTile).AllowCollisions > 0); } if (camera == null) { camera = FlxG.camera; } point.X = point.X - camera.Scroll.X; point.Y = point.Y - camera.Scroll.Y; getScreenXY(_tagPoint, camera); return((_tileObjects[_data[(int)(((point.Y - _tagPoint.Y) / _tileHeight) * widthInTiles + (point.X - _tagPoint.X) / _tileWidth)]] as FlxTile).AllowCollisions > 0); }