java - Libgdx - Box2D: Attach Physics Body Editor Loader mask to dynamic texture -


i have texture of circle, gets drawn new position when touch drag occurs. isn’t set body.

i have made physics map using aurelien ribon's physics body editor loader gui circle's upper , lower part, , i’d draw mask on texture’s position, , new position when drag occurs.

how can this? in create method initialize variables, mask gets drawn texture’s initial position, when move mask stays @ circle’s initial position.

here's code:

create() method:

 //... rest of method ommited clarity      karika = gameworld.getkarika();      world world = new world(new vector2(0, 0), false);   box2ddebugrenderer renderer = new box2ddebugrenderer();     bodyeditorloader karikaloader = new bodyeditorloader(gdx.files.internal("data/collision-masks/karika.json"));      bodydef karikadef = new bodydef();     karikadef.type = bodytype.dynamicbody;     karikadef.position.set(karika.getposition().x, karika.getposition().y);     karikadef.angle = karika.getrotation();      body karikabody = world.createbody(karikadef);      fixturedef karikafixture = new fixturedef();     karikafixture.density = 0.5f;     karikafixture.friction = 0.8f;     karikafixture.restitution = 0.6f;      karikaloader.attachfixture(karikabody, "karika", karikafixture, karika.getwidth());     vector2 karikabodyorigin = karikaloader.getorigin("karika", karika.getwidth()).cpy();      //rest of method ommited clarity 

my render() method:

 //...     batch.begin();     batch.draw(karikatexture, karika.getposition().x, karika.getposition().y, karika.getwidth() / 2, karika.getheight() / 2, karika.getwidth(), karika.getheight(), 1, 1, karika.getrotation(), 0, 0, karikatexture.getwidth(), karikatexture.getheight(), false, false);     batch.end(); renderer.render(world, cam.combined);     world.step(1 / 60f, 6, 2);     //... 

the texture being drawn in render method circle's texture. said before, haven't set body, collision mask.

what i'd do, attach mask texture, , keep it's position, example when drag circle, mask should stay on circle.

look debugrenderer. works well, , precisely you're asking.

here's how use it.

debugrenderer.render(this.world, camera.combined); 

and here's a more thorough tutorial.

i recommend assign circle's position using physics object's position rather trying assign physics object texture's position.

in code, looks create karikabody using current position of karika, karikabody position never being updated after that. "collision mask" (your physics body) position never changes.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -