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 <----  
                    
                                    
                }
                
            }
 
Associate
Joined
16 Apr 2007
Posts
2,208
Something like
Code:
this.move = function() {
               
            this.bounds = {
                
                walking: {
                    
                    x: this.x - 5,
                    y: this.y - 5,
                    w: this.dw + 10,
                    h: this.dh + mobileFunc ();
                    
                                    
                }
                
            }
mobileFunc = function(){
var mobileStop = 300;
if (ismobile) {
            mobileStop = 130; 
        }  
return mobileStop;
}

Should work.

Not tested though
 
Associate
OP
Joined
11 Oct 2008
Posts
268
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';
 
Associate
Joined
4 Feb 2011
Posts
580
Location
Halifax
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';

Sure,

Code:
var whatEnemyTouch = isMobile ? 'touchstart' : 'click';
window[whatEnemyTouch] = function(){}
 
Back
Top Bottom