Я пытаюсь моргнуть по кругу, используя машинописный текст, где мой код для мерцания написан в геометрии. js и мой requestAnimationFrame написан в app.ts Я пытаюсь переместить круг по горизонтали одновременно, я ' Я могу изменить цвет, но это быстро повесить цвет от желтого до зеленого, трудно сказать, что я делаю неправильно?
app.ts
var scene:Geometry.Scene = new Geometry.Scene(canvas);
var shape:string = "circle";
var temp :Geometry.Circle;
var rtpt = new Geometry.Point(750,500);
var ltpt = new Geometry.Point(50,500);
function mouseClick(e:MouseEvent){
let p1 = new Geometry.Point(e.clientX,e.clientY);
console.log(shape)
if(shape == "circle"){
//checking which shape to be drawn
let vx = random(1,5);
temp = new Geometry.Circle(p1,25,rtpt,ltpt,vx,context);
//pushing it to the shape arr
scene.add(temp);
}else{
if(shape == "move")
if(scene.checkInside(p1)){
if(!isanim){
anim();
}
}
}
}
function anim(){
isanim = true;
if(isanim){
window.requestAnimationFrame(anim);
scene.draw();
}
}
код для изменения центр круга и цветовая геометрия. js
draw(){
this.context.beginPath();
this.context.arc(this._centpt.x,this._centpt.y,this._radius,0, 2 * Math.PI,false);
this.context.fillStyle = this.color;
this.context.fill();
this.context.stroke();
if(this.move){
this.tofro();
}
}
private tofro(){
if(this.motion == "forward"){
this._centpt.x += this._vx;
}
else{
this._centpt.x -= this._vx;
}
this.tofroCheck();
}
private tofroCheck(){
if(this.color == "yellow"){
this.color = "green"
}else{
this.color = "yellow";
}
if(this._centpt.x > this._rigthPt.x){
this.motion = "backward"
}else if(this._centpt.x < this._leftPt.x){
this.motion = "forward";
}
console.log(this._centpt.x + " " + this.motion);
}