phuurup Posted May 11, 2015 Share Posted May 11, 2015 I'm having troubles with really understanding how to evoke collision detection; how to and where to put it. I've looked at the examples and the API and I think my non existent background in computer science/logic are hindering me right now. Is it possible to get (or to be pointed towards) some really easy to follow examples of how to go about collision detection, from as primitive of a start as possible e.g. this.load.image('ball', images/ball.png). thanks for any help or suggestions! Link to comment Share on other sites More sharing options...
ZoomBox Posted May 11, 2015 Share Posted May 11, 2015 It mainly depends of what physic system you are using. Link to comment Share on other sites More sharing options...
BattyMilk Posted May 11, 2015 Share Posted May 11, 2015 Here you go. Using arcade physics: http://phaser.io/examples/v2/arcade-physics/sprite-vs-sprite There are some great examples covering pretty much anything you could want to do in the Phaser examples. Link to comment Share on other sites More sharing options...
phuurup Posted May 11, 2015 Author Share Posted May 11, 2015 This is what I've got. I tried going over the Phaser examples :\ var game = new Phaser.Game(384, 640, Phaser.AUTO, 'gameDiv'); function preload() { game.load.image('ground', 'images/PNG/red_button00.png'); game.load.image('ball', 'images/PNG/green_circle.png'); }, var sprite; var sprite2; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#124184'; sprite = game.add.sprite(300, 500, 'ground');sprite.name = 'ground';game.physics.enable(sprite, Phaser.Physics.ARCADE);sprite.body.collideWorldBounds = true;sprite.body.checkCollision.up = true;sprite.body.checkCollision.down = true;sprite.body.immovable = true; sprite2 = game.add.sprite(350, 400, 'ball', 2);sprite2.name = 'ball';game.physics.enable(sprite2, Phaser.Physics.ARCADE);sprite2.body.collideWorldBounds = true;sprite2.body.bounce.setTo(1, 1); sprite2.body.velocity.y = -200;},function update() { game.physics.arcade.collide(sprite, sprite2); game.physics.arcade.enable(this.ball); }, Am I even close? lol Link to comment Share on other sites More sharing options...
phuurup Posted May 11, 2015 Author Share Posted May 11, 2015 Here you go. Using arcade physics: http://phaser.io/examples/v2/arcade-physics/sprite-vs-sprite There are some great examples covering pretty much anything you could want to do in the Phaser examples.Thanks, I'll look threw it! Link to comment Share on other sites More sharing options...
phuurup Posted May 11, 2015 Author Share Posted May 11, 2015 Even when I blindly copy and paste it doesn't seem to work. I'm using brackets and it's live preview option. Could that Just be the issue? :\ thanks again everyone. I know it might be something small, but I'm just learning this Code if anyone cares: <!DOCTYPE html><html><head> <meta charset="utf-8" /> <title>practice</title> <script type="text/javascript" src="lib/phaser.js"></script> <script type="text/javascript" src="main2.js"></script></head><body> <div id="gameDiv"></div> </body> </html>______________________________________________________________________________________________ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'gameDiv'); function preload() { game.load.image('ground', 'images/PNG/red_button00.png'); game.load.image('ball', 'images/PNG/green_circle.png'); }, var sprite; var sprite2; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#124184'; sprite = game.add.sprite(50, 200, 'ground'); sprite2 = game.add.sprite(700, 220, 'ball'); game.physics.enable( [ sprite, sprite2 ], Phaser.Physics.ARCADE); sprite.name = 'ground'; sprite.body.velocity.x = 100; sprite2.name = 'ball'; sprite2.body.velocity.x = -100; } function update() { // object1, object2, collideCallback, processCallback, callbackContext game.physics.arcade.collide(sprite, sprite2, collisionHandler, null, this); } function collisionHandler (obj1, obj2) { // The two sprites are colliding game.stage.backgroundColor = '#992d2d'; } function render() { game.debug.body(sprite); game.debug.body(sprite2); } Link to comment Share on other sites More sharing options...
phuurup Posted May 12, 2015 Author Share Posted May 12, 2015 After going through other peoples code, i've figured it out! Thank you to the two individuals who commented, and to the other 159 (at this point) individuals who just looked at this and said "I'll let the next guy answer this one #n00b". joke directed towards myself** drhayes and druphoria 2 Link to comment Share on other sites More sharing options...
Recommended Posts