Games set scale to body

mzsoft

Member
hi.
i need to change body scale.
in basketball game when throw ball i need to reduce scale for make ball smaller.
how can i set scale or change ball size.?
thanks
 

ilan

Expert
Licensed User
Longtime User
xui2d physic engine is based on box2d and in box2d you cannot easily scale the physic body.
in your case it is a circle so you can change the radius of the body by getting the B2Shape of the body and change the radius.

but just a question why do you want to change the body? if you want to get the effect of a ball shrinking like when you throw it than you can change just the sprite.
but again it depends on the game effect you want to get.

bottom line, no simple solution because of box2d limitation (if you would have a polyline it would be very hard to do that) but it is possible as explained above.

ps: such a task is super simple in iSpritekit (this is why i love Spritekit 😁)
 
Last edited:

mzsoft

Member
xui2d physic engine is based on box2d and in box2d you cannot easily scale the physic body.
in your case it is a circle so you can change the radius of the body by getting the B2Shape of the body and change the radius.

but just a question why do you want to change the body? if you want to get the effect of a ball shrinking like when you throw it than you can change just the sprite.
but again it depends on the game effect you want to get.

bottom line, no simple solution because of box2d limitation (if you would have a polyline it would be very hard to do that) but it is possible as explained above.

ps: such a task is super simple in iSpritekit (this is why i love Spritekit 😁)
can LIBGDX change scale easily?

so use libgdx?
 

jhonsonjordan

New Member
The physic engine in xui2d is built on box2d, and you can't simply scale the physic body in box2d.
Because the body is a circle in your example, you can adjust the radius by retrieving the B2Shape of the body and changing the radius.


But I'm curious as to why you desire to transform your physique. If you want to simulate the effect of a ball decreasing as you toss it, simply alter the sprite.

However, it is dependent on the game impact you desire.



Bottom line, there is no simple answer due to the box2d constraint (it would be really difficult if you had a polyline), however it is doable as mentioned above.
 

jhonsonjordan

New Member
The physic engine in xui2d is built on box2d, and you can't simply scale the physic body in box2d.
Because the body is a circle in your example, you can adjust the radius view by retrieving the B2Shape of the body and changing the radius.


But I'm curious as to why you desire to transform your physique. If you want to simulate the effect of a ball decreasing as you toss it, simply alter the sprite.

However, it is dependent on the game impact you desire.



Bottom line, there is no simple answer due to the box2d constraint (it would be really difficult if you had a polyline), however it is doable as mentioned above.
Is it simple for LIBGDX to alter scale?

So you're going to utilise libgdx?
 
Top