actionscript-3collisionflixel

FlxG.collide (with setTileProperties) colliding outside the tile space in flixel


so I have been using flixel I some recently, and I think I am getting a feel for it, but I have come across a issue.

I have a Map class, that uses the loadMap() function, which comes out great.

I then use setTileProperties() on my Water tile, that then calls a function, calls a Boolean on my player class (to say that he is in the water), which then slows him down. This still works great, except for one thing. When I pass the water tile above or to the right (about 10-16ish pixels, haven't gotten the exact number) outside the tile, it still slows the player. I am not sure if this is just the way that FlxG.collide() works, or if there is something I can do to fix it, or maybe if I should find another way to use the collision. All help is appreciated.

Here is the code, if you need it:

Map.as

   private function createMap():void {
            loadMap(new currentMap, currentTiles, 32, 32, 0, 0, 0);
            setTileProperties(4, FlxObject.NONE, PlayerInWater);                
        }
override public function update():void {
        super.update();
        FlxG.collide(Registry.player, this);

    }

    private function PlayerInWater(tile:FlxTile, player:Player):void {
        Registry.player.inWater = true;
        trace("player is in the water"); 

    }

Solution

  • So, I have figured out an answer to this, for all of you who want to know. I used the overlapsPoint() method to create this:

    private function createMap():void {
            //load Map
            loadMap(new currentMap, currentTiles, 32, 32, 0, 0, 0);
            //set water tiles
            setTileProperties(4, FlxObject.NONE);
            //put all of the water tiles in an array
            waterArray = getTileCoords(4);
        }
    
    override public function update():void {
            super.update();
            //collision with map
            FlxG.collide(Registry.player, this);
            //loops through each water tile
            for each(var waterTile:FlxPoint in waterArray) {
                //checks if the player is overlapping the water tile
                if (Registry.player.overlapsPoint(waterTile)) {
                    //if so, then the player is in water
                    Registry.player.inWater = true;
                }
            }
        }
    

    This method being so simple, it kind of makes me feel stupid for getting stuck on it, but if someone finds a more efficient method, please, go ahead and comment, or make a new answer. I always appreciate feedback.