Слайд 1СОЗДАНИЕ HTML ИГР НА ЭЛЕМЕНТЕ CANVAS
Слайд 2ПРИЕМУЩЕСТВА HTML5 ПЕРЕД FLASH
Открытость платформы
Чистая веб-технология
Более высокие надёжность, производительность и безопасность
Более
низкое энергопотребление
Поддержка управления, с помощью сенсорных экранов
Слайд 5ОБЪЯВЛЕНИЕ ЭЛЕМЕНТА
Для объявления используется тег
Your browser doesn’t support canvas
element
canvas = document.getElementById('canvas');
if (canvas.getContext)
{ //Canvas поддерживается
}
else
{ //Canvas не поддерживается
}
Слайд 6СОЗДАНИЕ ПРИМИТИВОВ
beginPath()
moveTo(x, y)
lineTo(x, y)
stroke()
var canvas = document.getElementById(canvas);
var context = canvas.getContext(‘2d’);
context.beginPath();
context.moveTo(10, 20);
context.lineTo(20,
30);
context.stroke();
Слайд 7РАБОТА С КРИВЫМИ
quadricCurveTo(cpx, cpy, x, y)
bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y)
arcTo(x1,
y1, x2, y2, radius)
Слайд 8СТИЛИЗАЦИЯ ЛИНИЙ
lineWidth
lineJoin
strokeStyle
Слайд 9РАБОТА С ЦВЕТОМ
fillStyle
fillRect(x, y, width, height)
clearRect(x, y, width, height)
Слайд 10РАБОТА С ГОТОВЫМ ИЗОБРАЖЕНИЕМ
drawImage(image, x, y, width, height)
var image = new
Image();
image.src = ‘image.jpg’;
image.onload = function()
{
drawImage(image, 5, 10, 100, 100);
}
Слайд 11ГРАДИЕНТ
createLinearGradient(x0, x1, y0, y1)
addColorStop(gradientPart, color)
createRadialGradient(x0, y0, r0, x1, y1, r1);
var gradient
= createLinearGradient(0, 0, 100, 1000);
gradient.addColorStop(0, rgb(255, 0, 0));
gradient.addColorStop(0.5. rgb(0, 255, 0));
gradient.addColorStop(1 rgb(0, 0, 255));
context.fillStyle = gradient;
context.fillRect = (0, 0, 100, 100);
Слайд 12ИЗОБРАЖЕНИЯ - ШАБЛОНЫ
createPattern(Image, repeat)
repeat
repeat-x
repeat-y
norepeat
var image = new Image();
image.src = ‘image.jpg’;
Image.onload =
new function()
{
context.strokeStyle = context.createPattern(image, ‘repeat’);
Слайд 13ОСНОВНЫЕ ГРАФИЧЕСКИЕ ПРЕОБРАЗОВАНИЯ
translate(x, y)
scale(x, y)
rotate(cornerRadian)
save()
restore()
Слайд 14РАБОТА С ТЕКСТОМ
textAlign
font
textBaseLine
strokeText(text, x, y, maxWidth)
fillText(text, x, y, maxWidth)
context.textAlign = ‘center’;
context.font
= ‘Arial’;
context.strokeText(“Hello world!”, 0, 0, 300);
Слайд 15РАБОТА С ТЕНЬЮ
shadowColor
shadowOffsetX
shadowOffsetY
shadowBlur
Слайд 16РАБОТА С ПИКСЕЛЯМИ ИЗОБРАЖЕНИЯ
getImageData(x, y, width, height)
width
height
data
R = ((width * y)
+ x) * 4
G = (((width * y) + x) * 4) + 1
B = (((width * y) + x) * 4) + 2
Alpha = (((width * y) + x) * 4) + 3
putImageData(imageData, dx, dy)