PixelProgrammer

Members
  • Content count

    29
  • Joined

  • Last visited

  1. Hey there, So I've snagged onto a little problem while developing my game. I'm using Phaser with it's inbuilt support of gamepad. The axis of the controller input works in a way such that it returns 1 when held to the right and -1 when held to the left. Here's a picture to make things easier to understand. How would I map the values to degrees? Here's a visual representation of what I'd like to get. What's a formula that would allow me to do this?
  2. @samme you beautiful human being! orb.world was just what I wanted. Thank you!
  3. Hi there! So here's my issue. I have a player sprite which has an orb sprite attached to it as a child. Player = function (game, x, y, image) { Phaser.Sprite.call(this, game, x, y, image); //calls constructor this.orb = this.addChild(game.make.sprite(0, 0, 'orb')); game.add.existing(this); }; /*--------------------------------------------------------*/ Player.prototype = Object.create(Phaser.Sprite.prototype); Player.prototype.constructor = Player; /*--------------------------------------------------------*/ I want to reference the x and y positions of the orb so that I can shoot bullets out of it. BUT, if I console.log(this.orb.x) or the y position, the value that is returned is 0. What do I do so that I can get the x and y positions of the orb, relative to the game world and not the parent sprite??
  4. @samme Thank you. However, I'm afraid I won't be able to use the CE since I've already built most of my game on the official version. Do you think there's another way I could fire multiple bullets at the same time?
  5. @samme I saw that on another thread but was unsure of what it was. Could you please explain or give me a list of what Phaser CE is and how I'd implement it?
  6. Hi there, I want to build a shotgun weapon for my game. This shotgun would shoot 3 (or more) bullets in a conical angle. However, from what I see, Phaser.Weapon only fires one bullet at a time. What do I do in order to get the weapon to fire 3 bullets consecutively
  7. Hi there, I want to extend Phaser.Weapon so I can create my own custom weapons. I know that you extend groups by using Weapon.SingleBullet = function (game) { Phaser.Group.call(this, game, game.world, 'Single Bullet', false, true, Phaser.Physics.ARCADE); return this; }; Weapon.SingleBullet.prototype = Object.create(Phaser.Group.prototype); Weapon.SingleBullet.prototype.constructor = Weapon.SingleBullet; But what about the weapons group? Are there any examples out there for this? EDIT: I used Weapon.SingleBullet.prototype = Object.create(Phaser.Weapon.prototype); and it seems to work. However, when I try to fire my bullet I get the following error Cannot read property 'getFirstExists' of null at Pistol.Phaser.Weapon.fire (phaser.js:101053)
  8. So I'm currently following @rich 's Shoot-em-up tutorial from over here https://phaser.io/tutorials/coding-tips-007. Please have a look at the source code if you haven't already. From what I understand he create's a weapon array that holds all the weapon types (each of which are an object inside a Weapon object). Now my question is How do I access the current weapon bullets in game.physics.arcade.collide? I've used game.physics.arcade.collide(this.weapon[this.currentWeapon], this.enemies) and this works fine, the bullets and the enemy collide well. BUT what if I want to kill that bullet? How would I pass the specific bullet that collided with the enemy into a function? This is what I've tried: game.physics.arcade.collide(this.weapon[this.currentWeapon], this.enemies, function(bullet, enemy) { bullet.kill(); }, null, this); However the above code doesn't work. Bullet is undefined. What do I do?
  9. @drhayes Yup. onInputUp is what I was looking for.
  10. @samme Awesome! This is exactly what I wanted.
  11. @drhayes I'm sorry if I phrased the question badly. Let me clarify. I want to use phasers call back function. When I click the button I want the function to run. BUT I ALSO want to run the function whenever I want (For example when the user presses A on the controller). Now I know I can put all the callback functions in an array (and this is what I'm currently doing). But I feel this is bad code. Because if I were to rearrange buttons, I would have to rearrange the callback functions in the code in the same order as the buttons. I was just wondering if there was a way to access a button object's callback function. Such as playButton.callbackFunction()//runs play function. Where does phaser save the callback functions? Is it within the object itself or somewhere else?
  12. So I'm currently trying to implement controller support in my menu. The way I'm doing this right now is by pushing all the buttons into an array and when the player presses up or down on the dpad, they traverse through the array. But here's the issue. What do I use to access the callback parameter of the button? Essentially what I want to do is when the player reaches the button he wants to press in the array, I want to run the callback function. I know phaser does the automatically if you clicked the button. But what if I want to do it manually? if (controller.peressed.A_Button){ buttonArray[currentIndex].callbackFunction() }
  13. @mwiss Thanks I've implemented something like what you've recommended.. movePlayer: function (player) { if (!player.alive) return ; var pad = (player.color == "red") ? this.pad1 : this.pad2; /*-- Movements --*/ if (player.cursor.left.isDown || pad.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X)< -0.1){ //move left player.body.velocity.x = -300; player.animations.play('left'); } else if (player.cursor.right.isDown || pad.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X)>0.1){ //move right player.body.velocity.x = 300; player.animations.play('right'); } else { player.body.velocity.x = 0; player.animations.stop(); player.frame = 2; } } I'll only keep this as a temporary solution. I'll definitely review it again and change it to more like what you've said.
  14. I'm currently building a two player platform-shooting game that supports controllers. Right now I have two separate move functions placed in the update that handles player movement. Here's the code: movePlayer1: function () { if (!player.alive) return ; //controller input if(this.pad1.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X)< -0.1){ this.player_1.body.velocity.x = -300; //move left this.player_1.animations.play('left'); } if(this.pad1.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X)>0.1){ this.player_1.body.velocity.x = 300; //move right this.player_1.animations.play('right'); } if(this.pad1.justPressed(Phaser.Gamepad.XBOX360_A)&& this.player_1.body.onFloor() ){ this.player_1.body.velocity.y = -999; //jump } this.player_1.weapon.fireAngle = -(90 + 90 * -this.pad1.axis(Phaser.Gamepad.XBOX360_STICK_RIGHT_X)); if(this.pad1.isDown(Phaser.Gamepad.XBOX360_RIGHT_TRIGGER)||this.pad1.justPressed(Phaser.Gamepad.XBOX360_RIGHT_BUMPER)) { this.player_1.weapon.fire(); } }, movePlayer1: function () { //player 2 controller if(game.input.gamepad.supported && game.input.gamepad.active && game.input.gamepad.pad2.connected) { this.indicator2.animations.frame = 0; } else { this.indicator2.animations.frame = 1; } if(this.pad2.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X)< -0.1){ this.player_2.body.velocity.x = -300; this.player_2.animations.play('left'); } if(this.pad2.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X)>0.1){ this.player_2.body.velocity.x = 300; this.player_2.animations.play('right'); } if(this.pad2.justPressed(Phaser.Gamepad.XBOX360_A)&& this.player_2.body.onFloor() ){ this.player_2.body.velocity.y = -999; } this.player_2.weapon.fireAngle = -(90 + 90 * -this.pad1.axis(Phaser.Gamepad.XBOX360_STICK_RIGHT_X)); if(this.pad2.isDown(Phaser.Gamepad.XBOX360_RIGHT_TRIGGER)||this.pad2.justPressed(Phaser.Gamepad.XBOX360_RIGHT_BUMPER)){ this.player_2.weapon.fire(); } } , I feel that this isn't the best way to code for two player movement. What would you do differently?
  15. @Legomite Theoretically it should cost less since it wouldn't have to render it.