setScaleCenter() 在缩小 Sprite 时导致问题 - AndEngine

发布于 2024-12-21 10:57:47 字数 689 浏览 7 评论 0原文

我正在某个位置制作一个精灵,我想将其缩小。这是我正在使用的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小梨窩很甜 2024-12-28 10:57:47

看起来您正在尝试使用场景坐标而不是本地坐标。
如果我没记错的话,您应该在 setScaleFunction 的情况下提供本地坐标,尝试执行以下操作:

sp_nest_r4.setScaleCenter(0,0); //upper left corner of sprite

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:

sp_nest_r4.setScaleCenter(0,0); //upper left corner of sprite
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文