Search the Community
Showing results for tags 'pretty urgent'.
-
Hi guys, working on a project for school I just came accross a problem I can't seem to find a solution about. Here it is : So I have this enemy group rotating. The sprites are moving correcty but the bodies are staying in place because I set them to static = true. I have a gravity going on and I don't want them to be affected by it that's why they're set to static. Here's my code for these : EnemyGroup = function(positionX, positionY, radius, angle, rotateSpeed, clockwise) { Phaser.Group.call(this, game); this.position = {x:positionX, y:positionY}; this.radius = radius; this.pivot.x = positionX; this.pivot.y = positionY; this.angle = angle; this.rotateSpeed = rotateSpeed; this.clockwise = clockwise; this.addChild(new Enemy(this.position.x - this.radius, this.position.y, 0.4)); this.addChild(new Enemy(this.position.x + this.radius, this.position.y, 0.4)); this.addChild(new Enemy(this.position.x, this.position.y - this.radius, 0.4)); this.addChild(new Enemy(this.position.x, this.position.y + this.radius, 0.4)); this.update = function(){ if (this.clockwise) { this.angle += rotateSpeed; } else if (!this.clockwise) { this.angle -= rotateSpeed; } } } EnemyGroup.prototype = Object.create(Phaser.Group.prototype); EnemyGroup.prototype.constructor = EnemyGroup; Enemy = function(positionX, positionY, scale) { Phaser.Sprite.call(this, game, positionX, positionY, 'enemy'); game.physics.p2.enable(this, true); this.body.setCircle(7); this.scale.setTo(scale); this.anchor.setTo(0.5); this.body.setCollisionGroup(enemyCG); this.body.static = true; this.body.collides(playerCG); game.add.existing(this); this.update = function(){ } } Enemy.prototype = Object.create(Phaser.Sprite.prototype); Enemy.prototype.constructor = Enemy; The solution must be quite simple - I just don't see it at the moment. any clue ? Maybe have the rotation happening on single enemies with a pivot based on their parents - instead of rotating the whole group ? Thanks for reading !