|
-
[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.
-
What version of Flash and AS are you using?
How are you putting the tiles on the stage?
-
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.
-
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.
-
Pumpkin Carving 2008
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
-
Senior Member
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: 
-
Hype over content...
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.
-
Senior Member
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: 
-
Hype over content...
mc's are quicker than blitting in as2.
Blitting should only really be used as a last resort, not the default.
Squize.
-
 Originally Posted by RitualMagic
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
-
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.
-
Senior Member
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: 
-
-
 Originally Posted by bluemagica
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!
-
Senior Member
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: 
-
Custom User Title
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 ;
-
Senior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|