C# Class Nez.Tiled.TiledMapMover

WIP The TiledMapMover is a helper for moving objects around in a gravity-based Tiled map. It requires that the Entity it is on has a BoxCollider. The BoxCollider will be used in conjuntion with colliderHorizontal/VerticalInset for all collision detection. If you plan to use slopes/one way platforms with the TiledMapMover some extra properties need to be added to your tiles in Tiled. They are listed below: - nez:isOneWayPlatform (bool): one way platforms will ignore all collisions except from above - nez:isSlope (bool): signifies if the tile is a slope. Requires the next two properties if it is - nez:slopeTopLeft (int): distance in pixels from the tiles top to the slope on the left side. For example, a 45 top-left to bottom-right tile |\ would have a slopeTopLeft of 0 and slopeTopRight of 15 - nez:slopeTopRist (int): distance in pixels from the tiles top to the slope on the right side
Inheritance: Component
ファイルを表示 Open project: prime31/Nez

Public Properties

Property Type Description
colliderHorizontalInset int
colliderVerticalInset int
collisionLayer Nez.Tiled.TiledTileLayer
tiledMap TiledMap

Public Methods

Method Description
TiledMapMover ( Nez.Tiled.TiledTileLayer collisionLayer ) : System
move ( Vector2 motion, BoxCollider boxCollider, CollisionState collisionState ) : void

moves the Entity taking into account the tiled map

populateCollidingTiles ( Rectangle bounds, System.Edge direction ) : void

gets a list of all the tiles intersecting bounds. The returned list is ordered for collision detection based on the direction passed in so they can be processed in order.

render ( Graphics graphics, Camera camera ) : void
testCollisions ( Vector2 &motion, Rectangle boxColliderBounds, CollisionState collisionState ) : void

Private Methods

Method Description
collisionRectForSide ( System.Edge side, int motion ) : Rectangle

gets a collision rect for the given side expanded to take into account motion

testMapCollision ( Rectangle collisionRect, System.Edge direction, CollisionState collisionState, int &collisionResponse ) : bool
testTileCollision ( TiledTile tile, System.Edge edgeToTest, int perpindicularPosition, int leadingPosition, bool shouldTestSlopes, int &collisionResponse ) : bool

Tests the tile for a collision. Returns via out the position in world space where the collision occured.

worldToTilePosition ( float worldPosition, Axis axis ) : int

returns the tile position clamped to the tiled map

Method Details

TiledMapMover() public method

public TiledMapMover ( Nez.Tiled.TiledTileLayer collisionLayer ) : System
collisionLayer Nez.Tiled.TiledTileLayer
return System

move() public method

moves the Entity taking into account the tiled map
public move ( Vector2 motion, BoxCollider boxCollider, CollisionState collisionState ) : void
motion Vector2 Motion.
boxCollider BoxCollider Box collider.
collisionState CollisionState
return void

populateCollidingTiles() public method

gets a list of all the tiles intersecting bounds. The returned list is ordered for collision detection based on the direction passed in so they can be processed in order.
public populateCollidingTiles ( Rectangle bounds, System.Edge direction ) : void
bounds Microsoft.Xna.Framework.Rectangle Bounds.
direction System.Edge Direction.
return void

render() public method

public render ( Graphics graphics, Camera camera ) : void
graphics Graphics
camera Camera
return void

testCollisions() public method

public testCollisions ( Vector2 &motion, Rectangle boxColliderBounds, CollisionState collisionState ) : void
motion Vector2
boxColliderBounds Microsoft.Xna.Framework.Rectangle
collisionState CollisionState
return void

Property Details

colliderHorizontalInset public_oe property

the inset on the horizontal plane that the BoxCollider will be shrunk by when moving vertically
public int colliderHorizontalInset
return int

colliderVerticalInset public_oe property

the inset on the vertical plane that the BoxCollider will be shrunk by when moving horizontally
public int colliderVerticalInset
return int

collisionLayer public_oe property

the TiledTileLayer used for collision checks
public TiledTileLayer,Nez.Tiled collisionLayer
return Nez.Tiled.TiledTileLayer

tiledMap public_oe property

the TiledMap that contains collisionLayer
public TiledMap tiledMap
return TiledMap