setScaleCenter() 在缩小 Sprite 时导致问题 - AndEngine
我正在某个位置制作一个精灵,我想将其缩小。这是我正在使用的代码:
sp_nest_r4 = new Sprite(460f, 720f, txRg_nest_maroon);
sp_nest_r4.setScaleCenter(sp_nest_r4.getX(), sp_nest_r4.getY());
sp_nest_r4.setScale(0.454545f);
bdy_nest_r4 = PhysicsFactory.createCircleBody(mPhysicsWorld, sp_nest_r4, BodyType.StaticBody, fxd_spring);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(sp_nest_r4, bdy_nest_r4, true, true));
sp_nest_r4.setUserData(bdy_nest_r4);
mScene.attachChild(sp_nest_r4);
现在的问题是,当我设置比例中心时,精灵不显示并消失。但是,如果我删除行 sp_nest_r4.setScaleCenter(sp_nest_r4.getX(), sp_nest_r4.getY());
,精灵就会显示出来,但它的位置会稍微向右移动&低于原来指定的位置。
我无法弄清楚这种行为,如果我放大精灵也会出现同样的情况。
I am making a sprite at a certain location and I want to scale it down. Here is the code that I am using:
sp_nest_r4 = new Sprite(460f, 720f, txRg_nest_maroon);
sp_nest_r4.setScaleCenter(sp_nest_r4.getX(), sp_nest_r4.getY());
sp_nest_r4.setScale(0.454545f);
bdy_nest_r4 = PhysicsFactory.createCircleBody(mPhysicsWorld, sp_nest_r4, BodyType.StaticBody, fxd_spring);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(sp_nest_r4, bdy_nest_r4, true, true));
sp_nest_r4.setUserData(bdy_nest_r4);
mScene.attachChild(sp_nest_r4);
Now the problem is that when I set the scale center, the sprite doesn't show and gets disappeared. But if I remove the line sp_nest_r4.setScaleCenter(sp_nest_r4.getX(), sp_nest_r4.getY());
, the sprite shows up, but its position is slightly shifted towards right & downwards than the original specified position.
I can't figure out this behavior, same is the case if I scale up the sprite.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在尝试使用场景坐标而不是本地坐标。
如果我没记错的话,您应该在 setScaleFunction 的情况下提供本地坐标,尝试执行以下操作:
It looks like you are trying to use scene coordinates instead of local coordinates.
If I remember correctly, you should provide local coordinates in case of setScaleFunction, try to do like following: