本文整理汇总了TypeScript中@angular/core.ElementRef.getContext方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ElementRef.getContext方法的具体用法?TypeScript ElementRef.getContext怎么用?TypeScript ElementRef.getContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/core.ElementRef
的用法示例。
在下文中一共展示了ElementRef.getContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: animateStance
animateStance(playerClass){
/* Set up canvas variables */
var canvas = this.canvas.nativeElement;
var character,characterImage;
function gameLoop(){
window.requestAnimationFrame(gameLoop);
character.update();
character.render();
}
switch(playerClass){
case("Elementalist"):
// Get canvas
canvas.width = 125;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: 331,
height: 162,
image: characterImage,
numberOfFrames: 3,
ticksPerFrame: 4,
loop: true
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-2/piccolo/piccolo-standing.png";
break;
case("Highwayman"):
// Get canvas
canvas.width = 99;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: 300,
height: 162,
image: characterImage,
numberOfFrames: 3,
ticksPerFrame: 5,
loop: true
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-2/trunks/trunks-standing.png";
break;
case("Paragon"):
// Get canvas
canvas.width = 125;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: 373,
height: 162,
image: characterImage,
numberOfFrames: 4,
ticksPerFrame: 4,
loop: true
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-2/gohan/gohan-standing.png";
break;
}
}
示例2: animate
animate(playerClass,playerAction){
/* Set up canvas variables */
var canvas = this.canvas.nativeElement;
var character,characterImage;
function gameLoop(){
window.requestAnimationFrame(gameLoop);
character.update();
character.render();
}
/* Animate based on player and action */
switch(playerClass){
// elementalist : piccolo
case ("Elementalist"):
switch(playerAction){
case("strike"):
// Get canvas
canvas.width = 150;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: 450,
height: 162,
image: characterImage,
numberOfFrames: 3,
ticksPerFrame: 4
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-2/piccolo/piccolo-punch.png";
break;
case("special"):
// Get canvas
canvas.width = 190;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: 380,
height: 162,
image: characterImage,
numberOfFrames: 2,
ticksPerFrame: 20
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-2/piccolo/piccolo-magic.png";
break;
case("defend"):
// Get canvas
canvas.width = 120;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: 240,
height: 162,
image: characterImage,
numberOfFrames: 2,
ticksPerFrame: 20
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-2/piccolo/piccolo-defend.png";
break;
default:
this.animateStance(playerClass);
}
break;
// highwayman : trunks
case ("Highwayman"):
switch(playerAction){
case("strike"):
// Get canvas
canvas.width = 185;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: 556,
height: 162,
image: characterImage,
numberOfFrames: 3,
ticksPerFrame: 8
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-2/trunks/trunks-punch.png";
break;
case("special"):
// Get canvas
canvas.width = 190;
//.........这里部分代码省略.........
示例3: animateDefeat
animateDefeat(playerClass){
/* Set up canvas variables */
var canvas = this.canvas.nativeElement;
var character,characterImage;
function gameLoop(){
window.requestAnimationFrame(gameLoop);
character.update();
character.render();
}
switch(playerClass){
case("Elementalist"):
// Get canvas
canvas.width = 162;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: canvas.width,
height: canvas.height,
image: characterImage,
numberOfFrames: 1,
ticksPerFrame: 10
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-1/piccolo/piccolo-defeat.png";
break;
case("Highwayman"):
// Get canvas
canvas.width = 177;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: canvas.width,
height: canvas.height,
image: characterImage,
numberOfFrames: 1,
ticksPerFrame: 10
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-1/trunks/trunks-defeat.png";
break;
case("Paragon"):
// Get canvas
canvas.width = 162;
canvas.height = 162;
// Create sprite sheet
characterImage = new Image();
// Create sprite
character = this.sprite({
context: canvas.getContext("2d"),
width: canvas.width,
height: canvas.height,
image: characterImage,
numberOfFrames: 1,
ticksPerFrame: 10
});
// Load sprite sheet
characterImage.addEventListener("load", gameLoop);
characterImage.src = "images/sprites/player-1/gohan/gohan-defeat.png";
break;
}
}