Development suggestions ?

Started by aeroxr1, September 05, 2014, 04:17:27 PM

Previous topic - Next topic

aeroxr1

Hi :)
I'm new in jpct and in 3d programmation.

Have you some suggestions to give me ?

For example, on official google opengl it divide in 3 different files :

GLSurfaceView.Renderer
GLSurfaceView
and mainactivity

then it extends GLSurfaceView in something like this :
public class MyGLSurfaceView extends GLSurfaceView

I tryed to do in this way but some more doubts has appeared to me  :-\

Can I define world in renderer class ?
How can I access to res from the class that not extend activity ?

Put this code in onSurfaceCreated is equal to put it in oncreate() ?

Resources res = getResources();
modello = BonesIO.loadGroup(res.openRawResource(R.raw.vincent));
modello.addToWorld(world);


Do you suggest me the correct approach ?

EgonOlsen

That's a general design decision and not really related to 3d or jPCT. There is no "correct" approach to do it, just multiple ways to screw things up... ;)

I can only comment on what i'm doing and that is to move everything game related into it's own class (like MyGame), create an Activity of the kind that you've mentioned, initialize MyGame in onSurfaceCreated and basically let the Activity don't do anything more than delegating almost everything to the game class. About res...you could either pass it to each an every class/method that needs it or build some custom container class that contains it as a static attribute. In my game, this is the ContentManager, which does all the loading. At the start of the Activity, i do something like


ContentManager.injectAssetManager(getResources().getAssets(), getBaseContext());


(in this case it Assets, but the same goes for res) and MyGame uses the ContentManager to load it's data. That way, i can switch implementations too and load data in anyway i like and not just via Assets or res and the actual game won't notice.

But as said, that's my way of doing it. There are dozens of others ways of doing it...

aeroxr1

THanks :)
Another question, what are the differents between OnsurfaceCreated,OnsurfaceChanged and onDrawFrame ?

Because after I read the google official reference I thought that :
OnSurfaceCreated was running only once time
OnSurfaceChanged was running every time the direction of the screen changes
onDrawFrame I'm not very sure, but is the function that renders all the scene ?

But in the example presents on the jpct the things seems a bit different.

For example in deadzombie the world is created in onsurfacechanged , but if the screen will never be rotated ?

sorry for too questions..  :-[