如何在phase.js中移动时旋转汽车
how to rotate the car while moving in phase.js
当我使用此代码时,我面临如下错误: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');
};
});
您正在将this.game.car与game.kar混合。除此之外,速度和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>
相关文章:
- 使用KineticJS变换(移动/缩放/旋转)形状
- 如何水平移动旋转的画布
- 如何使我的功能360度旋转并上下移动
- 猫头鹰旋转木马-自动高度移动问题
- 如何在Javascript中移动元素的旋转点
- 如何旋转rect,并且它仍然根据其旋转沿正确的方向移动
- 用户键入时旋转的内容可编辑移动
- 在 HTML5 画布中沿路径旋转移动对象
- 三.js一个物体可以同时旋转和移动吗?
- 如何锁定在类固醇中旋转的场景.js - AppGyver移动应用程序
- 想要使用 html5 的画布优化捕获的图像调整大小和旋转的代码,现在在移动设备上发出内存不足警告
- 如何在phase.js中移动时旋转汽车
- OWL旋转木马移动+/-5张幻灯片
- 我可以使用旋转功能绕时钟移动一条线吗
- Three.js-鼠标移动时沿(0,0,0)旋转对象
- 在HTML画布中移动旋转对象
- 使用setInterval移动旋转木马
- jquery-移动旋转器加载
- 移动旋转的SVG元素
- 如何在单击按钮时移动旋转木马项目