Getting a Graphic Name

edited September 2012 in Help request
Looks like I've hit a small snag.

I have the following :
[SolidTileObject]
Graphic		= WALL

[TilesGraphic]
Texture 	= ../../data/scenery/tiling-map.png
TextureSize		= (64, 64, 0)

[WALL@TilesGraphic]
TextureCorner		= (0, 0, 0)

[GRASS@TilesGraphic]
TextureCorner		= (64, 0, 0)

[MapLevel]
Map		= WALL #WALL #WALL #GRASS

I can easily get an object name, or the tiling-map.png by casting the object to an orxTEXTURE, but is it possible to get the name of the graphic: WALL.

I need to locate the name "WALL" or any of the graphic names so that I can get my character to respond differently depending on what tile it collides with.

Don't seem to be able to work out how to get around this one.

Comments

  • edited September 2012
    Mmh, your graphic is linked to an object, isn't it?

    Either done in config or in code. If it's in config, you can get the info by pushing the object section and looking for the key Graphic. If it's linked in code, when you link it, simply push its name in the object's config section, this way you can easily find it back later.

    Would that work for you?
  • edited September 2012
    I don't have an answer using orx, but have you considered simply adding your own custom field for such data? This would allow you a little more control over reactions that aren't limited to what your graphics show. (ie: hidden exits in walls [walls with no collision], etc)
  • edited September 2012
    my opinion,

    it's a very strange way to define your map tiles...

    dont't be cheap on Config sections

    [WallObject]
    Graphic = WALL

    [GassObject]
    Graphic = GRASS

    [MapLevel]
    Map = WallObject # WallObject # WallObject # GrassObject

    Btw: consider using Scroll and ScrollEd.

    And override the OnCollide() callback to decide what to do
  • edited September 2012
    @iarwain: yes the linkage is done in code with something like..
    for (int y=0; y<20; y++){
    	  for (int x=0; x<20; x++){
    	  
    		const orxSTRING tileGraphicName = orxConfig_GetListString("Map", x + y*20);
    		
    		orxOBJECT *tileObject;
    		
    		if (orxString_Compare( tileGraphicName, "WALL" ) == 0){
    			tileObject = orxObject_CreateFromConfig("SolidTileObject");
    
    .. other logic ..
    				
    		orxGRAPHIC *graphic = orxGraphic_CreateFromConfig(tileGraphicName);
    		orxObject_LinkStructure(tileObject, orxSTRUCTURE(graphic));
    		
    		orxVECTOR tilePos;
    		tilePos.fX = (64 * x);
    		tilePos.fY = (64 * y);
    		tilePos.fZ = 0.1;
     
    		orxObject_SetPosition(tileObject, &tilePos);
    		
    	  }
      }
    

    So because it's in code @iarwain & @grey, then I can push a custom variable (the name) here to retrieve later. I like this idea.

    Many thanks.

    @lydesik, yep cheap I suppose but it works, and I can change common values within a base of "TilesGraphic". Not quite ready for scroll right now. I'd like to stick closer to the metal for a little while longer.
  • edited September 2012
    Silly me. Every tile is created using a "SolidTileObject" object defined by the same config section. So I can't push a variable to that section. It would be overwritten each time by the last.

    Is there no way using an orxStructure that I can get the graphic name currently assigned to an object?

    Sorry if I am missing the obvious.
  • edited September 2012
    You can still use the inheritances for your graphics, that's not a issue

    [TilesGraphic]
    Texture = ../../data/scenery/tiling-map.png
    TextureSize = (64, 64, 0)

    [WALL@TilesGraphic]
    TextureCorner = (0, 0, 0)

    [GRASS@TilesGraphic]
    TextureCorner = (64, 0, 0)

    this is perfectly fine, and a good way to define your tiles graphics.

    I don't have a solution for what you are looking for ( retrieve the Graphic name used by an Object at runtime ).

    But i propose you with a simple alternative to achieve what your are trying to do ( filter game logic base on Graphics, via the Objects names ). Tell me if I'm wrong.

    so your loop become
    for (int y=0; y<20; y++){
    for (int x=0; x<20; x++){
      
    const orxSTRING tileObjectName = orxConfig_GetListString("Map", x + y*20);
    
    orxOBJECT *tileObject;
    tileObject = orxObject_CreateFromConfig(tileObjectName);
    
    orxVECTOR tilePos;
    tilePos.fX = (64 * x);
    tilePos.fY = (64 * y);
    tilePos.fZ = 0.1;
     
    orxObject_SetPosition(tileObject, &tilePos);
    
    if (orxString_Compare( tileObjectName, "WallObject" ) == 0){
    
    .. other logic ..
    
      }
    }
    

    but now you can filter the behavior with player collisions based on the object name.
  • edited September 2012
    Sounds good to me!

    Another options would be to push the GUID of your object as a section and store there the name of the property you want to track (in your case the graphic's name).

    GUIDs are unique per structure instances and can be retrieved at runtime using orxStructure_GetGUID().
  • edited September 2012
    Thanks lydesik and everyone for the help.

    I forgot that I am already using Object names for different tiles already. So while I said I had an object name of "SolidTileObject", I also have others like "StickyTileObject".

    So I really wanted subsets of those objects to identify as well (which are the graphic names).

    So to avoid having to refactor how I use the config, I've fallen back to a nice solution of having a simple tile class and connecting them to objects with SetUserData (I love this thing). I store the names there.

    .h file
    class tile {
    
    private:
    	orxOBJECT *tileObject;
    	const orxSTRING name;
    	
    public:
    	tile(orxOBJECT *orxObject, const orxSTRING graphicName);
    
    
    };
    

    .cpp file
    tile::tile(orxOBJECT *orxObject, const orxSTRING graphicName){
    
    	tileObject = orxObject;
    	name = graphicName;
    	
    	orxObject_SetUserData(orxObject, this);
    	
    }
    

    In my map painting loop
    tile *t = new tile(tileObject, tileGraphicName);
    

    In my collision detection
    tile *t = (tile *)orxObject_GetUserData(wallObject);
    //t->GetName();
    
  • edited September 2012
    ok, suit yourself.

    as a side note, orxString_Compare() is not really efficient, you should try to call it once, and then, store a flag (bit field or boolean variable) in your class.

    so your subsequents test will be based on this flag, which is much more efficient.

    ofcourse there is the two programmer rules:
    1) dont optimize now
    2) dont optimize yet

    and maybe you are not doing these tests very often in your game loop
  • edited September 2012
    Yep I do use orxString_Compare() quite a lot, so I'll optimise use on that. Many thanks!
  • edited September 2012
    I'd be more concern by the dynamic allocations new/delete, personally. ;)

    But yep, Lydesik's right, don't optimize before knowing it needs optimization! Which reminds me I should optimize the render plugin. ^^
  • edited September 2012
    Not that interesting, but for the sake of completeness, another straightforward option:
    .. other logic ..
    
    orxGRAPHIC *graphic = orxGraphic_CreateFromConfig(tileGraphicName);
    orxObject_LinkStructure(tileObject, orxSTRUCTURE(graphic));
    
    // Storing name info into instance (can be wrapped in a function) and retrieval is just a Get instead of Set
    orxCHAR acBuffer[20];
    orxString_Prinf(acBuffer, "%lu", orxStructure_GetGUID(graphic));
    orxConfig_PushSection(acBuffer);
    orxConfig_SetString("Name", tileGraphicName);
    orxConfig_PopSection();
    
Sign In or Register to comment.