Object Repeat and Picking on Mouse Click

edited April 2013 in Help request
I am trying to create a simple rectangular board that consists of individual cells.
I am following tutorial projects as examples.

Config file made it easy to create a board of cells:

Position = (0, 0, 1.0); <= We place our first vertical wall
Graphic = CellGraphic;
Repeat = (22, 17, 1); tile graphic (x, y, 0) times on axis
Scale = @Cells.Repeat;
Body = WallBody

Then I display this object:


I then set event callback:

orxCLOCK *pstClock;
pstClock = orxClock_FindFirst(orx2F(-1.0f), orxCLOCK_TYPE_CORE);

/* Registers our update callback */
orxClock_Register(pstClock, Update, orxNULL, orxMODULE_ID_MAIN, orxCLOCK_PRIORITY_NORMAL);

And here is my update callback that changes the color of the object. I expected to pick an individual cell, but the entire collection of cells changes the color.

I think there is nothing wrong with that, but now I am stuck and can't figure out how to select just one object. I suspect that one INI section name is one object. If that's the case, then I assume I have to create objects inside Init function and I don't know how to do that. I am sorry, it must be trivial, but I want to make sure I don't do something stupid.



  • edited April 2013
    I got a very good idea of how the system works by reading this post: https://forum.orx-project.org/discussion/4714&catid=16#4714
  • edited April 2013
    Here is how I ended up solving it after reading the post on the nature of orxObject.

    I create objects in Init function based on the configuration file section:
    Position = (0, 0, 1.0);
    Graphic = CellGraphic;
    Body = WallBody

    here is a loop inside Init to create objects:
    for (int x = 0; x < 22; x++) {
            for (int y = 0; y < 17; y++) {
                orxOBJECT *cell = orxObject_CreateFromConfig("Cell");
                orxVECTOR pos;
                orxObject_GetPosition(cell, &pos);
                pos.fX = orx2F(x * 35);
                pos.fY = orx2F(y * 35);
                pos.fZ = orx2F(1);
                orxObject_SetPosition(cell, &pos);

    and now clicking highlights the object. It is just perfect. I wrote a small game in OpenGL and I remember dealing with the same issue. It was hard as I don't work day to day with this kind of staff.

    I really like the system so far. I don't mind choice of C. In fact, I prefer it.
  • edited April 2013
    Looks good to me!

    Also, I'm glad that you enjoy orx so far. :)

    As for this specific code, let me suggest you an alternative that would take advantage of the config system, letting you adjust things directly from config without having to recompile.

    Position = (0, 0, 1)
    Graphic = CellGraphic
    Body = WallBody
    GridWidth = 22
    GridHeight = 17
    Offset = (35, 35, 0)

    orxU32    u32Width, u32Height;
    orxVECTOR vOffset;
    // Pushes [Cell] config section
    // Getting our Grid data
    u32Width = orxConfig_GetU32("GridWidth");
    u32Height = orxConfig_GetU32("GridHeight");
    orxConfig_GetVector("Offset", &vOffset);
    for(orxU32 x = 0; x < u32Width; x++)
        for(orxU32 y = 0; y < u32Height; y++)
            orxOBJECT *pstCell;
            orxVECTOR  vPos, vTemp;
            // Creates new cell
            pstCell = orxObject_CreateFromConfig("Cell");
            // Gets its grid "coordinates"
            orxVector_Set(&vTemp, orxU2F(x), orxU2F(y), orxFLOAT_1);
            // Computes its absolute offset
            orxVector_Mul(&vTemp, &vTemp, &vOffset);
            // Gets base position, updates it with the offset and sets it back
            orxObject_SetPosition(pstCell, orxVector_Add(&vPos, orxObject_GetPosition(pstCell, &vPos), &vTemp));
    // Pops config section
Sign In or Register to comment.