我在Phaser中使用一些我想在实际游戏中缩小的大图像进行游戏:
create() { //Create the sprite group and scale it down to 30% this.pieces = this.add.group(undefined,"pieces",true); this.pieces.scale.x = 0.3; this.pieces.scale.y = 0.3; //Add the players to the middle of the stage and add them to the 'pieces' group var middle = new Phaser.Point( game.stage.width/2,game.stage.height/2); var player_two = this.add.sprite(middle.x - 50,middle.y,'image1',undefined,this.pieces); var player_one = this.add.sprite(middle.x,middle.y-50,'image2',this.pieces); }
但是,由于精灵尺寸的缩小,它们的起始位置也被缩放,所以相反出现在舞台的中间,它们只显示到中间距离的30%.
如何缩小精灵图片而不影响他们的位置?
(代码是附带的在Typescript,但我认为这个特定的样本也是javascript,所以这可能是无关紧要)
解决方法
将Sprite.anchor设置为0.5,因此物理身体以Sprite为中心,缩放精灵图像,而不会影响其位置.
this.image.anchor.setTo(0.5,0.5);
原文地址:https://www.jb51.cc/js/152160.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。