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;
}
}
});
await ymaps3.ready;
const {YMap,YMapDefaultSchemeLayer,YMapDefaultFeaturesLayer,YMapControls,YMapMarker,YMapListener,YMapFeature} = ymaps3;
const {YMapZoomControl,YMapGeolocationControl} = await ymaps3.import('@yandex/ymaps3-controls@0.0.1');
const {YMapDefaultMarker} = await ymaps3.import('@yandex/ymaps3-markers@0.0.1');
const MAP = new YMap(document.getElementById('map'),{
location: {
center: center,
zoom: zoom
}
});
let ROUTE_LINE = new YMapFeature({
geometry:{
type: 'LineString',
coordinates: []
}, style: {
stroke: [{
color: opMapROUTING.line.color,
width: 6,
opacity: 0.8
}]
}
});
MAP.addChild(ROUTE_LINE);
fetch(atumquiz.arrayToUrlParams('https://api.routing.yandex.net/v2/route',{
apikey: opMapROUTING.apikey,
waypoints:`${latLon}|${latLon}`,
mode: 'truck'
}), {
headers: {
'Accept': 'application/json'
}
}).then(response => {
return response.json();
}).then(routes => {
if(routes.errors){
ROUTE_LINE.update({geometry:{type: "LineString", coordinates: []}});
console.error(routes.errors[0]);
}else{
if(routes.route.legs[0].status = "OK"){
let LINE_latlngs = [];
routes.route.legs.forEach(leg => {
leg.steps.forEach(step => {
step.polyline.points.forEach(point => {
LINE_latlngs.push([point[1],point[0]]);
});
});
});
ROUTE_LINE.update({geometry:{type: "LineString", coordinates: LINE_latlngs}});
}else{
ROUTE_LINE.update({geometry:{type: "LineString", coordinates: []}});
console.error(`Route not found`);
}
}
});
Нашёл решение: