newbieCoder Posted November 2, 2017 Share Posted November 2, 2017 Hi, I bought the joystick plug in and seems like it is a little bit different than the tutorial. I try to remove the prototype from the plug in code but not be able to change all "this" to the object name. I wonder if anyone has suggestions ? <script type="text/javascript"> var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update }); function preload() { game.load.atlas('generic', 'assets/virtualjoystick/skins/generic-joystick.png', 'assets/virtualjoystick/skins/generic-joystick.json'); game.load.image('ship', 'assets/virtualjoystick/thrust.png'); game.load.image('bg', 'assets/virtualjoystick/sky2.png'); } var sprite; var pad; var stick; var buttonA; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.renderer.renderSession.roundPixels = true; bullets = game.add.physicsGroup(); bullets.createMultiple(32, 'bullet', false); bullets.setAll('checkWorldBounds', true); bullets.setAll('outOfBoundsKill', true); game.add.image(0, 0, 'bg'); this.sprite = this.add.sprite(400, 350, 'ship'); this.sprite.texture.baseTexture.scaleMode = PIXI.NEAREST; this.sprite.scale.set(2); this.sprite.anchor.set(0.5); this.sprite.angle = -90; this.physics.arcade.enable(this.sprite); this.pad = this.game.plugins.add(Phaser.VirtualJoystick); this.stick = this.pad.addStick(0, 0, 200, 'generic'); this.stick.alignBottomLeft(20); this.stick.motionLock = Phaser.VirtualJoystick.HORIZONTAL; this.buttonA = this.pad.addButton(500, 520, 'generic', 'button1-up', 'button1-down'); this.buttonA.alignBottomRight(20); } function update() { var maxSpeed = 400; if (this.stick.isDown) { this.sprite.body.velocity.x = this.stick.forceX * maxSpeed; } else { this.sprite.body.velocity.x = 0; } } game.state.add('Game', PhaserGame, true); </script> Link to comment Share on other sites More sharing options...
rich Posted November 2, 2017 Share Posted November 2, 2017 Here, like this: <script type="text/javascript"> var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update }); function preload() { game.load.atlas('generic', 'assets/virtualjoystick/skins/generic-joystick.png', 'assets/virtualjoystick/skins/generic-joystick.json'); game.load.image('ship', 'assets/virtualjoystick/thrust.png'); game.load.image('bg', 'assets/virtualjoystick/sky2.png'); } var sprite; var pad; var stick; var buttonA; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.renderer.renderSession.roundPixels = true; bullets = game.add.physicsGroup(); bullets.createMultiple(32, 'bullet', false); bullets.setAll('checkWorldBounds', true); bullets.setAll('outOfBoundsKill', true); game.add.image(0, 0, 'bg'); sprite = this.add.sprite(400, 350, 'ship'); sprite.texture.baseTexture.scaleMode = PIXI.NEAREST; sprite.scale.set(2); sprite.anchor.set(0.5); sprite.angle = -90; game.physics.arcade.enable(sprite); pad = game.plugins.add(Phaser.VirtualJoystick); stick = pad.addStick(0, 0, 200, 'generic'); stick.alignBottomLeft(20); stick.motionLock = Phaser.VirtualJoystick.HORIZONTAL; buttonA = pad.addButton(500, 520, 'generic', 'button1-up', 'button1-down'); buttonA.alignBottomRight(20); } function update() { var maxSpeed = 400; if (stick.isDown) { sprite.body.velocity.x = stick.forceX * maxSpeed; } else { sprite.body.velocity.x = 0; } } game.state.add('Game', PhaserGame, true); </script> newbieCoder 1 Link to comment Share on other sites More sharing options...
newbieCoder Posted November 2, 2017 Author Share Posted November 2, 2017 Awesome, ... ... thanks a lot, rich Link to comment Share on other sites More sharing options...
Recommended Posts