Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlxTilemap one-way collision bug #1546

Closed
Gama11 opened this issue Jun 29, 2015 · 8 comments
Closed

FlxTilemap one-way collision bug #1546

Gama11 opened this issue Jun 29, 2015 · 8 comments
Milestone

Comments

@Gama11
Copy link
Member

Gama11 commented Jun 29, 2015

Originally reported here.

Code to reproduce:

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.graphics.FlxGraphic;
import flixel.tile.FlxTilemap;
import flixel.util.FlxColor;

class PlayState extends FlxState
{
    public var sprite:FlxSprite;
    public var tiles:FlxTilemap;

    override public function create():Void
    {
        super.create();

        sprite = new FlxSprite(0, 8);
        sprite.makeGraphic(8, 8);
        add(sprite);

        tiles = new FlxTilemap();
        tiles.loadMapFrom2DArray([[1],[0]], FlxGraphic.fromClass(GraphicAuto));
        tiles.x += 20;

        add(sprite);
        add(tiles);
    }

    override public function update(_):Void
    {
        super.update(_);
        readInput();
        FlxG.collide(sprite, tiles);
    }   

    public function readInput()
    {
        var speed = 50;
        sprite.velocity.y =
            if (FlxG.keys.anyPressed([UP, W])) -speed;
            else if (FlxG.keys.anyPressed([DOWN, S])) speed;
            else 0;

        sprite.velocity.x =
            if (FlxG.keys.anyPressed([LEFT, A])) -speed;
            else if (FlxG.keys.anyPressed([RIGHT, D])) speed;
            else 0;
    }
}

Moving from left to right works fine - right to left doesn't though, the sprite gets stuck at the edeg of the tilemap. Doesn't seem to be a target-specific issue.

Supposedly, this doesn't happen in AS3 Flixel (haven't tested myself), so comparing some of the collision code might be helpful.
Originally reported here.

Happens in both dev and 3.3.8, so not a recent regression.

@Gama11 Gama11 added the Bug label Jun 29, 2015
@Gama11 Gama11 added this to the 4.0.0 milestone Jun 29, 2015
@SeiferTim
Copy link
Member

If you add another column, this stops happening.
I'm not sure what the issue is, yet.

@Gama11
Copy link
Member Author

Gama11 commented Jun 29, 2015

Depends on what the column looks like... The original csv from the thread looked like this:

1,1,1,1,1,1,1,1,1,1
1,0,4,0,0,0,0,4,0,1
1,1,1,0,0,0,0,1,1,1
0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0
1,1,1,0,0,0,0,1,1,1
1,0,4,0,0,0,0,4,0,1
1,1,1,0,0,0,0,1,1,1
1,0,4,0,0,0,0,4,0,1
1,1,1,0,0,0,0,1,1,1
2,0,0,0,0,0,0,0,0,3
2,0,0,0,0,0,0,0,0,3
2,0,0,0,0,0,0,0,0,3
1,1,1,0,0,0,0,1,1,1
1,0,4,0,0,0,0,4,0,1
1,1,1,1,1,1,1,1,1,1

I just reduced it as much as possible.

@chiguire
Copy link

I assume this code compiles on Dev, it doesn't on 3.3.8. Tim, how did you add the other column? I'm using a CSV in a string "1,1\n0,0" and I'm still getting the collision.

@SeiferTim
Copy link
Member

tiles.loadMapFrom2DArray([[1, 0],[0, 0]], FlxGraphic.fromClass(GraphicAuto));

@chiguire
Copy link

In AS3 Flixel, in FlxTilemap.overlapsWithCallback selectionX and selectionY are respectively set to 0 if they're less than 0. I added this in Haxe and the collision was correct.

@SeiferTim
Copy link
Member

It looks like the issue with with FlxTilemap.overlapsWithCallback not bounding the selectionX and selectionY variables. I'll add the change to dev.

@chiguire
Copy link

It also seems to solve the problem in the original case :-) when debugging before, it seems that the collision function was looking in a negative column (-2), maybe it was accessing an invalid tile.

@chiguire
Copy link

Cheers, thanks for all the help.

Gama11 added a commit that referenced this issue Jun 29, 2015
Fix a one-way collision bug in FlxTilemap, closes #1546
Gama11 added a commit that referenced this issue Jun 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants