setGlobalTileID

  ... discussions about development with the GLES2 branch of AndEngine.

setGlobalTileID

Postby Queeez » Fri Feb 03, 2012 12:48 pm

Hi!

When i use e.g. tmxTile.setGlobalTileID(mTMXTiledMap, 31) and tile 31 is a tile which i gave a property that the user can not walk on, then the player on my map is after that not able to walk on this tile.
So far so good...

So lets say the tile was before a "grass"-tile and after that the tile with id 31 is a "stone"-tile. Should the display of that tile after that change? Because in my example the tile gets only the property of the new tile, but on the screen i dont see the new stone-tile!

Do i something wrong or is the new tile with that method not displayed?
Queeez
 
Posts: 4
Joined: Thu Feb 02, 2012 1:44 pm

Re: setGlobalTileID

Postby CaptnIgnit » Wed Feb 08, 2012 1:24 am

I'm having the same problem too. I'm guessing it has to do with changes to how the textures are managed. Currently looking through the code to see if I can find a work around.
CaptnIgnit
 
Posts: 87
Joined: Tue Feb 01, 2011 5:10 am

Re: setGlobalTileID

Postby CaptnIgnit » Wed Feb 08, 2012 1:41 am

k after reading through the code I think the issue is that the mSpriteBatchVertexBufferObject in the TMXLayer never gets updated with the proper texture at the given coordinate as it is only calculated through the addTileByGlobalTileID() call.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.setIndex(this.getSpriteBatchIndex(column, row));
  2. this.drawWithoutChecks(tmxTileTextureRegion, tmxTile.getTileX(), tmxTile.getTileY(), tileWidth, tileHeight, Color.WHITE_PACKED);
  3. this.submit(); // TODO Doesn't need to be called here, but should rather be called in a "init" step, when parsing the XML is complete.
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


this is the code that needs to be rerun once the textureregion has been changed.
CaptnIgnit
 
Posts: 87
Joined: Tue Feb 01, 2011 5:10 am

Re: setGlobalTileID

Postby CaptnIgnit » Wed Feb 08, 2012 2:00 am

k got a fix(hack), but you'll need to edit some of the the TMX extension files.

Adjust this however you need to apply to whatever TMXLayer the tile is on.

first, add this function into the TMXLayer class:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. void updateTileTexture(final int pTileColumn, final int pTileRow)
  2. {
  3.         TMXTile tmxTile = mTMXTiles[pTileRow][pTileColumn];
  4.                
  5.         final int tileHeight = this.mTMXTiledMap.getTileHeight();
  6.         final int tileWidth = this.mTMXTiledMap.getTileWidth();
  7.                
  8.         this.setIndex(this.getSpriteBatchIndex(pTileColumn, pTileRow));
  9.         this.drawWithoutChecks(tmxTile.getTextureRegion(), tmxTile.getTileX(), tmxTile.getTileY(), tileWidth, tileHeight, Color.WHITE_PACKED);
  10.         this.submit(); // TODO Doesn't need to be called here, but should rather be called in a "init" step, when parsing the XML is complete.
  11. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


then in the setGlobalTileID in the TMXTile class add this line to the bottom:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. pTMXTiledMap.getTMXLayers().get(0).updateTileTexture(this.mTileColumn,this.mTileRow);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
CaptnIgnit
 
Posts: 87
Joined: Tue Feb 01, 2011 5:10 am

Re: setGlobalTileID

Postby Queeez » Thu Feb 09, 2012 10:33 am

Thanks!
Queeez
 
Posts: 4
Joined: Thu Feb 02, 2012 1:44 pm

Re: setGlobalTileID

Postby DragonPT » Wed May 09, 2012 11:07 am

I think you should push this fix into the git tmx extension so that future versions have it included. I'm also having this problem and will apply you fix to the tmx extension. The problem is that if the extension is updated in the git without your fix, it will get lost.

Thanks for your solution on this problem!

Dragon

CaptnIgnit wrote:k got a fix(hack), but you'll need to edit some of the the TMX extension files.

Adjust this however you need to apply to whatever TMXLayer the tile is on.

first, add this function into the TMXLayer class:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. void updateTileTexture(final int pTileColumn, final int pTileRow)
  2. {
  3.         TMXTile tmxTile = mTMXTiles[pTileRow][pTileColumn];
  4.                
  5.         final int tileHeight = this.mTMXTiledMap.getTileHeight();
  6.         final int tileWidth = this.mTMXTiledMap.getTileWidth();
  7.                
  8.         this.setIndex(this.getSpriteBatchIndex(pTileColumn, pTileRow));
  9.         this.drawWithoutChecks(tmxTile.getTextureRegion(), tmxTile.getTileX(), tmxTile.getTileY(), tileWidth, tileHeight, Color.WHITE_PACKED);
  10.         this.submit(); // TODO Doesn't need to be called here, but should rather be called in a "init" step, when parsing the XML is complete.
  11. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


then in the setGlobalTileID in the TMXTile class add this line to the bottom:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. pTMXTiledMap.getTMXLayers().get(0).updateTileTexture(this.mTileColumn,this.mTileRow);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
DragonPT
 
Posts: 1
Joined: Fri Nov 12, 2010 11:36 am

Re: setGlobalTileID

Postby rioneye » Thu May 10, 2012 3:13 am

if you don't want to change the Andengine library than try this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mTestTile.setGlobalTileID(mTMXTiledMap, mGloabalIndex);
  2.  
  3. //After changing the global ID do this      
  4. final int TileHeight = mTMXTiledMap.getTileHeight();
  5. final int TileWidth = mTMXTiledMap.getTileWidth();          
  6. //See TMXLayer Class line 308 (getSpriteBatchIndex)
  7. lTMXLayer.setIndex(mTestTile.getTileRow() * mTMXTiledMap.getTileColumns() + mTestTile.getTileColumn());
  8. lTMXLayer.drawWithoutChecks(mTestTile.getTextureRegion(), mTestTile.getTileX(), mTestTile.getTileY(), lTileWidth, lTileHeight, Color.WHITE_ABGR_PACKED_FLOAT);    
  9. mTMXTiledMap.mTestTMXLayer.submit();
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Nice work finding this fix out in the first place CaptnIgnit!
User avatar
rioneye
 
Posts: 277
Joined: Tue Jun 28, 2011 7:08 pm
Location: USA

Re: setGlobalTileID

Postby thonguyen252 » Sat Jun 15, 2013 1:26 pm

Thanks you. That's my problem.
thonguyen252
 
Posts: 1
Joined: Sat Jun 15, 2013 1:24 pm

Re: setGlobalTileID

Postby feanras » Mon Aug 26, 2013 2:26 pm

where you are accesing tmxTile.setGlobalTileID ? where it should be called, why and is it only way? I can't find out why the only option to change tile texture runs through setGlobalTIleID. is it correct to try coding it inside onmanagedupdate method? maybe it's better to simple overdraw a sprite onto such tile?
feanras
 
Posts: 11
Joined: Sat Apr 13, 2013 12:18 am

Re: setGlobalTileID

Postby kabuto178 » Sun Sep 15, 2013 9:55 pm

I tried the changes outlined here, but still ended up with the same problem, any other fixes?
kabuto178
 
Posts: 105
Joined: Sun Sep 08, 2013 2:31 am


Return to GLES2

Who is online

Users browsing this forum: Alexa [Bot], metalnumb, Yahoo [Bot] and 33 guests