Size of body

General discussion about the R.U.B.E editor
Post Reply
blakey87
Posts: 28
Joined: Wed Jan 09, 2013 7:57 pm

Size of body

Post by blakey87 »

Is there any way of getting the size of a body in r.u.b.e in pixels or some other measurement,

So I can then create a the corresponding graphic in Photoshop?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Size of body

Post by iforce2d »

Measurements in the physics world are not related to the number of pixels in an image, so you can make the graphics at whatever size suits best.

For example, let's say you have a platform game where the player characters are 1 unit tall in the physics world, and you want the player character's height to take up about 1/10th of the screen height.

To draw this on an iPhone 3G with a 480x320 pixel screen, an image of about 32 pixels high would be enough. If you want to let the view zoom in sometimes, maybe you could use a higher resolution image so it doesn't look too blurry.

Now suppose you want to run the same game on a desktop computer, where the game screen size could be something like 1920x1080. For this case, the player character will be about 108 pixels high on screen, so a 32 pixel high image would get very stretched. I guess for this you would want to make the image at least 108 pixels high.

The point is, there is no official pixel size for a body :)

(Side note: you should not change any physics sizes, because the game will play completely differently. All you need to change is how it is rendered.)
metalbass_92
Posts: 18
Joined: Wed Dec 26, 2012 12:27 pm

Re: Size of body

Post by metalbass_92 »

What we do at work for handling multiple resolutions is to use different pixel to meter ratios, so you need to use methods in code to convert between pixels and meters and the other way.

32 pixels per meter seams a pretty standard value if you don't know what value to use ;)
Xavier Arias
Cocos2d-x Game Programmer
blakey87
Posts: 28
Joined: Wed Jan 09, 2013 7:57 pm

Re: Size of body

Post by blakey87 »

Both your points make sense,but I think I am still trying to make sense of how I would attach a graphic to a shape with with different size vertices, if this makes sense
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Size of body

Post by iforce2d »

To be honest I'm not really sure what you mean. Could you give an example?
blakey87
Posts: 28
Joined: Wed Jan 09, 2013 7:57 pm

Re: Size of body

Post by blakey87 »

In rube you can scale bodies.

If I increase the scale of a body would the size of the sprites I need to use then need to changed.

So basically if this were the case how would I work out what the size the corresponding sprite would be, sorry if I am missing something obvious, I'm an extreme noob coming from predominately a web developer background.

Thanks for the help!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Size of body

Post by iforce2d »

It comes back to the same answer though... it depends on how much of the screen you want the thing to take up.

When an image is attached to a body, scaling the body will cause the image to scale with it.

From the JSON you can get information about the image that lets you know where to draw it in relation to the body. The basic attributes are center point, angle and scale. The center point and angle are relative to the body position, so they should be modified by body->GetBody() to draw the image at the right position when the body moves. The scale is the size of the vertical side of the image in physics units. If you are using a PTM ratio you could multiply this by the PTM to get a 'pixel' size for the image.

If you are using OpenGL you might find the C++ sample loader useful as an example. If you are using a javascript canvas the Javascript example would be useful to look at, and I think the Android canvas is similar. What type of rendering API are you dealing with?
blakey87
Posts: 28
Joined: Wed Jan 09, 2013 7:57 pm

Re: Size of body

Post by blakey87 »

Ok great that makes a lot more sense now thanks!

I'm going to be using cocos2d for attaching sprites too
Post Reply