Author Topic: Development suggestions ?  (Read 1908 times)

Offline aeroxr1

  • int
  • **
  • Posts: 82
    • View Profile
Development suggestions ?
« on: September 05, 2014, 04:17:27 pm »
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() ?

Code: [Select]
Resources res = getResources();
modello = BonesIO.loadGroup(res.openRawResource(R.raw.vincent));
modello.addToWorld(world);

Do you suggest me the correct approach ?
« Last Edit: September 05, 2014, 04:23:09 pm by aeroxr1 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Development suggestions ?
« Reply #1 on: September 05, 2014, 09:41:48 pm »
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

Code: [Select]
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...

Offline aeroxr1

  • int
  • **
  • Posts: 82
    • View Profile
Re: Development suggestions ?
« Reply #2 on: September 06, 2014, 09:54:58 am »
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..  :-[