Body created using Libgdx Box2d is not being showing on screen when project is run -
project: i've been working on little project using libgdx-box2d in want create object, render screen , apply gravity collides ground. part working on creating , rendering body.
problem: problem body created not showing on screen when run project, sense have created body correctly there no compilation problems.
what tried:
i tried many things such increasing radius of circle create bigger (more visible)
zooming in screen doing camera = new orthographiccamera(gdx.graphics.getwidth() /10, gdx.graphics.getheight() /10); incase little see no matter tried object created cant seen.
changing position of body different x,y locations
outcome want: perchance reply why body created isn't beingness shown , help in rendering can seen. hope construction laid out question clear , informational. give thanks guys in advance help
here relevant code:
package com.mohamed.junglefighter; import com.badlogic.gdx.game; import com.badlogic.gdx.gdx; import com.badlogic.gdx.input; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.orthographiccamera; import com.badlogic.gdx.graphics.texture; import com.badlogic.gdx.graphics.g2d.sprite; import com.badlogic.gdx.graphics.g2d.spritebatch; import com.badlogic.gdx.graphics.g2d.textureregion; import com.badlogic.gdx.math.vector2; import com.badlogic.gdx.physics.box2d.bodydef; import com.badlogic.gdx.physics.box2d.bodydef.bodytype; import com.badlogic.gdx.physics.box2d.box2ddebugrenderer; import com.badlogic.gdx.physics.box2d.circleshape; import com.badlogic.gdx.physics.box2d.fixture; import com.badlogic.gdx.physics.box2d.fixturedef; import com.badlogic.gdx.physics.box2d.world; import com.sun.xml.internal.ws.wsdl.writer.document.soap.body; //i'm extending libgdx's built in game class implements activity listener public class junglefightermain extends game { private orthographiccamera camera; private spritebatch sbatch; private texture player; private texture enemy; //private spritebatch enemybatch; private sprite sprite1; private sprite sprite2; //just setting game heighty , width public static int gamewidth = 1280, gameheight = 720; private world world; private box2ddebugrenderer debugrenderer; p @override public void create () { //camera related photographic camera = new orthographiccamera(gdx.graphics.getwidth() /10, gdx.graphics.getheight() /10); //end of photographic camera related //box2d code creating wworld world world = new world(new vector2(0, -10), true); //creating box2d body definition bodydef bodydef = new bodydef(); //setting body type dynamic bodydef.type = bodytype.dynamicbody; //position bodydef.position.set(0, 0); //sending made world created // making circle radius of 6 circleshape circle = new circleshape(); circle.setradius(30f); //making fixtures circle fixturedef fixturedef = new fixturedef(); fixturedef.shape = circle; fixturedef.density = 0.5f; fixturedef.friction = 0.4f; //making bounce little fixturedef.restitution = 0.6f; //addding fixture attributes ball //fixture fixture = body.createfixture(fixturedef); //end of creating circle ball //creating actual ball in world world.createbody(bodydef).createfixture(fixturedef); circle.dispose(); //ground start bodydef bodyground = new bodydef(); bodyground.type = bodytype.staticbody; bodyground.position.set(-100,-100); //setting shape of ground chainshape groundshape = new chainshape(); groundshape.createchain(new vector2[] {new vector2(-250, 0), new vector2(250, 0)}); //fixtures ground fixturedef fixturedefground = new fixturedef(); fixturedefground.shape = groundshape; fixturedefground.friction = 0.5f; fixturedefground.restitution = 0; world.createbody(bodyground).createfixture(fixturedefground); groundshape.dispose(); } public void dispose() { world.dispose(); } public void render (float delta) { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); // photographic camera related sbatch.setprojectionmatrix(camera.combined); debugrenderer.render(world, camera.combined); world.step(timestep, velocityiterations, positioniterations); } } public void resize(int width, int height){ } public void pause(){ } public void resume(){ } }
in java not plenty declare object, have with:
private box2ddebugrenderer debugrenderer you need instantiate it, otherwise null reference. seek adding
debugrenderer = new box2ddebugrenderer() to create function avoid error mention in comments. constructor may take arguments not familiar box2d or libgdx.
libgdx box2d render
No comments:
Post a Comment