Pixi.js: 特定对象的中心舞台

创建于 2016-03-31  ·  3评论  ·  资料来源: pixijs/pixi.js

在制作 2D 游戏的过程中,通常要求视图以代表玩家的任何东西为中心。 在这一点上,除了手动偏移所有精灵的所有坐标之外,我不知道如何做到这一点。

如何正确移动舞台以使玩家始终位于画布视图的中心?

最有用的评论

我使用标准位置/比例/枢轴组合。

//(0,0) for us is center of the screen
stage.position.x = renderer.width/2;
stage.position.y = renderer.height/2;
//scale it
stage.scale.x = 2.0;
stage.scale.y = 2.0;
//now specify which point INSIDE stage must be (0,0)
stage.pivot.x = character.position.x;
stage.pivot.y = character.position.y;

在我的开发版本中,有一个秘密的 Camera 对象,即使它在某些容器内,也可以让它跟随任何对象。

所有3条评论

我使用标准位置/比例/枢轴组合。

//(0,0) for us is center of the screen
stage.position.x = renderer.width/2;
stage.position.y = renderer.height/2;
//scale it
stage.scale.x = 2.0;
stage.scale.y = 2.0;
//now specify which point INSIDE stage must be (0,0)
stage.pivot.x = character.position.x;
stage.pivot.y = character.position.y;

在我的开发版本中,有一个秘密的 Camera 对象,即使它在某些容器内,也可以让它跟随任何对象。

非常感谢,它完美地工作! :)

它还回答了我需要但甚至没有问的另一个问题 - 如何缩放舞台。

由于关闭后没有任何近期活动,因此该线程已自动锁定。 请为相关错误打开一个新问题。

此页面是否有帮助?
0 / 5 - 0 等级