我想制作一个非常基本的机器人,围绕它旋转一个手臂轴,如下图jsfiddle coffeescript version ,我已经尝试过P2关节,群体,孩子,并没有成功,任何人都可以帮助有了这个 ? :)
'use strict';
var game, mainState;
game = new Phaser.Game(320, 480, Phaser.AUTO, 'space');
mainState = {
preload: function() {
game.load.image('body', 'data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAA1CAIAAAAyDncDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDE0IDc5LjE1MTQ4MSwgMjAxMy8wMy8xMy0xMjowOToxNSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIChNYWNpbnRvc2gpIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkRGQjhBNEU1REE1QTExRTU5N0MzOEQxNTFGN0Y0QzlDIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkRGQjhBNEU2REE1QTExRTU5N0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1gAYhrAAxDWABiGsADENYAGIaxNDRP66h+n6qgKJxd54ADQAAAAAAAAAAAAAAAAAE0NE/vqD6/uqAonF3ngANAAAAAAAAAAAAAAAAAATQ0T++oPr+6oCicXeeAA0AAAAAAAAAAAAAAAAABNDRP76g+v7qgKJxd54ADQAAAAAAAAAAAAAAAAAE0NE/vqD6/uqAonF3ngANAAAAAAAAAAAAAAAAAATQ0T++oPr+6UoPctd5bgpQbmm1KUDNNqUoGabUpQM02pSgZptSlAzTalKBmm1KUDNNqUoGabUpQM02oA5Xqf31//2Q==')
},
create: function() {
var groundCollisionGroup, robotCollisionGroup;
game.physics.startSystem(Phaser.Physics.P2JS);
this.chest = game.add.sprite(29, 53, 'body');
this.arms = game.add.sprite(8, 53, 'arms');
this.ground = game.add.sprite(320, 70, 'ground');
game.physics.p2.enable([this.chest, this.arms, this.ground]);
robotCollisionGroup = game.physics.p2.createCollisionGroup();
groundCollisionGroup = game.physics.p2.createCollisionGroup();
this.ground.body["static"] = true;
this.ground.body.setCollisionGroup(groundCollisionGroup);
this.ground.body.collides(robotCollisionGroup);
this.chest.body.debug = true;
this.chest.body.setCollisionGroup(robotCollisionGroup);
this.chest.body.collides(groundCollisionGroup);
this.arms.body.debug = true;
this.arms.body.setCollisionGroup(robotCollisionGroup);
this.arms.body.collides(groundCollisionGroup);
this.ground.reset(game.world.centerX, game.world.height);
this.chest.reset(game.world.centerX, game.world.height - 100);
this.arms.reset(game.world.centerX, game.world.height - 100);
game.physics.p2.gravity.y = 600;
this.chest.body.collideWorldBounds = true;
this.arms.anchor.setTo(0.5, 0.5);
this.arms.body.data.gravityScale = 0;
this.constraint = game.physics.p2.createRevoluteConstraint(this.chest, [-14, -26.5], this.arms, [-4, 28]);
return this.cursors = game.input.keyboard.createCursorKeys();
},
update: function() {
if (this.cursors.left.isDown) {
this.arms.body.rotateLeft(60);
} else if (this.cursors.right.isDown) {
this.arms.body.rotateRight(60);
} else {
}
},
render: function() {
return game.config.enableDebug = true;
}
};
game.state.add('start', mainState);
game.state.start('start');
//# sourceMappingURL=application.js.map

<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.6/phaser.min.js"></script>
<div id="space"></div>
&#13;