• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

HTML5 Multitouch running a step twice?

F

FloresSottile

Guest
Hi, i'm working on a game for HTML5. I know it's just not the best platform to put a game on, but it's just how I was asked to do it.
I've made some buttons to move: left and right which are triggered by the user's left finger and shooting which is triggered by touching the right side of the screen.

This works so far, the only problem I have is that when i'm moving and also shooting, the instance creation for the bullet runs twice. But when i'm only shooting it runs once. What I want is to only shoot one bullet per touch on the screen and not twice as it happens when I'm also moving the character.

This is the code:

Code:
for(i=0;i<4;i++){
    if(device_mouse_check_button(i,mb_any)){
        if(point_in_rectangle(device_mouse_x(i),device_mouse_y(i),0,room_height-barHeight*2,room_width/6+3,room_height-barHeight)){
            leftFinger = -1;
        }
   
        if(point_in_rectangle(device_mouse_x(i),device_mouse_y(i),room_width/6+4,room_height-barHeight*2,room_width/3+3,room_height-barHeight)){
            leftFinger = 1;
        }
    }
   
    if(device_mouse_check_button_released(i,mb_any)){
        if(point_in_rectangle(device_mouse_x(i),device_mouse_y(i),room_width-room_width/4,0,room_width,room_height)){
            rightFinger = 1;
        }  
    }

}


if(leftFinger == -1){
    oCannon.x -= oCannon.xSpeed;
    show_debug_message("MOVE LEFT");
    leftFinger =  0;
}

if(leftFinger == 1){
    oCannon.x += oCannon.xSpeed;
    show_debug_message("MOVE RIGHT");
    leftFinger = 0;
}
   
if(rightFinger == 1 and canShoot){
    audio_play_sound(sndShoot,10,false);
    instance_create_depth(oCannon.x,oCannon.y-sprite_get_height(sCannon),-1001,oProjectile);
    show_debug_message("SHOOT");
    rightFinger = 0;
}
Just in case you ask, the variable canShoot sets to true once the instructions have been read and never changes again.

Thanks in advance.
 
Top