Tiles = new FlxTilemap();
Tiles.widthInTiles = 150;
Tiles.heightInTiles = 70;
Tiles.loadMap(makeTileMap(BG_BWMap), "assets/images/tiles.png", 10, 10);
Tiles.setTileProperties(0, FlxObject.ANY);
Tiles.setTileProperties(1, FlxObject.ANY);
Tiles.setTileProperties(2, FlxObject.NONE);
private function makeTileMap(bwm:BitmapData):Array<Int> {
var map:Array<Int> = new Array<Int>();
var tile:Int = 0;
for (i in 0...Std.int(bwm.height / 10)) {
for (j in 0...Std.int(bwm.width / 10)) {
switch(bwm.getPixel(j * 10, i * 10)) {
case 16777215: tile = 2;
default: tile = 0;
}
map.push(tile);
}
}
return map;
}
if (FlxG.mouse.justReleased) {
trace("Pixel: "+BG_BWMap.getPixel(Std.int(FlxG.mouse.x), Std.int(FlxG.mouse.y)));
trace(Tiles.getTile(Std.int(FlxG.mouse.x / 10), Std.int(FlxG.mouse.y / 10)));
}
. Any ideas what's going on here?
Edit: It seems like it's just to the left and to the right side. Very strange...
//Increase world bounds to allow collisions between player and other objects FlxG.worldBounds.width = tileSize * Tiles.widthInTiles; FlxG.worldBounds.height = tileSize * Tiles.heightInTiles;
package;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.util.FlxMath;
import flixel.tile.FlxTilemap;
class MenuState extends FlxState
{
public var Tiles:FlxTilemap;
override public function create():Void
{
super.create();
Tiles = new FlxTilemap();
var map:String = "1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2,2,2,2,2,2,2,2,2,2";
Tiles.loadMap(map, "assets/images/tiles.png", 10);
add(Tiles);
}
override public function destroy():Void
{
super.destroy();
}
override public function update():Void
{
if (FlxG.mouse.justPressed) {
trace(Tiles.getTile(Std.int(FlxG.mouse.x / 10), Std.int(FlxG.mouse.y / 10))+" at "+Std.int(FlxG.mouse.x)+" "+Std.int(FlxG.mouse.y));
}
super.update();
}
}