<! DOCTYPE html >
< html >
< head >
< title > Animation test </ title >
< meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" >
</ head >
< body >
< canvas id ="cnv" width ="600" height ="200" > It's not working! </ canvas >
< select id ="animations" name ="animations" onchange ="changeAnimation(this.value)" >
< option value ="stop" > Stop </ option >
< option value ="jump" > Jump </ option >
< option value ="bum" > Bum </ option >
< option value ="dead" > Dead </ option >
</ select >
</ body >
</ html >
* This source code was highlighted with Source Code Highlighter .
<! DOCTYPE html >
< html >
< head >
< title > Animation test </ title >
< meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" >
</ head >
< body >
< canvas id ="cnv" width ="600" height ="200" > It's not working! </ canvas >
< select id ="animations" name ="animations" onchange ="changeAnimation(this.value)" >
< option value ="stop" > Stop </ option >
< option value ="jump" > Jump </ option >
< option value ="bum" > Bum </ option >
< option value ="dead" > Dead </ option >
</ select >
</ body >
</ html >
* This source code was highlighted with Source Code Highlighter .
<! DOCTYPE html >
< html >
< head >
< title > Animation test </ title >
< meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" >
</ head >
< body >
< canvas id ="cnv" width ="600" height ="200" > It's not working! </ canvas >
< select id ="animations" name ="animations" onchange ="changeAnimation(this.value)" >
< option value ="stop" > Stop </ option >
< option value ="jump" > Jump </ option >
< option value ="bum" > Bum </ option >
< option value ="dead" > Dead </ option >
</ select >
</ body >
</ html >
* This source code was highlighted with Source Code Highlighter .
//
function $(id) {
return document .getElementById(id);
}
var tx = $( 'cnv' ).getContext( '2d' ); //
var childs = {}; //
var animate = {}; //
* This source code was highlighted with Source Code Highlighter .
//
function $(id) {
return document .getElementById(id);
}
var tx = $( 'cnv' ).getContext( '2d' ); //
var childs = {}; //
var animate = {}; //
* This source code was highlighted with Source Code Highlighter .
//
function $(id) {
return document .getElementById(id);
}
var tx = $( 'cnv' ).getContext( '2d' ); //
var childs = {}; //
var animate = {}; //
* This source code was highlighted with Source Code Highlighter .
function initAnimation() {
//
childs[ 'ball' ] = {
'at' : 'jump' , //
'w' : 30, //
'h' : 30, //
'fw' : 30, //
'x' : 100, //
'y' : 100 //
}
//
animate[ 'ball' ] = {
'jump' : { //
'el' : null , // Image
'src' : 'images/ball.png' , //
'step' : 0, //
'speed' : 3, //
'curr' : 0, //
'steps' : 3, // , 0
'onend' : null //
},
'bum' : {
'el' : null ,
'src' : 'images/ball_m.png' ,
'step' : 0,
'speed' : 3,
'curr' : 0,
'steps' : 7,
'onend' : 'onBumEnd'
},
'stop' : {
'el' : null ,
'src' : 'images/ball_s.png' ,
'step' : 0,
'speed' : 10,
'curr' : 0,
'steps' : 0,
'onend' : null
},
'dead' : {
'el' : null ,
'src' : 'images/ball_d.png' ,
'step' : 0,
'speed' : 10,
'curr' : 0,
'steps' : 0,
'onend' : null
}
}
//
for ( var o in childs) {
//
for ( var a in animate[o]) {
//
var img = new Image();
img.src = animate[o][a].src;
//
animate[o][a].el = img;
}
}
}
* This source code was highlighted with Source Code Highlighter .
function initAnimation() {
//
childs[ 'ball' ] = {
'at' : 'jump' , //
'w' : 30, //
'h' : 30, //
'fw' : 30, //
'x' : 100, //
'y' : 100 //
}
//
animate[ 'ball' ] = {
'jump' : { //
'el' : null , // Image
'src' : 'images/ball.png' , //
'step' : 0, //
'speed' : 3, //
'curr' : 0, //
'steps' : 3, // , 0
'onend' : null //
},
'bum' : {
'el' : null ,
'src' : 'images/ball_m.png' ,
'step' : 0,
'speed' : 3,
'curr' : 0,
'steps' : 7,
'onend' : 'onBumEnd'
},
'stop' : {
'el' : null ,
'src' : 'images/ball_s.png' ,
'step' : 0,
'speed' : 10,
'curr' : 0,
'steps' : 0,
'onend' : null
},
'dead' : {
'el' : null ,
'src' : 'images/ball_d.png' ,
'step' : 0,
'speed' : 10,
'curr' : 0,
'steps' : 0,
'onend' : null
}
}
//
for ( var o in childs) {
//
for ( var a in animate[o]) {
//
var img = new Image();
img.src = animate[o][a].src;
//
animate[o][a].el = img;
}
}
}
* This source code was highlighted with Source Code Highlighter .
function initAnimation() {
//
childs[ 'ball' ] = {
'at' : 'jump' , //
'w' : 30, //
'h' : 30, //
'fw' : 30, //
'x' : 100, //
'y' : 100 //
}
//
animate[ 'ball' ] = {
'jump' : { //
'el' : null , // Image
'src' : 'images/ball.png' , //
'step' : 0, //
'speed' : 3, //
'curr' : 0, //
'steps' : 3, // , 0
'onend' : null //
},
'bum' : {
'el' : null ,
'src' : 'images/ball_m.png' ,
'step' : 0,
'speed' : 3,
'curr' : 0,
'steps' : 7,
'onend' : 'onBumEnd'
},
'stop' : {
'el' : null ,
'src' : 'images/ball_s.png' ,
'step' : 0,
'speed' : 10,
'curr' : 0,
'steps' : 0,
'onend' : null
},
'dead' : {
'el' : null ,
'src' : 'images/ball_d.png' ,
'step' : 0,
'speed' : 10,
'curr' : 0,
'steps' : 0,
'onend' : null
}
}
//
for ( var o in childs) {
//
for ( var a in animate[o]) {
//
var img = new Image();
img.src = animate[o][a].src;
//
animate[o][a].el = img;
}
}
}
* This source code was highlighted with Source Code Highlighter .
function onBumEnd() {
//
childs[ 'ball' ].at = 'dead' ;
//
animate[ 'ball' ][childs[ 'ball' ].at].curr = 0;
}
* This source code was highlighted with Source Code Highlighter .
function onBumEnd() {
//
childs[ 'ball' ].at = 'dead' ;
//
animate[ 'ball' ][childs[ 'ball' ].at].curr = 0;
}
* This source code was highlighted with Source Code Highlighter .
function onBumEnd() {
//
childs[ 'ball' ].at = 'dead' ;
//
animate[ 'ball' ][childs[ 'ball' ].at].curr = 0;
}
* This source code was highlighted with Source Code Highlighter .
function changeAnimation(value) {
//
childs[ 'ball' ].at = value;
//
animate[ 'ball' ][childs[ 'ball' ].at].curr = 0;
}
* This source code was highlighted with Source Code Highlighter .
function changeAnimation(value) {
//
childs[ 'ball' ].at = value;
//
animate[ 'ball' ][childs[ 'ball' ].at].curr = 0;
}
* This source code was highlighted with Source Code Highlighter .
function changeAnimation(value) {
//
childs[ 'ball' ].at = value;
//
animate[ 'ball' ][childs[ 'ball' ].at].curr = 0;
}
* This source code was highlighted with Source Code Highlighter .
function startAnimation() {
//
setInterval( function () {
//
ctx.save();
ctx.fillStyle = '#FFFFFF' ;
ctx.fillRect(0, 0, 600, 200);
ctx.restore();
//
for ( var o in childs) {
//
if (animate[o]) {
//
var step = animate[o][childs[o].at].step;
//
ctx.drawImage(
animate[o][childs[o].at].el, // Image
Math.round(childs[o].fw * step), // , *
0, // , 0
childs[o].w, //
childs[o].h, //
childs[o].x, //
childs[o].y, //
childs[o].w, //
childs[o].h //
);
// speed,
if (animate[o][childs[o].at].curr >= animate[o][childs[o].at].speed) {
//,
if (animate[o][childs[o].at].step >= animate[o][childs[o].at].steps) {
animate[o][childs[o].at].step = 0;
// , ,
if (animate[o][childs[o].at].onend)
window[animate[o][childs[o].at].onend]();
}
else animate[o][childs[o].at].step++;
//
animate[o][childs[o].at].curr = 0;
}
//
animate[o][childs[o].at].curr++;
}
}
}, 1000/16);
}
* This source code was highlighted with Source Code Highlighter .
function startAnimation() {
//
setInterval( function () {
//
ctx.save();
ctx.fillStyle = '#FFFFFF' ;
ctx.fillRect(0, 0, 600, 200);
ctx.restore();
//
for ( var o in childs) {
//
if (animate[o]) {
//
var step = animate[o][childs[o].at].step;
//
ctx.drawImage(
animate[o][childs[o].at].el, // Image
Math.round(childs[o].fw * step), // , *
0, // , 0
childs[o].w, //
childs[o].h, //
childs[o].x, //
childs[o].y, //
childs[o].w, //
childs[o].h //
);
// speed,
if (animate[o][childs[o].at].curr >= animate[o][childs[o].at].speed) {
//,
if (animate[o][childs[o].at].step >= animate[o][childs[o].at].steps) {
animate[o][childs[o].at].step = 0;
// , ,
if (animate[o][childs[o].at].onend)
window[animate[o][childs[o].at].onend]();
}
else animate[o][childs[o].at].step++;
//
animate[o][childs[o].at].curr = 0;
}
//
animate[o][childs[o].at].curr++;
}
}
}, 1000/16);
}
* This source code was highlighted with Source Code Highlighter .
function startAnimation() {
//
setInterval( function () {
//
ctx.save();
ctx.fillStyle = '#FFFFFF' ;
ctx.fillRect(0, 0, 600, 200);
ctx.restore();
//
for ( var o in childs) {
//
if (animate[o]) {
//
var step = animate[o][childs[o].at].step;
//
ctx.drawImage(
animate[o][childs[o].at].el, // Image
Math.round(childs[o].fw * step), // , *
0, // , 0
childs[o].w, //
childs[o].h, //
childs[o].x, //
childs[o].y, //
childs[o].w, //
childs[o].h //
);
// speed,
if (animate[o][childs[o].at].curr >= animate[o][childs[o].at].speed) {
//,
if (animate[o][childs[o].at].step >= animate[o][childs[o].at].steps) {
animate[o][childs[o].at].step = 0;
// , ,
if (animate[o][childs[o].at].onend)
window[animate[o][childs[o].at].onend]();
}
else animate[o][childs[o].at].step++;
//
animate[o][childs[o].at].curr = 0;
}
//
animate[o][childs[o].at].curr++;
}
}
}, 1000/16);
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/119585/