Author Topic: Tile Index doesnt work how I think it does...  (Read 839 times)


  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
Tile Index doesnt work how I think it does...
« on: Sat, Apr 10, 2010 »
so umm, basically that. I was under the impression that a tiles index would be be the y coordinate of the tile (in tiles) * the total width in tiles, + the x coordinate in tiles. It seems I was wrong however, and as of such Im rather confused.
My code is rather simple, in the playstate I have this
Code: [Select]
if (FlxG.keys.D)
plantablemap.plant = 11;
plantablemap.change = ((((tile.y / 32)) * 48) + (tile.x /32));
and in my plantablemap (that extends FlxTilemap) I have
Code: [Select]
if (change > 0)
setTileByIndex(change, plant);
time[change] = curtime;
change = 0;
This breaks in a couple ways, first off (and this is slightly minor) the tile doesnt get updated right away (at least graphically) until a later event hits the point in the time array that got changed, and updates the tile
Code: [Select]
if (time[grow] + growthrate < curtime && (getTileByIndex(grow)%5) != 0 && getTileByIndex(grow) > 4)
setTileByIndex(grow, (mapdata[grow] + 1));
time[grow] += growthrate;
Where mapdata = the map's actual array, and grow is an int that basically just loops through every index in the map forever. (Im using an if event for this, so that other things can happen at the same time, it makes it take a second to update, but otherwise is fine, and given that ultimately growthrate is going to be a few hours, it wont really be to noticeable)

Basically, what ends up happening, is when the value is set, it updates a tile one below and considerably to the right of where I would expect it to update, and waits for the grow event to actually update the graphic. If I use setTile((tile.x/32),(tile.y/32)) it behaves as expected, but I then I have the same problem updating the time array. I could make time a tilemap inside of the tilemap instead of an array, and just make it invisible and non colliding, but that seems really inefficient, especially when if I use an array, there index's still lineup fine, and all Im storing in time is the timestamp for when things happen, and I really dont need any of the usual tilemap cruft.