DbD Posted May 25, 2015 Share Posted May 25, 2015 Hi, i'm trying to create an object to the right of another object. I want it to check if there is an object that exists already, and if not then create the same object to the right 48 px. I tried this: grass = game.add.sprite(0, 0, 'grass'); if (!grass.body.touching.right) { game.add.sprite(grass+48, 0, 'grass'); }but no luck. any solutions? p.s. i'm fairly new to the Phaser framework, and i'm still learning how to do things like collision checking in phaser. Thanks! Link to comment Share on other sites More sharing options...
Account Deleted Posted May 26, 2015 Share Posted May 26, 2015 This is a function I am using from one of the phaser tutorials, it checks for overlap instead of collision though. checkOverlap: function(spriteA, spriteB) {var boundsA = spriteA.getBounds();var boundsB = spriteB.getBounds();return Phaser.Rectangle.intersects(boundsA, boundsB It returns a matrix instead of just an X or Y value though, so you'll need to place the grass keeping this in mind. Then the return just returns a true or false for your conditional. Hope that helps!} Link to comment Share on other sites More sharing options...
DbD Posted May 27, 2015 Author Share Posted May 27, 2015 Thanks man i'll see what i can do with this! Link to comment Share on other sites More sharing options...
Recommended Posts