Advertisement
benshepherd

Untitled

Feb 1st, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function LovelockSticker()
  2. {
  3.     var ctx = null;
  4.     var canvas = null;
  5.     var width = 375;
  6.     var height = 210;
  7.     this.background = null;
  8.     this.habboLeft = null;
  9.     this.habboLeft_x = 120;
  10.     this.habboLeft_y = 0;
  11.     this.habboRight = null;
  12.     this.habboRight_x = 255;
  13.     this.habboRight_y = 0;
  14.  
  15.     this.setCanvasById = function(selector)
  16.     {
  17.         canvas = document.getElementById(selector);
  18.         ctx = canvas.getContext('2d');
  19.         canvas.width = width;
  20.         canvas.height = height;    
  21.         this.update();
  22.     }
  23.     this.setBackground = function(src)
  24.     {
  25.         this.background = getImage(src);
  26.         this.update();
  27.     }
  28.  
  29.     this.setHabboLeft = function(src)
  30.     {
  31.         var callback = this.update;
  32.         this.habboLeft = getImage(src, callback);
  33.     }
  34.  
  35.     this.setHabboRight = function(src)
  36.     {
  37.         this.habboRight = getImage(src);
  38.         this.update();
  39.     }  
  40.  
  41.     this.update = function()
  42.     {  
  43.         console.log('lovelock updating...', this.background, this.habboLeft);
  44.  
  45.         if(this.background != null) {
  46.             console.log('lovelock debug 0');
  47.             ctx.drawImage(this.background,0,0);
  48.         }
  49.  
  50.         if(this.habboLeft != null) {
  51.             console.log('lovelock debug 1');
  52.             ctx.drawImage(this.habboLeft, this.habboLeft_x, this.habboLeft_y);
  53.         }
  54.  
  55.         if(this.habboRight != null) {
  56.             console.log('lovelock debug 1');
  57.             ctx.drawImage(this.habboRight, this.habboRight_x, this.habboRight_y);
  58.         }      
  59.     }
  60.  
  61.     var getImage = function(src, callback)
  62.     {
  63.         var img = new Image;
  64.  
  65.         if(typeof callback == 'function')
  66.         {
  67.             img.onload = callback;
  68.        
  69.         }
  70.        
  71.         img.src = src;
  72.         return img;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement