当我使用这段代码时,我面临这样的错误:Uncaught TypeError: Cannot read property 'angle' of undefined.
var app = angular.module('myapp',[]);
app.controller('mycontrol',function($scope){
var game = new Phaser.Game(700, 590, Phaser.AUTO, 'cargame');
var mainState = {
preload:function(){
game.load.image('car', 'images/car90.png');
},
create:function(){
game.physics.startSystem(Phaser.Physics.ARCADE);
this.car =this.game.add.sprite(game.world.centerX,game.world.centerY,'car');
this.car.anchor.setTo(0.5,0.5);
game.physics.arcade.enable(this.car);
this.car.body.allowRotation = true;
},
update:function(){
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)){
this.game.car.angularVelocity = -200;
}
else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)){
this.game.car.body.angularVelocity = 200;
}
else if(game.input.keyboard.isDown(Phaser.Keyboard.UP)){
this.game.car.velocity.copyFrom(game.physics.arcade.velocityFromAngle(game.car.angle, 200));
}
else{
this.car.body.angularVelocity = 0;
this.car.body.velocity.x =0;
this.car.body.velocity.y = 0;
}
},
};
$scope.car1 = function(){
game.state.add('main', mainState);
game.state.start('main');
};
});发布于 2016-01-11 10:16:38
你把this.game.car和game.car混在一起。此外,速度和angularVelocity必须应用于精灵体。
试试这个:
var game = new Phaser.Game(700, 590, Phaser.AUTO, 'cargame');
var mainState = {
preload:function(){
game.load.image('car', 'notfonud');
},
create:function(){
game.physics.startSystem(Phaser.Physics.ARCADE);
this.car =this.game.add.sprite(game.world.centerX,game.world.centerY,'car');
this.car.anchor.setTo(0.5,0.5);
game.physics.arcade.enable(this.car);
this.car.body.allowRotation = 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, 200));
}
else{
this.car.body.angularVelocity = 0;
this.car.body.velocity.x =0;
this.car.body.velocity.y = 0;
}
},
};
game.state.add('main', mainState);
game.state.start('main');<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.4/phaser.min.js"></script>
<div id="cargame"></div>
https://stackoverflow.com/questions/34718217
复制相似问题