khleug35 Posted February 3, 2019 Share Posted February 3, 2019 About the joystick plugin problem. Is it possible to make the sprite rotation angle follow by joystick pad position?? if the joystick pad move to right-left, the sprite angle is right-left like the following images The following is my solution, but I think it is not the best way. I create the hidden object and the joystick can control the hide sprite movement. this.gun.rotation= this.gun.position.angle(game.scene.HiddenObject.point.position); like the following image Hidden object class game.createClass('HiddenObject', { init: function() { this.point = new game.Sprite('circle2.png') this.point.anchorCenter(); this.point.alpha =0 this.body = new game.Body(); this.body.collisionGroup = game.Body.POINTER; this.body.collideAgainst= [game.Body.WALL]; this.body.position.x = 500; this.body.position.y = 600; var shape = new game.Rectangle(this.point.width, this.point.height); this.body.addShape(shape); this.body.addTo(game.scene.world); this.body.collide = this.collide.bind(this); var ths = this; }, collide: function(body) { if (body.collisionGroup === game.Body.WALL) { return true; } return true; }, update: function() { if(game.scene.joystick2.axis.x ==0 && game.scene.joystick2.axis.y ==0){ this.body.velocity.x = 0; this.body.velocity.y = 0; } this.point.position.x = this.body.position.x; this.point.position.y = this.body.position.y; this.body.velocity.x += game.scene.joystick2.axis.x * 4800; this.body.velocity.y += game.scene.joystick2.axis.y * 4800; } Rotation Sprite class game.createClass('rotationsprite', { init: function() { this.gun = new game.Sprite('gun.png'); this.gun.anchorCenter(); this.gun.position.set(450, 550); this.gun.addTo(game.scene.container); }, update: function(){ this.gun.rotation= this.gun.position.angle(game.scene.HiddenObject.point.position); } } }); Any idea,? thank, I am sorry about my poor English. Quote Link to comment Share on other sites More sharing options...
enpu Posted February 3, 2019 Share Posted February 3, 2019 Hi! Here is example project, that shows you how to do it example.zip Wolfsbane and khleug35 2 Quote Link to comment Share on other sites More sharing options...
khleug35 Posted February 4, 2019 Author Share Posted February 4, 2019 @enpu OH, Thank you very much for this solution, !! I downloaded the example It is more helpful and work for me !!!! thanks again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.