GithubHelp home page GithubHelp logo

Comments (13)

hexus avatar hexus commented on August 24, 2024 2

Okay, so this technically isn't a bug (but I think it is).

The callback is working as expected because the sprites are indeed overlapping a tile.

phaser-overlap-bug-1

The problem, as highlighted in the GIF, is that these tiles shouldn't collide and have an index of -1, but Phaser doesn't say anything about overlap() only checking tiles that collide. Whether this is correct is up for debate, but I feel like it isn't.

To work around this, you can add a process callback.

this.physics.arcade.overlap(this.emitter, this.ground, function (particle, tile) {
    particle.kill();
}, function (particle, tile) {
    return tile.collides;
}, this);

This will still check the overlap, but only for tiles that can collide. It should give the result you're after.

phaser-overlap-bug-2-2

Collision process callbacks in Phaser are a check that let you decide whether to actually continue with the overlap/collision based on the result of your own callback function. In this case, we simply check whether the current tile is meant to collide with anything.

Feel free to let me know if this resolves all of your issues. 😃

Also, technically, this means my plugin is incorrect, because it will bail out from overlapOnly collision checks if the tile doesn't collide, which is adverse to Phaser's above mentioned behaviour.

from phaser-arcade-slopes.

hexus avatar hexus commented on August 24, 2024 1

Interesting! Thanks for such a clear explanation.

If you have a way of setting up something like a codepen that I could use to diagnose this I'd be happy to look into it.

Something that jumps out at me immediately:

bullet.height = this.bulletHeight
bullet.width = this.bulletWidth

This is being set after enabling physics bodies for the particles of the emitter. Could it be that the body of each particle is larger than you expect? Perhaps you could find away to draw debug output for the bodies of currently alive particles, just to get a better visual of what's going on. Might be helpful to do the same for the tilemap at the same time.

Unfortunately the plugin itself doesn't yet have its own debug output for all the polygons and vectors involved in the collision handling, but that is on the roadmap for 0.2.0 (#4).

from phaser-arcade-slopes.

hexus avatar hexus commented on August 24, 2024 1

Very interesting! I will absolutely investigate this at some point, thank you for highlighting it so well.

The plugin is probably not handling the overlapOnly flag correctly. :)

from phaser-arcade-slopes.

iCodeForBananas avatar iCodeForBananas commented on August 24, 2024 1

LICEcap
http://www.cockos.com/licecap/

One of the most useful tools ever for showing people stuff!

from phaser-arcade-slopes.

hexus avatar hexus commented on August 24, 2024 1

Oh, and thanks for showing me LICEcap, it's fabulous! ✨

from phaser-arcade-slopes.

iCodeForBananas avatar iCodeForBananas commented on August 24, 2024 1

It totally worked! I didn't get a chance to really test it a lot but immediately I was able to shoot again! :)

from phaser-arcade-slopes.

iCodeForBananas avatar iCodeForBananas commented on August 24, 2024

bullets6

I was messing with the body width and height instead like you said. I think the main issue is that I'm unable to use overlap instead of collide with the bullets. I'll see if I can get a codepen together.

from phaser-arcade-slopes.

iCodeForBananas avatar iCodeForBananas commented on August 24, 2024

Some of the particles in the example have a similar issue.
Change the collision on https://github.com/hexus/phaser-arcade-slopes/blob/gh-pages/src/ArcadeSlopesDemo.js#L300 to the below:

            // Collide the particles against the collision layer
            this.physics.arcade.overlap(this.emitter, this.ground, function(particle, ground) {
                particle.kill()
            }, null, this);

This should allow for the particles to come out of the player and when they overlap the ground be killed.
Instead they get killed instantly inside of the player object.

bullets7

from phaser-arcade-slopes.

iCodeForBananas avatar iCodeForBananas commented on August 24, 2024

Ok so I don't really understand the consequences of my actions but I got it to kind of work now.

Go to this line:

Replace the if statement with the following:

        if (! overlapOnly && collideCallback) {
            collideCallback.call(callbackContext, sprite, tile);
        }

overlap test

from phaser-arcade-slopes.

hexus avatar hexus commented on August 24, 2024

Hmm, okay. That's interesting, because that branch passes handling to Arcade Physics to handle normally, if the tile doesn't have a tile.slope property (i.e. it hasn't been converted by the plugin).

Except the callback should still be called in the case of an overlap. The code you've linked to is meant to mirror this, to an extent:

https://github.com/photonstorm/phaser/blob/master/src/physics/arcade/TilemapCollision.js#L63

Except I decided to break it down a little more to avoid code repetition. But perhaps the return statements I've used are causing issues down the line, or separateTile() is doing something that I'm not catering for properly.

Also, love that the Lenny face is in the example GIF, haha. What do you use for screen capture?

from phaser-arcade-slopes.

hexus avatar hexus commented on August 24, 2024

I totally managed to reproduce the issue above, but even after completely disabling the plugin. This might be an issue with Phaser itself, and not the plugin.

from phaser-arcade-slopes.

iCodeForBananas avatar iCodeForBananas commented on August 24, 2024

Just a heads up for closure on this, it's works awesome!
I updated the sprite bodies and added the processCallback to other things needing overlap and it all works! :)

from phaser-arcade-slopes.

hexus avatar hexus commented on August 24, 2024

Awesome, thanks for letting me know.

I did close this pre-emptively but I had a gut feeling that this was the cause of all your issues. I thought maybe something else would be causing the sliding/missing tiles, but assumed these were different attempts to get it working and ultimately you just wanted the correct overlap responses. :)

Glad it works so well! I look forward to seeing your project progress.

from phaser-arcade-slopes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.