Phaser 3:改变精灵相对于高度的宽度
我希望能够更改精灵的高度以适应菜单,但是当我使用 sprite.displayHeight = menu.height
更改高度时,它的宽度不会随之缩放它会被拉伸/压扁。
有没有办法相对于高度缩放宽度,以保持精灵的原始比例?
I'd like to be able to change the height of my sprite to fit into a menu, however when I change the height with sprite.displayHeight = menu.height
, it's width won't scale along and it will be stretched/squashed.
Is there a way to scale the width relative to the height, to keep the sprite's original ratio?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道任何特殊函数可以开箱即用,但是您只需额外一行代码即可实现此目的. 无需额外计算。
(这也适用于
displayHeight
)img.displayWidth = 100;
displayWidth
来设置的):img.scaleY = img.scaleX;
这里是一个工作演示:
I don't know any special function, that does this out-of-the-box, BUT you can achieve this, with only one extra line of code. No extra calculation needed.
(this works also with the
displayHeight
)img.displayWidth = 100;
displayWidth
):img.scaleY = img.scaleX;
Here a working demo: