Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

angleToPointer on child sprite


Titus
 Share

Recommended Posts

Hi guys,

I'm trying to rotate a player's arm (anchored at the shoulder) to the mouse pointer using angleToPointer() method for aiming.  I have a player sprite and a frontArm sprite. angleToPointer works as expected until I make the frontArm sprite a child of the player sprite. When I do this, the frontArm sprite will get stuck at certain points and won't rotate any further. I'm a complete newbie to Phaser and game dev so any help would be appreciated. I'll put my code below:

	create: function() {
	
		this.background = this.game.add.sprite(0, 0, 'background');	
		this.game.physics.startSystem(Phaser.Physics.ARCADE);
		
		this.player = this.game.add.sprite(200, 500, 'player', 'Fire Marshall Main_00025'); 
		this.game.physics.arcade.enable(this.player);			
		this.player.anchor.setTo(0.5);

		this.frontArm = this.player.addChild(this.game.make.sprite(-10, -240, 'frontArm'));
		this.frontArm.anchor.setTo(0.48, 0.30);		
		this.game.physics.arcade.enable(this.frontArm);			

		//walk animation
		this.player.animations.add('walkright', Phaser.Animation.generateFrameNames('Fire Marshall Main_', 0, 24,'', 5), 24, true, false);
		this.player.animations.add('walkleft', Phaser.Animation.generateFrameNames('Fire Marshall Main_', 24, 0,'', 5), 24, true, false);
		

		cursors = this.game.input.keyboard.createCursorKeys();
		

	},

	update: function() {
//player walk movement
 this.player.body.velocity.x = 0;
	if (cursors.right.isDown) {
        this.player.body.velocity.x = 150;
        this.player.animations.play('walkright');
    }else if (cursors.left.isDown){
        this.player.body.velocity.x = -150;
        this. player.animations.play('walkleft');
    }else {
    	this.player.animations.stop();
    	this.player.frame = 25; 
    }

    this.frontArm.rotation = this.game.physics.arcade.angleToPointer(this.frontArm);





	}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...