FlxG.collide not working!!!



  • Hey everyone, I'm doing the HaxeFlixel tutorial (the dungeon crawler one) and I got stuck at the map collision part.
    The problem: the collision is not working . Now maybe (and probably) I made a mistake but I can't pinpoint it so I figured some fresh eyes might help.

    This is the code inside the PlayState class:

    //Player variable:
    private var player:Player;
    
    //Create tilemap variables:
    private var map:FlxOgmoLoader;
    private var mapWalls:FlxTilemap;
    
    override public function create():Void {
    	super.create();
    	
    	//Create map:
    	map = new FlxOgmoLoader(AssetPaths.room_001__oel);
    	mapWalls = map.loadTilemap(AssetPaths.tiles__png, 16, 16, "walls");
    	mapWalls.follow();
    	mapWalls.setTileProperties(1, FlxObject.NONE);
    	mapWalls.setTileProperties(2, FlxObject.ANY);
    	add(mapWalls);
    	
    	//Create player:
    	player = new Player();
    	map.loadEntities(placeEntities, "entities");
    	add(player);
    }
    
    //Create player at tilemap entity position
    private function placeEntities(entityName:String, entityData:Xml):Void {
    	var x:Int = Std.parseInt(entityData.get("x"));
    	var y:Int = Std.parseInt(entityData.get("y"));
    	
    	if (entityName == "player") { //If the entity is of "player type"
    		player.x = x;
    		player.y = y;
    	}
    	
    }
    
    override public function update(elapsed:Float):Void {
    	super.update(elapsed);		
    	FlxG.collide(mapWalls, player);
    	//Disable mouse pointer:
    	FlxG.mouse.hideCursor();
    	
    }
    

    Thank you for helping ヽ(⩾‿⩽)ノ


  • administrators

    I can't spot anything obviously wrong here. Have you tried comparing with the completed game (available in flixel-demos)?

    Btw, FlxG.mouse.hideCursor() is private and should not be accesible (it seems to be due to a bug though!). It will likely not be available anymore in the next release, the correct usage is FlxG.mouse.visible = false.



  • @Gama11 Thanks but I didn't find any difference at this point. I'll just follow along the tutorial. Maybe I'll find something after its complete.



  • Try checking the tile indices. Maybe you meant 0 as FlxObject.NONE and 1 as FlxObject.ANY?
    Try changing FlxG.worldBounds to a bigger rect


  • administrators

    @starry-abyss 1 and 2 should be correct, it's exactly what the tutorial uses. Also, mapWalls.follow(); already sets the worldBounds to the size of the tilemap.


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.