A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: [HELP] Different tile states...best method?

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    9

    [HELP] Different tile states...best method?

    Hiyas

    Once again, I turn to the experts here for help with a simple prob...

    Basically, I have a tile map. I need every tile to have 3 states - lit (explored), dark (unexplored) and dim (in sight but unexplored).

    The hero steps on a tile, and that tile becomes "lit". The 9 tiles around hero become "dim".

    I can't see any way to do this without changing the tile array and redrawing the whole map every time the hero moves. Am I missing something easier?

    Thanks,

    RM.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    What version of Flash and AS are you using?
    How are you putting the tiles on the stage?

  3. #3
    Senior Member
    Join Date
    Feb 2004
    Posts
    312
    just find the adjacent tiles of the one that the hero is on.
    Code:
    var tileArray:Array = [[tile1, tile2,...],[tile1, tile2,...],[tile1, tile2,...],[tile1, tile2,...]]
    
    /**
    * @param t_i the index i of the tile that the hero is on
    * @param t_j the index j of the tile that the hero is on
    */
    function dimAdjacentTiles(t_i:uint,t_j:uint):void {
      for(var i:uint=-1; i <= 1; i++) {
        for(var j:uint = -1; j <= 1; j++) {
          if(i != 0 || j != 0) {
            (tileArray[t_i + i][t_j + j]).dim();
          }
        }
      }
    }
    Hope this helps.

  4. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    9
    Hi,

    Using AS2 and FP9. I think there's a little confusion here - I have no issues detecting the correct tiles to target - in fact my loop is almost exactly like yours

    What I was asking was what is the best way to actually change the tiles? Is it possible to change an element of the tile array, then redraw JUST that tile? Or should I be layering "effects" (dark, light, dim) over a tile map?

    Depending on the state of the tile, different actions become available to the hero, so I want to start this in the best way, not have to totally rewrite halfway through.

    The tiles are being placed in a very simple array, originally derived from tonypa's tutorials, but I have written some code to load them from xml.

    Thanks!

    RM.

  5. #5
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    As dawsonk asked, that depends on how you're placing those tiles on stage. However, in just about every efficient placement method the answer is yes.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  6. #6
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    Well, I don't really know about your current placement methods, but If it were me, I would simply blit the correct tile images around the player tile, when the player moves(or just update the necessary tile images). Cause, if I understand correctly, when the player moves, you are only updating 9 or 10 tiles, so it isn't a problem with performance.
    like:
    Code:
    //..within something like aluminx's loop above
    ......
    .....
         {
           dimOut (t_i + i,t_j + j);
         }
    ...
    ..
    
    protected function dimOut(m:Number,n:Number):void
    {
       tileArray[m][n].state = 2; // or "dim" or however you wanna specify them
       tileArray[m][n].bitmapData = _global.states[2]; //assuming states is a global array holding the bitmapData of all the tiles.
    }
    tileArray can also simply hold instances of "tile" class extending Bitmap, and you can probably write a setter method to handle changing the state and bitmapData all at once.

    As for the global array, I would simply load in a spritesheet, or rather I should say a tilesheet, and split it into bitmapData tiles for easy referencing. (I am using this technique in my current as3 project.)


    I wish you had followed tonypa's as3 tutorials instead of as2 ones, then probably I could have been more of a help to you.
    Last edited by bluemagica; 08-26-2010 at 11:35 PM.
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  7. #7
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    I may have missed the point slightly, so this may be crap, but can't you just make the tiles movieclips ?

    If you're fine with detecting which tiles should be altered then it's as simple as a gotoAndStop.

    You should only need to alter the map to reflect explored tiles, those are the ones which permanently change state (?)

    Sorry if I've missed the point.

    Squize.

  8. #8
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    Using movieclips would be the standard way, but i don't think they would be very efficient especially in as2. Oh well, the concept is the same, and using movieclips will take some work off his shoulders.
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  9. #9
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    mc's are quicker than blitting in as2.

    Blitting should only really be used as a last resort, not the default.

    Squize.

  10. #10
    Senior Member
    Join Date
    Feb 2004
    Posts
    312
    Quote Originally Posted by RitualMagic View Post
    Hi,

    Using AS2 and FP9. I think there's a little confusion here - I have no issues detecting the correct tiles to target - in fact my loop is almost exactly like yours

    What I was asking was what is the best way to actually change the tiles? Is it possible to change an element of the tile array, then redraw JUST that tile? Or should I be layering "effects" (dark, light, dim) over a tile map?

    Depending on the state of the tile, different actions become available to the hero, so I want to start this in the best way, not have to totally rewrite halfway through.

    The tiles are being placed in a very simple array, originally derived from tonypa's tutorials, but I have written some code to load them from xml.

    Thanks!

    RM.

    Ohh i see. Well you can either re-draw the tile or just have the dim graphic on a different frame.
    Pick whichever seems easier for you to do. If performance is what worries you, than I say don't over engineer it. Just do it if you see that's the bottle neck, than come back and we'll revisit the issue

  11. #11
    Junior Member
    Join Date
    Jul 2010
    Posts
    9
    Wow, so many responses - this forum is great!

    I've been looking at the issue from a few different angles, and I think I am going to adopt the approach of changing the tile array and rebuiding the map when the hero moves - there are only 25 tiles visible at any time, so it's not too processor intensive

    As an aside: any particular reason I should look at AS3 rather than AS2 to do this? I am not so far into the game that I can't do a swift rewrite of the basic framework

    Thanks all!

    RM.

  12. #12
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    SWITCH TO AS3 REASONS:
    1) Better performance
    2) More efficient
    3) Proper coding, close to java.
    4) I will be able to help...... XD.


    PS: Incase you didn't read what we all said, DO NOT REBUILD THE ENTIRE MAP, JUST UPDATE THE PARTICULAR TILES AS REQUIRED.
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  13. #13
    Junior Member
    Join Date
    Jul 2010
    Posts
    9
    Hi!

    Sorry about the delay in replying - I have had the most horrible weekend at work....don't ask....

    Anyhow Thanks again for all the replies. I have a really good start made now, and will be posting an example and some code tomorrow when I am not too tired to remember the ftp password to my domain :P

    Re: the AS2 vs AS3 thing.... 90% of the code I have is just logic and operations - very little is actually API stuff. I'm working on seperating it into sections so that if I decide (or need) to rewrite in AS3 it will be very little work. bluemagica - would really like any help you can offer hehe

    Thanks again to all - without this forum I think that my project would be 100x more difficult than it is!

    RM.

  14. #14
    Junior Member
    Join Date
    Jul 2010
    Posts
    9
    Quote Originally Posted by bluemagica View Post
    PS: Incase you didn't read what we all said, DO NOT REBUILD THE ENTIRE MAP, JUST UPDATE THE PARTICULAR TILES AS REQUIRED.
    Oh yeah, I did (finally) figure out that I can just use a different frame of the same tile movie clip.....*slap forehead*

    Thanks!

  15. #15
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    lol...so you finally understood.

    as for as2-as3, You don't really need to separate code sections for as3. You can write it on the timeline the same way you write as2. We generally separate it to get the full power of as3, and for optimization purposes. And that means the arrangement(inheritance,abstaction,...) is a bit different than the general procedural approach of as2, so if you are separating code sections, keep in mind the OOP structure to make the move easier, otherwise it won't be much help.
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  16. #16
    Custom User Title Incrue's Avatar
    Join Date
    Feb 2004
    Posts
    973
    If you ever switch to AS3 it would be easy, make each tile a Bitmap and change the BitmapData reference of them, like
    currentTileBmp.BitmapData = litBmdt ;
    currentTileBmp.BitmapData = darkBmdt ;

  17. #17
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    yeh, I suggested the same thing in my first post here. It is really efficient.
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center