Collision between a FlxTilemap
and at least one FlxObject
is really simple. Just call FlxG.collide()
, passing the tilemap and the object(s), and flixel takes care of the rest.
FlxG.collide(map, sprite);
Collision between a FlxTilemap
and at least one FlxObject
is really simple. Just call FlxG.collide()
, passing the tilemap and the object(s), and flixel takes care of the rest.
FlxG.collide(map, sprite);
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.tile.FlxTilemap;
class PlayState extends FlxState
{
var map:FlxTilemap;
var sprite:FlxSprite;
override function create()
{
super.create();
map = new FlxTilemap();
map.loadMapFromCSV("assets/room-map.csv", "assets/tiles.png", 16, 16);
add(map);
sprite = new FlxSprite("assets/sprite.png");
sprite.screenCenter();
sprite.velocity.set(200, 200);
sprite.elasticity = 1;
add(sprite);
}
override function update(elapsed:Float)
{
super.update(elapsed);
FlxG.collide(map, sprite);
}
}