How to set offset of a sprite during runtime?

Hello~
When I set hflip of a sprite with offset(center of the animation is not the center of collsion shape), it seems that the animation is flipped correctly , but the offset of the sprite doesn’t flip with that. How can i fix this? Thanks!

As far as I know you cannot change the collisionobject position in runtime, but you can solve your issue by having two collision objects, one for the sprite when it’s not flipped and one when it’s flipped.
You can just enable/disable the correct collisionobject when you flip the sprite doing something like this:

if flip then
    msg.post("#flipped_collision", "enable")
    msg.post("#collision", "disable")
else
    msg.post("#flipped_collision", "disable")
    msg.post("#collision", "enable")
end

I got it , thanks.

1 Like