javascript - collision taking after image also? -
i'm creating car parking game collision detection.
my problem checking collision after image has updated.
my phaser code:
var app = angular.module('myapp',[]); app.controller('mycontrol',function($scope){ var game = new phaser.game(1100, 590, phaser.auto, 'cargame'); var mainstate = { preload:function(){ game.load.image('wood','images/wood1.png'); game.load.image('car', 'images/maincar.png'); }, create:function(){ game.physics.startsystem(phaser.physics.arcade); this.car =this.game.add.sprite(game.world.centerx,game.world.centery,'car'); //this.car.body.collide = true; this.car.anchor.setto(0.5,0.5); //this.wood1.anchor.setto(0.5,0.5); game.physics.arcade.enable(this.car); this.car.body.allowrotation = true; platforms = game.add.group(); platforms.enablebody = true; var ground = platforms.create(200,300, 'wood'); ground.body.immovable = true; }, update:function(){ if(game.input.keyboard.isdown(phaser.keyboard.left)){ this.car.body.angularvelocity = -200; } else if(game.input.keyboard.isdown(phaser.keyboard.right)){ this.car.body.angularvelocity = 200; } else if(game.input.keyboard.isdown(phaser.keyboard.up)){ this.car.body.velocity.copyfrom(game.physics.arcade.velocityfromangle(this.car.angle, 150)); } else if(game.input.keyboard.isdown(phaser.keyboard.down)){ this.car.body.velocity.copyfrom(game.physics.arcade.velocityfromangle(this.car.angle, -150)); } else{ this.car.body.angularvelocity =0; this.car.body.velocity.x =0; this.car.body.velocity.y = 0; } game.physics.arcade.collide(this.car, platforms); }, }; $scope.car1 = function(){ game.state.add('main', mainstate); game.state.start('main'); }; });
and html
<html> <head> <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <script src="controller2.js"></script> <script type="text/javascript" src="phaser.min.js"></script> </head> <body ng-app="myapp" ng-controller="mycontrol"> <div id="cargame" ng-click="car1()"> </div> </body> </html>
from phaser docs (physics.arcade, collide method):
an optional processcallback can provided. if given function called when 2 sprites found colliding. called before separation takes place, giving chance perform additional checks. if function returns true collision , separation carried out
so, can this:
game.physics.arcade.collide(this.car, platforms, mycallback);
and then, define 'mycallback' funtion, can whatever want objects in collision.
Comments
Post a Comment