Dave February 2016

Mousedown not working on Iphone?

I am try to make a mousedown function work on ios however cant seem to fix the issuse. I know the problem is with the code below any help would be greatful!

 bindInteractions: function(){
        // bind interactions used during live play
        this.playfield.on('mousedown','touchstart', _.throttle(_.bind(function(event){
            this.fireGun();
            var weaponSpread = this.player.getWeapon().getSpread();
            if(weaponSpread <= 0) {
              console.error("Zero spread weapons can do no damage. Recommended minimum size: 25");
            }
            var playfieldOffset = $(event.delegateTarget).offset();
            var location = {
                top: event.pageY - playfieldOffset.top,
                left: event.pageX - playfieldOffset.left
            };
            $.each(this.liveDucks, function(i,duck){
               duck.shotsFired(location, weaponSpread);
            });

        },this), this.player.getWeapon().getReloadTime()));
        this.showLevelInfo();
    },
    unbindInteractions: function(){
        // unbind interactions that should not be available during transitions and other non live play states
        this.playfield.off('mousedown','touchstart');
        $.each(this.liveDucks, function(i, duck) {
            duck.unbindEvents();
        });

Answers


radioaktiv February 2016

Jquery official docs:

The mousedown event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed.

https://api.jquery.com/mousedown/

Question: Do you have a mouse pointer on mobile devices ?


Niko February 2016

According to JQuery documentation about .on()

.on( events [, selector ] [, data ], handler )

events

Type: String One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin".

It says One or more space-separated event types.

So maybe your mousedownand touchstart should be in the same string parameter :

this.playfield.on('mousedown touchstart', _.throttle(_.bind(function(event){

}

Post Status

Asked in February 2016
Viewed 2,954 times
Voted 12
Answered 2 times

Search




Leave an answer