Create multiple objects from one config

edited February 2011 in Help request
Hople I'll describe my needs so everyone can get it :) It's my first "projet" in ORX and I'm quite confused.

I have definition of object in ini file. It is simple picture, but I want to insert it into scene 9 times with different positions and interact with them separately.

Is there any way to do it without creating 9 objects in config file and creating them with 9 lines of code?


  • edited February 2011

    Yes, you can create 9 times the same object in code and then call orxObject_SetPosition() on them, and store the positions in config so as to be able to change them without having to recompile:
    ObjectPositions = (0, 0, 0) # (100, 0, 0) # ...
    Texture = ...
    Graphic = MyGraphic
    for(orxS32 i = 0; i < orxConfig_GetListCounter("ObjectPositions"); i++)
      orxVECTOR v;
      orxOBJECT *pstObject = orxObject_CreateFromConfig("MyObject");
      orxObject_SetPosition(pstObject, orxConfig_GetVectorList("ObjectPositions", i, &v));

    Or you can do it all in config and create only one object:
    ChildList = Object1 # Object2 # ...
    Graphic = MyGraphic
    Position = (0, 0, 0)
    Position = (100, 0, 0)
    in Code:

    And if you move this object, all the children will move at the same time.
  • edited February 2011
    Yes, I figured something like this alone, but what if I need to delete one (and only one) of this objects? Specifically after I click on it with mouse (Don't need full code of mouse clicks or so :)).
  • edited February 2011
    You have more than one option:
    - store every object manually in code when creating them one by one
    - store every object by listening to the orxOBJECT_EVENT_CREATE event (and only create the parent object)
    - go through all the objects when you need it and find the one you want (orxStructure_GetFirst/GetNext)
    - pick the object with orxObject_Pick() using the mouse position, in your case (the picking function looks only for object that have a greater Z than the position you give)

    There might be other ways, but I think those are the most common. :)
  • edited February 2011
    What a comprehensive response. Picking object by mouse position looks like the best way for me. I'll try it out.
  • edited February 2011
    Let me know if you encounter any trouble with it!
Sign In or Register to comment.