js, how to add this variable?

Associate
Joined
11 Oct 2008
Posts
268
I'm trying to make a canvas elements position a little responsive.

I am using:

Code:
if (ismobile) {
            var mobileStop = 130; 
        }  else {
                    var mobileStop = 300; 
                }

If it detects that it is being played on a mobile device, i would like it to change the line below (h: this.dh + ) so it either adds 130 or 300 to h: this.dh.

I cant seem to get it working, I'm guessing i've done something stupid wrong, but is there a way to merge these?

Code:
this.move = function() {
               
            this.bounds = {
                
                walking: {
                    
                    x: this.x - 5,
                    y: this.y - 5,
                    w: this.dw + 10,
                    h: this.dh + ---> mobileStop here <----  
                    
                                    
                }
                
            }
 
moving on to a different part of my javascript game :P

is it possible to to change the 'onclick' part of:

Code:
window.onclick=function(e){

so instead of onclick, I can use:

Code:
var whatenemyTouch = isMobile ? 'touchstart' : 'click';
 
Back
Top Bottom