Getting an object from a World

Started by Melssj5, September 10, 2005, 04:11:42 AM

Previous topic - Next topic

Melssj5

Hi, am am doing a game in wixh I want to use two Worlds.

I wanted to have a methos that loads all the .3DS files from a given directorie so I have ordered my level in direcories like

MAP1

MAP2

MAP3

and I just have to call a method to load all 3D objects inside, but as the my loading method loads Object in general, I used a local temporalObject3D, and after loading all inside the direcorie it builds them into the world with buildAllbjects ();

Now I need to move one of the .3DS files inside the directory I loaded, bus as I used a local object3D for generality reasons now I need to get the Object3D whose file is called Seleccionador.3DS but I cant, how can I do it, the file only have 2 pyramids but I need to move it, I tried using the getObjectByName (String name) from World but it didnt work.

Which are the names of the 3DS loaded, I tried using "Seleccionador", "Seleccionador.3DS", as it didnt worked I think can only the parts can be gotten with this method so I tried with "Pyramid01_jPCT18" because I saw that name when the 3DS file is being loaded, but it didnt worked too, how can I do that.
Nada por ahora

EgonOlsen

If you want to do it that way, you have to set the name yourself by using setName(<String>) for the objects in question, i.e. after loading your object, call obj.setName("Seleccionador"); before adding it to the world. But you have to make sure that the name is unique for the world the object belongs too. jPCT doesn't check this.
In Paradroidz, i'm using a subclass of World called Level that holds references to XXXManagers, which are in fact object pools. I.e. an EnemyManager manages all the enemies, an ExplosionManager manages all the explosion...that way, it's always possible to access your objects without retrieving them back from the world. But that's totally up to you, it's just one way of doing it that i wanted to share...it doesn't have to be the best one.

Melssj5

I dont think that this is a possible solution, This is my code for loading 3DS files.


public static World cargarMapas (String DIR) {
       World tempWorld=new World ();
       Object3D tempObject3D=null;
       Configuracion C=new Configuracion ();
       File directorioMapas=new File (C.getPath ()+"Mapas/"+DIR+"/");
       String nombresMapas []=directorioMapas.list ();
       for (int i=0;i<nombresMapas.length;i++) {
           if (nombresMapas [i].endsWith ("3DS")){
               tempObject3D=null;
               tempObject3D=new Object3D (0);
               Object3D mapaPartes []=Loader.load3DS (C.getPath ()+"Mapas/"+DIR+"/"+nombresMapas [i], 1f);
               for (int j=0;j<mapaPartes.length;j++) {
                   Object3D part=mapaPartes [j];

                   part.setCenter(SimpleVector.ORIGIN);
                   part.rotateX((float)-Math.PI/2);
                   part.rotateMesh();
                   part.setRotationMatrix(new Matrix());

                   if ((i&1)==1) {
                       part.setTransparency(0);
                   }
                   
                   tempObject3D=Object3D.mergeObjects (tempObject3D, part);
               }

               tempObject3D.setCollisionMode (Object3D.COLLISION_CHECK_OTHERS|Object3D.COLLISION_CHECK_SELF);
               tempWorld.addObject (tempObject3D);
           }
       }

       return tempWorld;
   }


In this method a String is received as parameter that is the anme of the directory, the method loads all the .3DS files inside that directory into a temporal world that is returned, so you can see, that for generality reasons I cant reference my Object3D "Seleccionador", because I use it for all the program

for example

World Level1=cargarMapas ("Map1");

Would be very very useful that the parts of the Object3D were stored using the File name to identify all of them, for example getObjectByFileLoaded ("Seleccionador.3DS");

Any idea about how to solve my problem?
Nada por ahora

EgonOlsen

Quote from: "Melssj5"
Any idea about how to solve my problem?

tempObject3D.setName("Seleccionador.3DS");   :?:

Anonymous

Quote from: "EgonOlsen"
Quote from: "Melssj5"
Any idea about how to solve my problem?

tempObject3D.setName("Seleccionador.3DS");   :?:

If I do that then all the objects will be called "Seleccionador.3DS" because the tempObject3D is a diferent .3DS file on each for iteration.

EgonOlsen

It was just an example. tempObject3D.setName(nombresMapas ); is better?

Melssj5

Quote from: "EgonOlsen"It was just an example. tempObject3D.setName(nombresMapas ); is better?

Of course, I was so fool today. I solved my problem, thanks  :wink:
Nada por ahora