libgdx + rub + noob questions ... :P

General discussion about Box2D tutorials
Post Reply
simondid
Posts: 4
Joined: Tue Jul 16, 2013 11:05 am

libgdx + rub + noob questions ... :P

Post by simondid »

Hey

So I’m kind of new to box2d in general... and I’m trying to make a pong game :P when I have made my bodies and textures in rub and exported in to my libgdx project I use this lines off code

Code: Select all

private RubeSceneLoader loader;
		private RubeScene scene;
		World world;
		loader = new RubeSceneLoader();
		scene = loader.loadScene(Gdx.files.internal("data/test.json"));
		world = scene.getWorld();
		world.setContactListener(new contactlistenerHandler());
my first problem is that i in some why need to identify my ball body... but i don't find a why to due this with out user data but in i figure out how to set user data in rube :( is there a better why to due this ???

second question :shock:
this problem have i been struggling with for a while now when the ball hits a paddle i need it to bounce off with an angel relative to where it hit the paddle ... but i can't figure out how to change the travel angel off my ball body :( how cut i solve this ???
i Goth a working pong game but it aint using box2d ... in this program the return angel is calculated like this

Code: Select all

private float getReflectionAngle(Paddle paddle) {
			float ballCenterY = ball.getY() + (ball.getHeight() / 2f);
			float paddleCenterY = paddle.getY() + (paddle.getHeight() / 2f);
			float difference = ballCenterY - paddleCenterY;
			float position = difference / paddle.getHeight();
			return BALL_REFLECT_ANGLE * position;
		}
i think i shut be able to use the same function in my box2d based pong game :P
but i need a function to change the movement angel...

sorry for my bad english :(
notnowlewis
Posts: 8
Joined: Tue Jul 09, 2013 6:46 pm

Re: libgdx + rub + noob questions ... :P

Post by notnowlewis »

Quick solution to your first question:

In RUBE, you have a list of bodies on the left. You'll see them as body0, body1, body2...

Double click one of them. Then you can type a new name, so you can change it to ball

Then you can get the ball in your code this way:

Code: Select all

Body ball = scene.getNamed(Body.class, "ball")
Post Reply