Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to add background to kaboom js

async function init() {
  kaboom();
  let bgImage = await loadSprite("background", "https://www.paulwheeler.us/files/windows-95-desktop-background.jpg");

  let background = add([
    sprite("background"),
    // Make the background centered on the screen
    pos(width() / 2, height() / 2),
    origin("center"),
    // Allow the background to be scaled
    scale(1),
    // Keep the background position fixed even when the camera moves
    fixed()
  ]);
  // Scale the background to cover the screen
  background.scaleTo(Math.max(
    width() / bgImage.tex.width,
    height() / bgImage.tex.height
  ));
}

init();
Comment

PREVIOUS NEXT
Code Example
Javascript :: Replacing String Content 
Javascript :: discord.js v13 joinVoiceChannel 
Javascript :: hash url owl carousel example 
Javascript :: return js 
Javascript :: spread operator react 
Javascript :: return jsx in for loop 
Javascript :: convert string to regular expression js 
Javascript :: angular javascript 
Javascript :: javascript and json 
Javascript :: reverseString / Palindrome / Split string / Reverse Array 
Javascript :: hash_hmac javascript 
Javascript :: options not working properly in reactjs 
Javascript :: js user add names to a list on screen 
Javascript :: reverse method in javascript 
Javascript :: ValueError: dictionary update sequence element #0 has length 1; 2 is required 
Javascript :: curved lines on google maps usint react 
Javascript :: send object from laravel to react js component 
Javascript :: calculate 7 days in javascript countdown 
Javascript :: invert linked list js 
Javascript :: order by type 
Javascript :: map array with only lenghth given 
Javascript :: javascript code to test if screen is idle 
Javascript :: javascript download file 
Javascript :: how to clear all slash commands 
Javascript :: does kendo window content clear on close 
Javascript :: exit node 
Javascript :: Turn array items to matrix javascript 
Javascript :: clear input fild 
Javascript :: mongoose encrypt database using mongoose encryption package 
Javascript :: How to have hotjar in react-hotjar 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =