这是一个游戏世界。在游戏世界里,有一个小圈子。我如何才能在周长周围添加一个精灵圆,使其不超出该圆。
发布于 2018-03-17 18:16:46
如果我没记错的话,你的问题是关于如何计算圆的坐标的更一般的问题。
通常你可以使用sine和cosine来计算圆的位置,在JavaScript和Phaser中,你可以这样做:
addSpritesInCircle: function(xpivot, ypivot, radius, amount) {
// add sprites in a circle
for (var i = 0; i < amount; i++) {
// divide sprites evenly around the circle
var angle = 360.0 * (i / amount);
// calculate circle coordinates
var xpos = xpivot + (Math.cos(2 * Math.PI * angle / 360.0) * radius);
var ypos = ypivot + (Math.sin(2 * Math.PI * angle / 360.0) * radius);
// add phaser sprite
var sprite = this.game.add.sprite(xpos, ypos, 'mysprites', 'alienfoe1');
// optionally also add to a group for handling/updates later
this.myAliensGroup.add(sprite);
};
}https://stackoverflow.com/questions/49306101
复制相似问题