java - Bx2D body Sprite synch -
seeing how box2d bodies cannot resized, have problem bodies , animated sprites.
here's situation have no doubt not unique: sprite's dimensions change during different motions attacking, walking, jumping. seeing how use box2d body collision detection can cause quite problem. far thought of 3 ways solve issue.
1- not use box2d bodies collision detection , use them object's physical behavior
2- delete , recreate body before each render. or on animation change.
3- trying recheck collision on bodies see if collides sprite itself. act.
and here's problem have each of these solutions.
1- way makes using box2d whole seem rather absurd, i'll using not one, 2 world logic , trying keep them in sync. seems big headache.
2- doesn't optimized, doubt can make objects pop in , out of existence in physics world without side effects.
3- i'm not sure how or if can done, option 1 require more advice on. cause difficulties in long run, or cause conflicts in physics.
please let me know if there efficient way solve , or if of above solutions worth working on.
my thanks
edit: more of general question since still don't have proper graphics game i'm writing, here's practice material:
walking waiting (standing) attacking
a body can have multiple fixtures, can add fixtures each state body. if make them 0 density should not affect physics behavior of body. keep in mind though, @ least 1 fixture on body should non-zero density - make 1 fixture act main fixture, has density give body mass.
if need detect when these fixtures touching something, make them sensor fixtures, , use contact listener keep track of other things touching. contact listener give callbacks of fixtures regardless of state character in, , each state keep list of things fixtures state touching.
if need fixtures have physical interaction when state active, above in begincontact contact->setenabled(false) if contact fixture not in active state.
Comments
Post a Comment