Jump to content

Drag on edges and firing problem


Recommended Posts


I stared learing html5 game dev with the use of phaser engine and got few issues.


1. I host my app to google.drive and until it's loaded, there is black are on site. Is this something google specific? Can bee seen on: googledrive.com/host/0B929yjYvfjo7WlRySWhTUFVDRE0

2. I wanted to add left - right, right - left drag and drop (so let's say movement by sliding a sprite) and when i'm near the edges and do not release earlier my sprite, it's bouncing. It's probably by adding collideWorldBounds but is there a way to make it somehow better? Maybe i should use different code for edges handling. Example on this behaviour in link above, code available here

3. I would like to add to code above firing on slide on my sprite up but without moving sprite up. I just wanted to fire only one sprite at a time and be able to fire another only if this first hits another or leaves game area. So i added following code, but my code doesn't work as expected.

I did not how to make it on slide, so for test purposes i did it only on inputDown

player2blue.events.onInputDown.add(fire, this);

then in fire() function i added this "if (!bullet)", as i thought add.sprite and rest of code by only available when there is no such sprite, but this allows me to fire only once :) so probably i messed up something here.

function fire(){    if (!bullet) {        bullet = game.add.sprite(player2blue.x, player2blue.y, 'bullet');        game.physics.enable(bullet, Phaser.Physics.ARCADE);        bullet.checkWorldBounds = true;        bullet.outOfBoundsKill = true;        bullet.body.gravity.y = -2000;        bullet.body.velocity.y = 50;    }}

Then my update() and collisionHandler() functions

function update(){    game.physics.arcade.collide(opponent, bullet, collisionHandler, null, this);}function collisionHandler(){    bullet.kill();    opponent.kill();}

No matter, if my bullet hits another sprite (here collision works ok, both sprites are killed) or leaves game arena, i can only fire once, without if statement, i can fire multiple times, but it's not what i want. If you could provide me with some tutorials for that i would be grateful.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...