ZhouWeikuan / cocos2d

cocos2d for android, based on cocos2d-android-0.82, and now ported from cocos2d-iphone 0.99.4. The googlecode address is here: http://code.google.com/p/cocos2d-android-1/ . There are several demos to watch.
610 stars 291 forks source link

Can't retrieve tile properties #43

Open ghost opened 12 years ago

ghost commented 12 years ago

The following should return the properties for a tile:

propertiesHashMap = _map.propertiesForGID( layer.tileGIDAt( point ) );

It seems that the poperties for a tileset's GIDs do not match up with the map's GID's. The tile's GID's are numbered 1 through tileset size, so if there are 16 tiles, then it has GIDs 1 through 16. The map's GID's are generated in some other manner. Example is 637534208.

So when I get the tile by GID at a point on the layer it returns 637534208. When I use this GID to get the tile properties for that tile I get an error or null.

ghost commented 12 years ago

I am noticing the same issue.

When using CCTMXLayer.tileGIDAt(CGPoint pos) no matter what index I pass into the tiles.get(int index) method I get back a tile GID of 1677216.

When I inspect the contents of the 'tiles' object I see that it's populated with my 2500 tiles and their appropriate GID. In my case I have two tiles on my map, tile GID 1 and tile GID 2. Why then does tiles.get(int index) always return back 1677216 as my GID?

Does anyone have a workaround for this so that I can retrieve the correct tile GID?

So I figured it out.

so I dug a little deeper into the cocos2d-android code and found the CCTMXLayer.setupTiles() method. There is a note in that method that says the GIDs are stored in little endian.

            // gid are stored in little endian.
            // if host is big endian, then swap
            // Java is big endian
            // if( o == CFByteOrderBigEndian )
            gid = CCFormatter.swapIntToLittleEndian(gid);

so, now after I call this._meta.tileGIDAt(CGPoint pos); to get my tileGid I now swap the returned value from a BIG ENDIAN to a LITTLE ENDIAN

    tileGid = CCFormatter.swapIntToLittleEndian(tileGid);

This gives me the tile GID that I have been expecting to see the whole time.

I hope this can help anyone else having the same issue.

I don't believe this is a bug after all. This can probably be closed.