• Content Count

  • Joined

  • Last visited

About kray

  • Rank

Contact Methods

  • Website URL

Profile Information

  • Gender
  1. No I'm not collide on the players and letters. this.check is a function to check if letters are collected in the correct order.
  2. I have a few bugs in my game: This game is help kids learn the correct order of the alphabets. When the dude sprite first collects a letter, i.e. A, it stops for a while and moves back, touching the world boundary. How do I prevent that? Code: this.physics.arcade.overlap(player, letters, this.collectLetter, null, this); collectLetter: function(player,letter) { this.arr.push(; this.check(); letter.kill(); }
  3. The sprite had a bounce and was not entirely touching the platform. Sorry.
  4. In my code, I have a ground, and some ledges. On pressing up arrow, I want my player sprite to jump only if he is on the ground or a ledge. I added the code: if (cursors.up.isDown && player.body.touching.down) { player.body.velocity.y = -250; } as I saw in phaser's official first tutorial. This is working for the ground but not for the ledges. When the player is on a ledge, the up arrow doesn't make the sprite jump. In my game, I have not added them to the same group. Is that why this is happening? This is the related code: platforms =; platforms.enableBody=true; var ground = platforms.create(0, - 64, 'ground'); ground.scale.setTo(2, 2); ground.body.immovable = true; ledges =; ledges.enableBody = true; ledges.body.immovable = true; player = this.add.sprite(32, - 150, 'dude'); //enable physics on the player this.physics.arcade.enable(player);cursors = this.input.keyboard.createCursorKeys(); this.timer =, this.drawLedge, this); var rand = Math.floor(Math.random() * 4500)+100; this.time2 =,this.drawHelp,this);update: function() { this.physics.arcade.collide(player,platforms); this.physics.arcade.collide(player,ledges); player.body.velocity.x = 0;'right'); if (cursors.up.isDown && player.body.touching.down) { player.body.velocity.y = -250; } },drawLedge: function() { var ledge_y = Math.floor(Math.random()*; var ledge = ledges.create(,ledge_y,'ledge'); ledge.anchor.setTo(0.5); ledge.checkWorldBounds = true; ledge.kilOutOfBounds = true; ledge.body.velocity.x=-150; }, drawHelp: function() { var helper = ledges.create(, Math.floor(Math.random()*,'ledge'); helper.anchor.setTo(0.5); helper.body.velocity.x = -150; helper.checkWorldBounds = true; helper.kilOutOfBounds = true; },Am I missing something?
  5. When I changed ground to a group, it started working.
  6. I have enabled physics, but it isn't working. On writing this.physics.arcade.collide(letters,ground);there is no overlap and the letter is stopping above the ground. But if I don't give this statement, as soon as letter comes in contact with the ground, the ground falls down.
  7. Do functions take parameters implicitly? I need to check for overlap and kill a sprite if overlap is true. So far, this is my code: update: function() { this.physics.arcade.collide(player,ground); this.physics.arcade.collide(letters,ground); this.physics.arcade.overlap(player, letters, this.collectLetter, null, this); this.physics.arcade.overlap(letters, ground, this.killLetter, null, this);My functions are: collectLetter: function(player,letter) { letter.kill(); //increase score }, killLetter: function(letter,ground) { letter.kill(); }But this doesn't seem to be working. The sprite is not being killed in killLetter, when it overlaps with the ground. Although it is being killed in collectLetter, i.e, when a player overlaps with it.
  8. I have an atlas containing all letters. Due to some reason, the image chosen from the atlas is not being displayed. Instead, it just shows a black box. My preloader: preload: function() { this.load.spritesheet('dude', 'asset/dude.png', 32, 48); this.load.atlas('alphavets','asset/letters.png','asset/letters.json'); this.load.image('ground','asset/platform.png'); this.load.image('sky','asset/sky.png'); }Using the atlas: var x = Math.floor(Math.random()*1000); var letter = this.add.sprite(x, 0, 'alphabets'); letter.frameName = "a.png"; this.physics.arcade.enable(letter); console.log("Chosen: "+img); letter.body.gravity.y = 200;Why is this happening? The console also says phaser.js not found. I have copied phaser.min.js to my folder.
  9. In my game, I need letters to fall from the sky. For the letters, I have created an atlas. The problem is, I cannot apply gravity on those letters. I'm reading images as: this.load.atlas('alphabets','asset/letters.png','asset/letters.json');var img = (String.fromCharCode((Math.floor(Math.random()*100)%26)+97))+'.png'; var x = Math.floor(Math.random()*1000); // Create a star inside of the 'stars' group var letter = this.add.sprite(x, 0, 'alphabets'); //letter.frameName = img;On typing letter.body.gravity.y = 200I get an error saying 'Cannot read property gravity of null'. Don't atlases have bodies?
  10. I need to select an image at random from my atlas. I used Texture Packer to make the atlas. But I don't understand how to get an image from the atlas. This is my code: preload: function() { this.load.spritesheet('dude', 'asset/dude.png', 32, 48); this.load.atlas('alphabets','asset/letters.png','asset/letters.json'); this.load.image('ground','asset/platform.png'); },I found this method to use atlases, using frameName: var x = Math.floor(Math.random()*10);var letter = this.add.sprite(x, 0, 'alphabets');//letter.frameName = img;letter.frameName = "a.png";// Let gravity do its thingletter.body.gravity.y = 200;However, my console says Cannot read property 'gravity' of null. Why is letter null? Am i reading it wrong?
  11. I have a game in which sprites(letters) will be falling from the top and the player has to collect the sprites in a specific order. The trouble I'm having is, how do I keep track of the order in which the player is collecting the sprites?
  12. I understood the issue. It is because answer is called only when the condition becomes true and then the function exits. How do make the control sty within the function?
  13. In my code, after checking a condition, I changed the y position of my sprite (a ship). When I do that, the ship does not stay at that position, instead it flies off the screen. The code: answer: function(sprite) { if( == "have") { this.bgMusic.stop(); this.bgMusic.loop = false; this.cheer ='cheer');; this.ship.y=340; this.text.y=420;}I tried adding this.ship.body.velocity.y=0;this.text.body.velocity.y=0;but it has no effect. What seems to be the issue?
  14. kray

    turn off group gravity

    What is the problem you are facing when you try this code?