Jump to content

callidus

Members
  • Content Count

    22
  • Joined

  • Last visited

Everything posted by callidus

  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.
  15. I'm trying to spawn a randomly coloured block and to do so I am using math.random and the console says everything is loading but the assets aren't loading. There are no errors in it but can anyone find an error that might be causing the assets not to load? Parts of the code that's relevant is coloured 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 x = Math.floor(Math.random () * 800); // ball spawns in a random placevar y = Math.floor(Math.random() * 600);var text; var c
  16. I want a ball to bounce but my current code isn't working and I don't know why, thanks for any feedback. My Code: * I have made the parts of the code which are relevant green var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update,});var x = Math.floor(Math.random () * 800); // ball spawns in a random placevar y = Math.floor(Math.random() * 600);var text; function preload() {cursors = game.input.keyboard.createCursorKeys(); //allows keyboard inputthis.game.load.image("block","assets/block.png");th
  17. http://www.youtube.com/channel/UCLj4fAgRzjHaD7vICKaUbZA/videos This channel has everything step by step from the beginning of setting up phaser to using it for mobile games. It deserves more attention. It currently has about 5 views per video.
  18. I downloaded Brackets and opened my files in it, but once I open the html file the canvas is all black and two errors come up. These are, error 1: Failed to load resource: the server responded with a status of 400 (Bad Request) and error 2: Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://127') does not match the recipient window's origin ('http://127'). *note: I took out some of the numbers in the brackets of the second error since it displays personal data regarding the server. Thanks for any help
  19. Thank you everyone for your answers and especially Chupup for your suggestion of using brackets. The program fixed my problems.
  20. Is a local web server like cloud9 necessary to code in phaser? I heard about it recently but up until now i have simply been opening the canvas on my web browser and everything has been working fine. I dont use anything like cloud9 to run my code and havent had any problems. But even the phaser setup talks about downloading a local web server. So ultimately im confused, do we really need one, and if so why. I dont seem to have any problems just coding and opening it in my browser.
  21. I'm trying to have my sprite jump, and the conditions are if he is on the floor and if I'm pressing the up key. But he wont jump even when he's on the floor. When taking "player.body.touching.down" out of the code the sprite jumps so I'm assuming something in my code is interfering with hit detection between the player and the ground. Here is the code: (I have coloured the part of the code which I assume is the problem and anything that is relevant green) Any help is greatly appreciated var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: creat
×
×
  • Create New...