Muthar

Members
  • Content Count

    1
  • Joined

  • Last visited

  1. Muthar

    overlap

    hey guys hey i am new this , i am making a game and in this game i wanted when the player overlap with the coin, the coin disappear but its not over for some reason and i don't why. i have tired a lot of ways even i tired asking the coin into a tile when i made the map but even than it still doesn't work this is my code var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.tilemap('level12', 'res/level12.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('sprite12', 'res/sprite12.png'); game.load.spritesheet('dude', 'res/player.png', 64, 64); game.load.spritesheet('droid', 'res/droid.png', 32, 32); game.load.image('starSmall', 'res/star.png'); game.load.spritesheet('coin', 'res/coin.png',32,32 ); game.load.image('background', 'res/sprite3.png'); } var map; var tileset; var layer; var player; var facing = 'left'; var jumpTimer = 0; var cursors; var jumpButton; var bg; var coin; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#000000'; bg = game.add.tileSprite(0, 0, 800, 600, 'background'); bg.fixedToCamera = true; map = game.add.tilemap('level12'); map.addTilesetImage('sprite12'); map.addTilesetImage('coin'); map.setCollisionBetween(1, 12); map.setCollisionByExclusion([ 13, 14, 15, 16, 46, 47, 48, 49, 50, 51 ]); layer = map.createLayer('Tile Layer 1'); layer.resizeWorld(); coin = game.add.group(); coin.enableBody = true; coin.physicsBodyType = Phaser.Physics.ARCADE; createcoin(); game.physics.arcade.gravity.y = 200; player = game.add.sprite(150, 900, 'dude'); game.physics.enable(player, Phaser.Physics.ARCADE); player.body.bounce.y = 0.2; player.body.collideWorldBounds = true; player.animations.add('left', [3,2,1,0], 10, true); player.animations.add('right', [4,5,6,7], 10, true); game.camera.follow(player); cursors = game.input.keyboard.createCursorKeys(); jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); game.physics.arcade.overlap(coin, player, killcoin(), null, this); } function killcoin(coin,player) { coin.kill(); } function createcoin() { coin = game.add.sprite(50,700, 'coin'); } function update() { game.physics.arcade.collide(player, layer); player.body.velocity.x = 0; if (cursors.left.isDown) { player.body.velocity.x = -150; if (facing != 'left') { player.animations.play('left'); facing = 'left'; } } else if (cursors.right.isDown) { player.body.velocity.x = 150; if (facing != 'right') { player.animations.play('right'); facing = 'right'; } } else { if (facing != 'idle') { player.animations.stop(); if (facing == 'left') { player.frame = 0; } else { player.frame = 5; } facing = 'idle'; } } if (jumpButton.isDown && player.body.onFloor() && game.time.now > jumpTimer) { player.body.velocity.y = -250; jumpTimer = game.time.now + 750; } } function render () { } if anyone can help would be great Regards