我遇到一个问题,如何让物体A跟随物体B呢
大家好啊
5 days later
It depends on which particular effect you want.
If you want instant snapping, you can do something like this:
var hero = templates.list['Hero'][0];
if (templates.isValid(hero)) {
this.x = hero.x + 32; // move to hero by X and shift to right by 32 pixels
this.y = hero.y - 64; // same for Y, move a bit higher
}
Or you can make a copy gradually move towards another copy:
var hero = templates.list['Hero'][0];
if (templates.isValid(hero)) {
// calculates direction from our position to hero's
this.direction = u.pointDirection(this.x, this.y, hero.x, hero.y);
this.move(); // movement method of your choice.
}