Apr 27, 2011 at 2:42 PM
Edited Apr 27, 2011 at 2:45 PM
Its good to see you're still trying. I would like to help point you in the right direction, but don't fully understand what you want to create. I don't really understand what you mean by art-based. If you are trying to create a
level from an image and then also use that image as the texture by drawing it on to the screen (on top of your physics), I wouldn't recommend that. I recall saying before that it can be done, but isn't a good idea. It just isn't practical, and
you'll fill up your video memory with those large textures. It's too limiting.
It sounds like you've looked at them but the advanced demo's provide code where they texture the physics objects and it may show you how you could approach the task.
The drawing and physics are two different systems and you really should try to separate them in your mind.
You have a texture you want to use to create your level (the 'level texture'). You will use each pixel to indicate the size and placement of your physics fixtures. This means that a pixel on your level texture doesn't equal a pixel on the screen when
you draw. You may want to ask yourself if creating a level from a texture is necessary and perhaps you could instead use an alternate approach..such as loading from a text or xml file. Because a texture is just data that is easier to visualize...but
a text file can provide the same data and may be easier to organize fixture sizes, shapes, and types.
Assuming you have fixtures created from your level data (the level texture), you'll have to save them somewhere. When saving them you may wish to organize them in a way so that you know what they are supposed to be in your world. Are they grass
sections, platforms, metal boxes? You could use the pixel color in your level texture to indicate this...or you could specify more directly in enumerations or integers if you are using a text/xml file.
So assuming when you created your fixtures you saved what type they were... above I mentioned grass, platforms and metal as examples. You can iterate through your fixtures and reference that type value... you can use it to draw the appropriate texture
to the screen. Use the fixture's position, dimension, and rotation to draw it in the correct shape and angle. You need to scale the fixture's values you use to world space (Research this on the forum if you don't understand...very important!) so they
are visible. Generally physics space is small and your world space will be larger.
Overall there are many ways to do this... my above mentioned approach is only one way. That's the beauty and horror of programming games.