Khawar
Khawar

Reputation: 5227

setScaleCenter() causing issue while scaling down a Sprite - AndEngine

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.

Upvotes: 2

Views: 1479

Answers (1)

cr_az
cr_az

Reputation: 453

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

Upvotes: 4

Related Questions