Jump to content

Another Sprite vs Sprite Collision Detection Issue 1.1.4


gareththegeek
 Share

Recommended Posts

I have encountered a problem with collision detection if I set the velocity of a sprite so it will move towards another sprite when it is already touching that sprite.  This problem is encountered when the user holds a key to walk up to an obstacle, then attempts to walk through it.

 

Any suggestions?

 

Thanks,

G

<!DOCTYPE html><html lang="en"><head>    <meta charset="utf-8" />    <title>Collision Detection Problem</title>    <script src="phaser.min.js"></script></head><body>    <div id="content"></div>    <script type="text/ecmascript">        window.onload = function () {            var purple = null;            var green = null;            var game = new Phaser.Game(                640, 480,                Phaser.AUTO,                "content", {                    preload: function () {                        game.load.image("purple", "purple.png");                        game.load.image("green", "green.png");                    },                    create: function () {                        purple = game.add.sprite(100, 120, "purple");                        green = game.add.sprite(300, 100, "green");                        purple.body.velocity.x = 200;                        green.body.immovable = true;                    },                    update: function () {                                                // If I set the velocity during update it is possible                        // for purple to pass through green                        // It doesn't matter if I set the velocity before or after                        // the collide call....                        //purple.body.velocity.x = 200;                        game.physics.collide(purple, green);                        purple.body.velocity.x = 200;                    }                });        };    </script></body></html>
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...