mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-26 04:07:24 +00:00
Rename canvas element id to avoid collisions
This commit is contained in:
11
birb.js
11
birb.js
@@ -38,7 +38,7 @@ const HOP_DISTANCE = settings.hopDistance;
|
|||||||
const AFK_TIME = 1000 * 20;
|
const AFK_TIME = 1000 * 20;
|
||||||
|
|
||||||
const styles = `
|
const styles = `
|
||||||
canvas {
|
#birb {
|
||||||
image-rendering: pixelated;
|
image-rendering: pixelated;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
@@ -261,6 +261,7 @@ if (window === window.top) {
|
|||||||
document.head.appendChild(styleElement);
|
document.head.appendChild(styleElement);
|
||||||
|
|
||||||
// Insert a canvas element into the body with the same dimensions as the 2D array
|
// Insert a canvas element into the body with the same dimensions as the 2D array
|
||||||
|
canvas.id = "birb";
|
||||||
canvas.width = sharedFrames.base.pixels[0].length * CANVAS_PIXEL_SIZE;
|
canvas.width = sharedFrames.base.pixels[0].length * CANVAS_PIXEL_SIZE;
|
||||||
canvas.height = sharedFrames.base.pixels.length * CANVAS_PIXEL_SIZE;
|
canvas.height = sharedFrames.base.pixels.length * CANVAS_PIXEL_SIZE;
|
||||||
document.body.appendChild(canvas);
|
document.body.appendChild(canvas);
|
||||||
@@ -332,9 +333,11 @@ document.addEventListener("click", (e) => {
|
|||||||
|
|
||||||
setInterval(update, 1000 / 60);
|
setInterval(update, 1000 / 60);
|
||||||
|
|
||||||
function draw() {
|
function requestDraw() {
|
||||||
requestAnimationFrame(draw);
|
requestAnimationFrame(requestDraw);
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
// Update the bird's position
|
// Update the bird's position
|
||||||
if (currentState === States.IDLE) {
|
if (currentState === States.IDLE) {
|
||||||
if (focusedElement !== null) {
|
if (focusedElement !== null) {
|
||||||
@@ -371,7 +374,7 @@ function draw() {
|
|||||||
setY(birdY);
|
setY(birdY);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw();
|
requestDraw();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} start
|
* @param {number} start
|
||||||
|
|||||||
Reference in New Issue
Block a user