{ // ...
/**
* Инициирует непрерывную перерисовку контента. Для плавной анимации.
*/
permanentdraw: function () {
if (!!this._interval) return;
this._interval = setInterval(() => anima.draw(), 10);
},
/**
* останавливает анимацию
*/
clearpermanent: function () {
if (!this._interval) return;
clearInterval(this._interval);
this._interval = null;
},
/**
* отложенный draw - заявка на перерисовку. Можно частить, все равно не должно тормозить
*/
draw: function () {
if (!this._TO) {
let that = this;
this._TO = window.requestAnimationFrame(function () {
that._TO = false;
that._draw();
});
}
},
}
const container = new Container();
house.addChild(container);
const player = new AnimatedSprite(animation('player'));
container.addChild(player);
//Скорость воспроизведения анимации
player.animationSpeed = 0.17;
player.play();
player.anchor.set(0.5,1);
player.x = 0;
player.y = 0;
house.eventMode = 'static';
let purpose = [player.x,player.y];
const direction = [0,0];
house.on('pointerdown',(e:any) => {
const local = house.toLocal(e.global);
purpose = [Math.floor(local.x),Math.floor(local.y)];
direction[0] = (player.x < local.x)?1:-1;
direction[1] = (player.y < local.y)?1:-1;
});
//Скорость перемещение объекта (пиксель в секунду)
speed = 2.5;
app.ticker.add((delta) =>{
if(direction[0]>0){
if(player.x < purpose[0]){
player.x += speed;
}
}
if(direction[0]<0){
if(player.x > purpose[0]){
player.x -= speed;
}
}
if(direction[1]>0){
if(player.y < purpose[1]){
player.y += speed;
}
}
if(direction[1]<0){
if(player.y > purpose[1]){
player.y -= speed;
}
}
});