Arts >> Umenie a zábava >  >> Filmy a TV >> Reality TV

SpongeBob Picture Day Disaster: Code snippet (JavaScript/Canvas) – Študentské cvičenie, nie herný kód

Ide o študentské kódovacie cvičenie (nie oficiálny herný kód). Vyčistená verzia:

// SpongeBob mouth animation loop const canvas = document.getElementById('game'); const ctx = canvas.getContext('2d'); const sprites = { closed: new Image(), open: new Image() }; sprites.closed.src = 'spongebob.png'; sprites.open.src = 'spongebobOpenMouth.png'; let current = 'closed'; let frame = 0; function animate() { frame++; if (frame % 10 === 0) { current = current === 'closed' ? 'open' : 'closed'; } ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(sprites[current], canvas.width/3*2, canvas.height/2); requestAnimationFrame(animate); } sprites.closed.onload = animate; 

Spustite v prehliadači s canvas id="game". Nie cheat kód – len sprite-flip demo.

Reality TV

Related Categories