Any likenesses to the following athletes in the last slide are purely conincidental.
sweet pixel art by @owenshifflett
<canvas></canvas>
var canvas = new document.createElement('canvas');
var ctx = canvas.getContext('2d');
var image = document.createElement('image');
image.src = ('runner.png');
ctx.drawImage(image, x, y);
You can draw:
<img>
elements<canvas>
elements<video>
elements
ctx.drawImage(
image, // source image (spritesheet)
source.x, // source x (x location within a spritesheet)
source.y, // source y (y location within a spritesheet)
width, // source width
height, // source height
x, // destination x
y, // destination y
width, // destination width (must match source width)
height // destination height (must match source width)
);
Clip with drawImage and move the source image.
Make each sprite a canvas object and draw to it.
var spriteCanvas = document.createElement('canvas');
spriteCanvas.width = 50;
spriteCanvas.height = 50;
spriteCtx = spriteCanvas.getContext('2d');
// Animate x and y position of the source image
spriteCtx.drawImage(image, x, y);
The maximum size for decoded GIF, PNG, and TIFF images is 3 megapixels for devices with less than 256 MB RAM and 5 megapixels for devices with greater or equal than 256 MB RAM.
—developer.apple.com
ctx.fillStyle = "red";
ctx.beginPath();
ctx.moveTo(30, 30);
ctx.lineTo(150, 150);
ctx.bezierCurveTo(60, 70, 60, 70, 70, 150);
ctx.lineTo(30, 30);
ctx.fill();
See the Pen spzwq by greypants (@greypants) on CodePen
var loop = {
clearCanvas();
updateObjects();
render();
requestAnimationFrame(loop);
};
setDelta: function() {
frames.now = Date.now();
frames.delta = (frames.now - frames.then) / 1000;
frames.then = frames.now;
}
var velocity = bullet.speed * frames.delta;
bullet.x = bullet.x - velocity;
isCollision: function(a, b) {
return a.x <= (b.x + b.width) &&
b.x <= (a.x + a.width) &&
a.y <= (b.y + b.height) &&
b.y <= (a.y + a.height);
}
PUMA.eightBit.debug = true;
var audio = document.createElement('audio');
audio.src = 'audio/pew.ogg';
audio.play();