JackBid

Members
  • Content Count

    19
  • Joined

  • Last visited

About JackBid

  • Rank
    Member
  • Birthday 04/29/1999

Contact Methods

  • Website URL
    www.jackbiddlecombe.co.uk

Profile Information

  • Gender
    Male
  • Location
    UK
  1. There is no set way to restart your game, its up to you to control how your game restarts and under what circumstances. However I think it can generally be broken down into two parts: 1. Detect that your game needs restarting. Maybe you want to restart the game when the user runs out of lives, or perhaps if he has shot a certain amount of enemies or if he clicks a restart button in your game. I would suggest putting some checks in your update function to see if the game need to be restarted, if they evaluate to true I would call a restart function. 2. Now you know that the gameplay needs restarting, how do you restart it? Well this is up to you, maybe you need to adjust the players position, or reset some score variables or add more enemies this is completely your decision to make dependent on your game - its your creation! This is the format that I would try and follow: update function() { // Inside our update function so constantly checked if(userClicksRestart() || userDead()){ // Check to see the game needs restarting restart(); // Call the restart function }}restart function() { // These are just examples of what you might do player.resetPosition(); // Reset the players position score = 0; // Reset the score to zero addMoreEnemies(); // Add more enemies to your game}I am not entirely sure what you are looking to do here, but this is just a brief overview of the logic that I might use to restart a game, I hope this helps.
  2. when I am creating a new group of sprites, if it possible to add an animation to these sprites? I could not find an example of it, or a previous post in the forums. I tried doing this: explosions.create(x, y, 'explosion');explosions.forEach(function(item){ item.animations.add("explode", [0,1]); item.animations.play("explode", 7, true);});However it responds with the error: Uncaught TypeError: Cannot read property 'uuid' of null
  3. Yeah pretty much, I checked what angled surface ii was (eg. if the bullet is moving up and should be reflecting to the right) and then I would center the bullet in the bounding box of that object, remove all velocity, rotate it to point in the right direction and add a new velocity. This does mean that the way the bullet reflects is not correct in terms of physics, but it is passable as the bullet moves fast and the user can barely notice the change. It is very simple and works surprisingly well, especially as I spend a while trying to think of more complex ways to achieve this!
  4. JackBid

    Ludum Dare 28

    Here is my entry using phaser: http://www.ludumdare.com/compo/ludum-dare-28/?action=preview&uid=21527 It is a bit buggy currently, I might try and develop the idea more though.
  5. You might want to check out this example, it shows a sprite colliding with a tilemap without any gravity. Make sure your using tileset.setCollision and tileset.setcollision range as in the example, you may also want to post some of your code in case it is a different bug in your code causing it!
  6. What I am trying to achieve is when a bullet is fired at a 45 degree slope, it bounces off at a 90 degree angle, this may be clearer looking at the attached image. As you can see you would expect the bullet to bounce off at a 90 degree angle when it collides with the slope. I have all the logic and code ready to bounce the bullet off at this angle, my problem is that the bounding box around the slope is square or rectangular, as a result the bullet bounces off the slope before it actually collides with the pixels. I read in the forums earlier that phaser only supports square/rectangular collision. But how else would I be able to achieve this in my game, it does not need to be perfect, but just passable?
  7. I think the only way to do this is to use game.debug: var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create, render: render });var floor;function create() { floor = new Phaser.Rectangle(0, 550, 800, 50);}function render () { game.debug.renderRectangle(floor,'#0fffff');}Is there a particular reason why you do not want to use game.debug?
  8. In one of the project I am working on. an animation is played when a sprite is colliding and the animation stops when the sprite exits collision. All I want to do is to check when the animation has reached the end (before is loops round again), or a simple method to check which frame an animation is on so I can check if it is on the last frame. So in other words, how you check which frame a sprite is on during an animation, or is there a way to check when a sprite has finished the animation before looping. Thanks.
  9. Just a guess, but you may need to use the setAll group method. group.setAll(scale.x, 2);i have not tested this myself, but it may be worth a try!
  10. Yes, but my main problem is that mummies and swords are arrays which contain objects. Part of the object is a phaser sprite, but the object as a whole is not just a sprite, this is where I am not sure how to fix it.
  11. Sword = function (x, y) { this.sprite = game.add.sprite(x, y, 'sword'); this.sprite.anchor.setTo(0.5, 0.5); this.sprite.immovable = true; this.sprite.body.velocity.y = -150; this.sprite.outOfBoundskill = true;};Mummy = function (x, y) { this.sprite = game.add.sprite(x, y, 'mummy'); this.sprite.anchor.setTo(0.5, 0.5); this.sprite.immovable = true; this.sprite.body.velocity.y = 30; this.sprite.animations.add('walk'); this.sprite.animations.play('walk', 7, true);}var swords = [];var mummies = [];function preload(){ game.load.spritesheet('player', 'assets/player.png', 64, 22); game.load.spritesheet('mummy', 'assets/mummy.png', 64, 22); game.load.image('sword', 'assets/sword.png');}function create(){ game.stage.backgroundColor = '#E2DBCE'; player = game.add.sprite(10,530, 'player'); player.name = 'player'; player.anchor.setTo(0.5, 0.5); player.body.collideWorldBounds = true; player.body.immovable = true; player.animations.add('walk'); leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT); rightKey = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT); spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);}function update() { game.physics.collide(swords, mummies, swordHitMummy. null, this); if (spaceKey.isDown) { createSword(player.x, player.y-50); } for (var i=0; i<10; i++){ createMummy(Math.random(), Math.random()); } }function createSword (x, y) { swords.push(new Sword(x, y));}function createMummy (x, y) { mummies.push(new Mummy(x, y));}function swordHitMummy (sword, mummy) { console.log("success");}The design of my game is that the player moves left and right firing swords (which move only up) at mummies (which move only down). The player is at the bottom of the canvas and the swords are created at the bottom and moved up, the mummies spawn in randomly at the top and move down. The code above had been edited and had pieces removed as to focus just on my current issue. I am unsure of how to collide the mummies and swords as they are stored in arrays. I tried a few ideas earlier but could not get it to work properly, so decided to post on here in order to find the best way to achieve this. I tried using groups, but it appeared that I could only store sprites in groups and not objects - although I could be wrong, I am quite new to this! I also tried looping through the arrays and colliding individual objects, but I had problems with objects with no sprite attached still colliding and causing errors. Basically I want to know what would be the best possible way to do this, am I even doing this at all right? Should I be using arrays (I noticed they were used in the tank example)? Please consider that I am quite new to programming and phaser. Thanks.
  12. My problem is that I do not know how to check if a body exits a collision state. I know how to check if it enters a collision, but not if it exits.
  13. I need to find a way to detect when a sprite exits collisions. My goal here is that when a sprite enters a collision an animation is played and when the sprite exits the collision the animation is paused leaving the sprite at a different frame from a sprite sheet. If there a simple built in function to phaser to achieve this? Or do I need to find a different solution. Here is my simple code so far: function update() { game.physics.collide(cup, sprite2, collisionHandler, null, this);}function collisionHandler (obj1, obj2) { cup.animations.play('fill', 10);}
  14. I spent a long time looking at lots of examples and managed to solve my problem! (On a side note I think I am beginning to realize how powerful phaser can be). Here is what i did if anyone needs it: Enemy = function(){ this.x = game.world.randomX; this.y = game.world.randomY; this.minSpeed = -75; this.maxSpeed = 75; this.vx = Math.random()*(this.maxSpeed - this.minSpeed+1)-this.minSpeed; this.vy = Math.random()*(this.maxSpeed - this.minSpeed+1)-this.minSpeed; this.enemySprite = game.add.sprite(this.x,this.y,"enemy"); this.enemySprite.anchor.setTo(0.5, 0.5); this.enemySprite.body.collideWorldBounds = true; this.enemySprite.body.bounce.setTo(1, 1); this.enemySprite.body.velocity.x = this.vx; this.enemySprite.body.velocity.y = this.vy; this.enemySprite.body.immovable = true; } var game = new Phaser.Game(600, 400, Phaser.AUTO, '', { preload: preload, create: create, update: update }); var numOfEnemies = 10; var player; var enemies; function preload() { game.load.image('enemy', 'assets/ball.png'); game.load.spritesheet("player", "assets/player.png", 20, 20, 2); } function create() { game.stage.backgroundColor = 0x8C8C8C; player = game.add.sprite(100,100,"player"); player.name = "Player"; player.animations.add("pulse"); player.animations.play("pulse", 20, true); player.anchor.setTo(0.5, 0.5); enemies = []; for (var i=0; i<numOfEnemies; i++) { enemies.push( new Enemy() ); } } function update() { player.x = game.input.x; player.y = game.input.y; for (var i=0; i<numOfEnemies; i++){ game.physics.collide(player, enemies[i].enemySprite, killPlayer, null, this) } } function killPlayer() { console.log('You Died'); }
  15. I am very new to phaser but what I am trying to achieve here is lots of sprites (in a group) moving at a constant speeds in different directions. This is the code I have so far: var game = new Phaser.Game(600, 400, Phaser.AUTO, '', { preload: preload, create: create, update: update });var enemies;var numOfEnemies = 10;function preload() { game.load.image('gold', 'assets/gold.png');}function create() { game.stage.backgroundColor = 0x8C8C8C; enemies = game.add.group(); for (var i=0; i<numOfEnemies; i++) { createEnemy(); }}function update() { for (var i=0; i<numOfEnemies; i++) { enemies.getAt(i).x += Math.random()*2; enemies.getAt(i).y += Math.random()*2; }}function createEnemy() { enemies.create(Math.random()*(game.width-32),Math.random()*(game.height-32),"gold");}The problem here is that the speed of each object in the group changes every update. I think the solution here would be to make it so that every object created has a set speed in the createEnemy function but it is different for each object in the group. How would I do something like this?