Jump to content

Dropping water on touch


gatoRojo
 Share

Recommended Posts

Hello everyone, i'm developing this little game in wich an airplane drops water, but i haven't been able to set a remaining water bar, by far this is how i've been trying to achieve this:

I have three vars, aguatanker the total amount of water, then when function is called, fall is the duration of touch event, then remain is the aguatanker minus the fall, after that i update aguatanker to remain value.

var aguatanker = 1000;
var remain = 1000;

function droping(){
    fall = game.input.activePointer.duration;
    remain = game.math.difference(aguatanker,fall); 
    aguatanker = remain;
}

The problem is that the difference give any weird number, let say i have 1033 ms pressed, remain value should be -33, but istead is 574. Again, i have it pressed by 1933 ms and difference is 965.

Most probably i'm doing this all wrong, can you please help me?

Thanks!

Link to comment
Share on other sites

I'd rethinked how i was doing this and found an alternate solution

I'm doing it with a timer with 5000 ms, then everytime i touch the screen the timer runs and stops when i remove the finger....

When i have all done i'll reveal the game i hope. Thanks!

var water;
var aguatanker = 5000;

function create() {
    timer = game.time.create(false);
    timer.add(aguatanker,drop,this);
    timer.start();
}

function update() {
    
    water = timer.duration;

    if(game.input.activePointer.isDown) {
        timer.resume();
    } else {
        timer.pause();
    }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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