Jump to content

callidus

Members
  • Content Count

    22
  • Joined

  • Last visited

About callidus

  • Rank
    Member

Recent Profile Visitors

1369 profile views
  1. knight = game.add.sprite(game.width/2,game.height-175,'knight'); game.physics.enable(knight, Phaser.Physics.ARCADE); knight.body.collideWorldBounds = true; weapon = knight.addChild(game.make.sprite(15, -15, 'greatsword')); //weapon.anchor.setTo(1,1) Knight is my player, and he holds a sword that I implemented as a child of the knight. My issue is that it follows the player but doesn't flip when he turns. I tried to set the weapon as an anchor but I get an error "Cannot read property 'anchor' of undefined". Thanks for any help
  2. After looking through the docs I realized there's a function that solves my problem. I called: game.physics.arcade.moveToObject(bubbleBullet, bubbles.getAt(0), 800); this grabs the first spawned bubble (therefore closest to the cannon) and has the bullet move towards it.
  3. Thank you your implementation has been helpful. I noticed you used tweens, is there any way to do this with velocity? I'd prefer to implement the bullets movement with an x and y velocity based on the angle between the cannon and the bullet.
  4. I have a cannon and bubbles that spawn at random points from the top of the screen. The cannon currently faces the bubble that's closest to it. The issue is the bullet itself shoots in a straight line regardless of the angle of the cannon, I want the bullet to shoot in the same angle. I've tried using velocityFromAngle and such but can't seem to figure it out. If you look at my fireCannon() code on line 130 you can see my attempts commented out. Thank you for any assistance. // Initialize the Phaser Game object and set default game window size const game = new Phaser.Game(325, 600,
  5. I see thank you this worked, I was over-complicating the problem in my head
  6. I've tried adding the text like this: function createBubble(xCoord, frame,value){ bubbleInstance = bubbles.getFirstDead(); bubbleInstance.reset(xCoord,0); bubbleInstance.anchor.setTo(0.5, 0.5); bubbleInstance.body.velocity.y = VELOCITY; bubbleInstance.frame = frame; //tracking the value of each bubble in an array BVALUES[currIndex] = value; currIndex++ bubbleInstance.addChild(game.make.text(0,0,BVALUES[currIndex])) //NEW LINE HERE } but I'm not sure how to handle changing the text. Lets say I have a function that handles the text change with setText, how should I
  7. I have a unique health value for each instance of a group, and I want to display it on the sprite as if it was a numeric health bar. Group object: Here is where my group members are being created. I have an array that stores a randomly generated health value and assigns it to the array based on the member that was produced (currIndex starts at 0). So I want to somehow associate the health value stored in the array with the current member, and display this over top of the sprite. So each sprite member has a corresponding health value in the array. Is there a better way to asso
  8. I want the bullets to fire in the direction the ship is facing such as in this example: https://phaser.io/examples/v2/arcade-physics/asteroids-movement I have followed the same code structure but my bullets don't fire in the direction I'm facing. Code: // Initialize the Phaser Game object and set default game window size const game = new Phaser.Game(325, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update }) function preload () { //player assets game.load.spritesheet('player', '
  9. Thanks to both of you, this solved my problem. Damn this community is fast I posted this like an hour ago lol.
  10. I have been trying to separate my code into states but no matter what I try the game comes up with a black screen, and an error saying "No state found with the key: playTest " . Here is my code: Thanks for any help this has been bothering me for a while *Note: each colour is a different file (index,load and playTest). Index: <!DOCTYPE html><html> <head><meta charset="utf-8" /><script src="phaser.js"></script><script src="load.js"></script><script src="playTest.js"></script></head> <body> <script> function creat
  11. In my game I want an animation to play when the player collides with a red block and dies. I used the arcade physics system and said a function called gameOver should trigger when the player and a block overlap. The animation I'm using is an explosion, the function then calls for the player to be killed and removed from the canvas and for the explosion sprite to be added and for it's animation to play. The problem is that the function only plays the first frame, I'm assuming this is because either the function only runs once after they overlap or because the player dies and therefore without t
  12. *face-palm*, thanks, didn't even notice the for loop started at 0.
  13. In my code im trying to have 3 diff colour blocks spawn in various areas on the screen, but one of the three red blocks spawns exactly on top of a blue one every single time. It makes no sense as I am using a math.random and have even used a game.add.text to make sure that the numbers aren't exactly the same yet it keeps happening. The relevant code is in green, thanks for any help. My code: var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update,});var Rx = Math.random () * 800; // ball spawns in a random placevar Ry = M
  14. Thank you very much for the answer, it worked perfectly.
×
×
  • Create New...