Mấy bác ơi em đang làm game trên Angular 6
Cho em hỏi có cách nào get được Dom Element(element canvas) ở trong file component.ts không ạ.
Em cảm ơn.
code đoạn khai báo biết get element đây ạ:
export class AppComponent {
winner: number;
paddleMoveSpeed: any;
paddlesSpeedRange: any;
players = [prompt('Type the name of player 1:', 'Player 1').toLocaleUpperCase(),
prompt('Type the name of player 2', 'Player 2').toLocaleUpperCase()
];
colors = ['#364f4c',
'#59fdf4',
'#3f9d74',
'#69877d',
'#de8925',
'#e4b069',
'#40d4bb',
'#bebbda',
'#ea0a57',
'#6859c3'
];
fps = 60; // Max FPS (frames per second)
particlesCount = 20; // Number of sparks when ball strikes the paddle
flag = 0; // Flag variable which is changed on collision
particlePos = {
x: 0,
y: 0
}; // Object to contain the position of collision
multiplier = 1; // Varialbe to control the direction of sparks
startBtn = new StartBtn(); // Start button object
restartBtn = new RestartBtn(); // Restart button object
over = 0; // flag varialbe, cahnged when the game is over
init; // variable to initialize animation
paddleHit;
mouse = {
x: 0,
y: 0
}; // Mouse object to store it's current position
particles = []; // Array containing particles
canvas = <HTMLCanvasElement> document.getElementById('canvas');
ctx = this.canvas.getContext('2d');
points = 0;
// Initialise the collision sound
collision = <HTMLAudioElement> document.getElementById('collide');
paddles: Paddle[];
playerScores = [0, 0];
ball = new Ball(); // Ball object