Advertisement
jargon

DrawStat ( );

Nov 9th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function drawSprite ( canvas, index, x, y ) {
  2.  
  3.     let context = canvas.getContext(`2d`);
  4.    
  5.     context.drawImage (             // Dest Context
  6.         Sprites[index].canvas,      // Source Canvas
  7.        
  8.         0,                          // Source X
  9.         0,                          // Source Y
  10.         Sprites[index].xspan,       // Source W
  11.         Sprites[index].yspan,       // Source H
  12.        
  13.         x * Sprites[index].xspan,   // Dest X
  14.         y * Sprites[index].yspan,   // Dest Y
  15.        
  16.         Sprites[index].xspan,       // Dest W
  17.         Sprites[index].yspan        // Dest H
  18.     );
  19.  
  20.     console.log(`Draw Sprite: "${Sprites[index].about.title}" @ ( ${x}, ${y} )`);
  21.  
  22.  
  23. }
  24.  
  25. function drawText ( canvas, index, x, y, text ) {
  26.    
  27.     let context = canvas.getContext (`2d`);
  28.    
  29.     context.fillStyle = `argb( 255, 255, 255, 1.0 )`;
  30.    
  31.     context.fillText (
  32.         text,
  33.         x * Sprites[index].xspan,
  34.         y * Sprites[index].yspan
  35.     );
  36.    
  37.     console.log(`Draw Text: "${text}" @ ( ${x}, ${y} )`);
  38. }
  39.  
  40. function drawSpriteText ( canvas, index, x, y, text ) {
  41.    
  42.     let context = canvas.getContext (`2d`);
  43.    
  44.     drawSprite ( canvas, index, x, y );
  45.     drawText ( canvas, index, x + 1, y, text );
  46. }
  47.  
  48. function drawStat ( canvas, index, x, y ) {
  49.    
  50.     drawSpriteText (
  51.         canvas,
  52.         HUD[index].sprite,
  53.         x,
  54.         y,
  55.         `${HUD[index].name}: ${player[HUD[index].name]}`
  56.     );
  57.    
  58.     console.log(`Draw Stat: ${HUD[index].name}: ${player[HUD[index].name]}`);
  59.  
  60. }
  61.  
  62.  
  63. function bufferReset ( canvas ) {
  64.  
  65.     let context = canvas.getContext (`2d`);
  66.    
  67.     bufferClear ( canvas );
  68.     bufferBlack ( canvas );
  69.    
  70.     debugCanvas ( canvas );
  71.  
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement