mirror of
https://github.com/cmclark00/tetris-3d.git
synced 2025-05-17 23:25:21 +01:00
Fix issue with blocks not displaying on PC
This commit is contained in:
parent
2b7c5175a0
commit
a6ceb3c9be
1 changed files with 12 additions and 10 deletions
22
script.js
22
script.js
|
@ -2,7 +2,7 @@
|
||||||
let lastTimestamp = 0;
|
let lastTimestamp = 0;
|
||||||
const FPS_LIMIT = 60; // Default FPS limit
|
const FPS_LIMIT = 60; // Default FPS limit
|
||||||
const MOBILE_FPS_LIMIT = 30; // Lower FPS on mobile
|
const MOBILE_FPS_LIMIT = 30; // Lower FPS on mobile
|
||||||
const FRAME_MIN_TIME = (1000 / FPS_LIMIT);
|
let FRAME_MIN_TIME = (1000 / FPS_LIMIT); // Changed from const to let so it can be modified
|
||||||
let isReducedEffects = false; // For mobile performance
|
let isReducedEffects = false; // For mobile performance
|
||||||
let maxFireworks = 30; // Default limit
|
let maxFireworks = 30; // Default limit
|
||||||
let maxParticlesPerFirework = 30; // Default limit
|
let maxParticlesPerFirework = 30; // Default limit
|
||||||
|
@ -1647,15 +1647,14 @@ function draw() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip frames to maintain target FPS
|
// Skip frames to maintain target FPS
|
||||||
const frameTime = isMobile ? (1000 / MOBILE_FPS_LIMIT) : FRAME_MIN_TIME;
|
if (elapsed < FRAME_MIN_TIME) {
|
||||||
if (elapsed < frameTime) {
|
|
||||||
requestAnimationFrame(draw);
|
requestAnimationFrame(draw);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTimestamp = now - (elapsed % frameTime);
|
lastTimestamp = now - (elapsed % FRAME_MIN_TIME);
|
||||||
|
|
||||||
// Only clear what's needed
|
// Clear canvas
|
||||||
ctx.fillStyle = EMPTY;
|
ctx.fillStyle = EMPTY;
|
||||||
ctx.fillRect(0, 0, COLS * BLOCK_SIZE, ROWS * BLOCK_SIZE);
|
ctx.fillRect(0, 0, COLS * BLOCK_SIZE, ROWS * BLOCK_SIZE);
|
||||||
|
|
||||||
|
@ -1667,9 +1666,10 @@ function draw() {
|
||||||
p.draw();
|
p.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
// On mobile, render fireworks less frequently
|
// Fireworks - limit on mobile
|
||||||
if (!isMobile || frameCounter % 2 === 0) {
|
const shouldDrawFireworks = !isMobile || frameCounter % 2 === 0;
|
||||||
// Draw fireworks (with clipping for performance)
|
if (shouldDrawFireworks) {
|
||||||
|
// Draw fireworks with clipping for performance
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.rect(0, 0, canvas.width, canvas.height);
|
ctx.rect(0, 0, canvas.width, canvas.height);
|
||||||
|
@ -2002,8 +2002,10 @@ window.onload = function() {
|
||||||
// Initialize the game
|
// Initialize the game
|
||||||
init();
|
init();
|
||||||
|
|
||||||
// Apply mobile optimizations
|
// Apply mobile optimizations only for mobile devices
|
||||||
optimizeForMobile();
|
if (isMobile) {
|
||||||
|
optimizeForMobile();
|
||||||
|
}
|
||||||
|
|
||||||
// Start animation loops
|
// Start animation loops
|
||||||
update(); // Start the fireworks update loop
|
update(); // Start the fireworks update loop
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue