View Full Version : RTS Help and Updates
flyingmonkey456
July 13th, 2009, 11:01 PM
I'm currently working on an engine for a SC/C&C/AoE style RTS. If I have any questions (which I will) I'll put them here, rather than starting a new thread for each question. I'll also try to post regular updates and screenshots as I progress. Wish me luck :)
Questions:
Get and parse string data from text document?
Updates:
I'm working on basic sprites and terrain right now.
Terrain is done, I'll do sprites later.
I'm working on the terrain generation.
My friend has been at my house all weekend, I haven't had time to work on it.
The map is typed.
Writing the code for rendering the map.
Skribble
July 13th, 2009, 11:49 PM
/digitized Starfox voice sample
"Good Luck!"
bluemagica
July 13th, 2009, 11:52 PM
Also when you have new questions/updates remember to update the first post so that someone doesn't need to go through the whole thread to keep track of what's going on.
flyingmonkey456
July 14th, 2009, 01:16 AM
Would using VCam be efficient here, or should I simulate a camera some other way like moving everything on the map the opposite direction?
also, is there a way to get the symbol name of an object with actionscript? i want each terrain tile to get it's symbol name to determine what kind of terrain it is, then set variables that decide it's properties. things like height, walkability, buildability, and such. i'll also be doing this with units and buildings.
therobot
July 14th, 2009, 01:29 AM
Would using VCam be efficient here, or should I simulate a camera some other way like moving everything on the map the opposite direction?
I would opt for something like this:
http://www.8bitrocket.com/newsdisplay.aspx?newspage=17171
It would help ensure you're not drawing a bunch of stuff that won't be seen, plus bitmapdata is pretty fast sometimes.
zubairclt
July 14th, 2009, 01:29 AM
Video play/pause button
I am playing an external flv movie. I have made a play button and a pause button - everything works fine.
What I need to do is have it so only one button is visible. When the movie is playing the pause button will show. When the movie is paused - the pause button changes to the play button
Any ideas?
flyingmonkey456
July 14th, 2009, 01:59 AM
Video play/pause button
I am playing an external flv movie. I have made a play button and a pause button - everything works fine.
What I need to do is have it so only one button is visible. When the movie is playing the pause button will show. When the movie is paused - the pause button changes to the play button
Any ideas?
create a button object, put that inside of a movie clip object on the first frame. on the second frame of the mc, put the other button object. if the movie is playing, put the mc on the frame that the play button is on, if not put in on the pause button frame. but what does this have to do with this topic? there's a button at the top that says "new thread", use it next time :)
TOdorus
July 14th, 2009, 07:48 AM
Would using VCam be efficient here, or should I simulate a camera some other way like moving everything on the map the opposite direction?
also, is there a way to get the symbol name of an object with actionscript? i want each terrain tile to get it's symbol name to determine what kind of terrain it is, then set variables that decide it's properties. things like height, walkability, buildability, and such. i'll also be doing this with units and buildings.
These are both very expensive ways to go about it. You need that cpu for the AI in your game, which will take up much more. Like TheRobot said, use a bitmap. This makes it only one object to update one time per frame (one bitmap, with locking and unlocking). Also, the use of vectors are a cpu overhead.
About getting the symbol name of an object. Store an integer in an array and compare it with a constant. This way you can only have one object per type, which saves in overhead. Also since there is no need to recreate instances there should be a very slight speedincrease.
class TileMap {
private var theGrass:Grass
private var theWater:Water
//
function createSingletons():void{
theGrass = new Grass()
theWater = new Water()
}
//
function returnTerrain(TERRAINNUMBER:int):Terrain{
var theTerrain:Terrain
switch(TERRAINNUMBER){
case FACTORY:
theTerrain= theGrass
break;
case BARRACKS:
theTerrain= theWater
break;
}
return(theTerrain)
}
//
function returnTopSpeed(MOVEMENTTYPE:int, TILECOORD:Point){
var terrainNumber:int = TileMap[TILECOORD.x][TILECOORD.y]
var theTerrain:Terrain = returnTerrain(terrainNumber)
var topSpeed:int
//
switch(MOVEMENTTYPE){
case FEET:
topSpeed = theTerrain.FeetSpeed
break;
case WHEELS:
topSpeed = theTerrain.WheelsSpeed
break;
case TRACKS:
topSpeed = theTerrain.TracksSpeed
break;
}
return(topSpeed)
}
}
This will work for static instances like grass, sand, water (I'd use a seperate array for storing height). For dynamic instances like a unit or a production building (if you have a system with a local que) this might be less effective, as these can change internally. For these you should use dynamic objects, or else you would need a whole lot of arrays. I would advise a dynamic objects map in which all the dynamic objects store which tiles they occupy. If you would ask a function objectsOnTile(TILECOORD) it could give you which stuff is on the tile. This will also immediatly give you a way to do gridbased collisions.
EDIT
Then again I don't know how a few, fairly big, arrays would compete against one fairly big array filled with objects. I do think the first option is the lightest in memory (less objects, only integers stored) and cpu (only two look ups if you're two dimensionel vs an extra lookup in the object stored in the 2D array)
flyingmonkey456
July 14th, 2009, 08:30 AM
@TOdorus
i need some way to get the name of the symbol. i don't want to have to go through every single tile and tell it what kind of terrain it is. if i can tell the symbol name, the tile will be able to tell what kind of terrain it is and adjust itself. i'm going to be turning this in to a big game with possibly 50+ maps. if all of those are 256x256 tiles, that would be 65,535 tiles per map. going through all of those 50 times would take a whole day, at least, if i even found the time to start.
TOdorus
July 14th, 2009, 09:03 AM
@TOdorus
i need some way to get the name of the symbol. i don't want to have to go through every single tile and tell it what kind of terrain it is. if i can tell the symbol name, the tile will be able to tell what kind of terrain it is and adjust itself. i'm going to be turning this in to a big game with possibly 50+ maps. if all of those are 256x256 tiles, that would be 65,535 tiles per map. going through all of those 50 times would take a whole day, at least, if i even found the time to start.
Erm... I think we're misunderstanding each other here. Why do you want to know the objects name? My point is that it doesn't matter if you store it like an integer or an object, every tileposition needs to have a tiletype stored. If you want your engine to run at any speed (especially with those mapsizes) you're going to use a way of storing which is hard to read by humans. The map format would actually look like this:
public const GRASS:int = 1
public const WATER:int = 2
public var TileMap:Array = [
[GRASS, GRASS, WATER,],
[GRASS, GRASS, WATER,],
[GRASS, GRASS, WATER,]
]
If you find this an inefficient way of "telling each tile what kind of terrain it is", then I'm curious to your way.
Gnoll
July 14th, 2009, 09:25 AM
I agree with TOdorus, tilemaps are going to be done with integers, whether they are stored in arrays or xml or whatever. I want enums in as3 :)
The way you say symbol names makes me think you are doing something with movieclips on the stage in flash or something? With 256x256 tiles you will probably want to use bitmaps like therobot said, and bitmapdata is not 'pretty fast' it is VERY fast, and copypixels will get you the fastest speeds with flash player currently I believe.
Gnoll
therobot
July 14th, 2009, 11:42 AM
Todorus speaks the truth.
Integers are very user-friendly when mapped to constants, and are much lighter weight than strings ( both in memory consumption and read/write speed ).
Edit:
Perhaps this snippet of code is more along the lines of what you meant. You can figure out what class an object is by passing the object reference along to the class in an if statement, like this, using MovieClip as an example:
var box:MovieClip = new MovieClip();
if ( flash.display.MovieClip(box as MovieClip) ){
trace("box is a movieclip");
} else {
trace( "box is not a movieclip" );
}
var object:Object = new Object();
if ( flash.display.MovieClip(object as MovieClip) ){
trace("object is a movieclip");
} else {
trace( "object is not a movieclip" );
}
// output:
// box is a movieclip
// object is not a movieclip
flyingmonkey456
July 14th, 2009, 06:06 PM
alright, it doesn't necessarily have to be the symbol name, i just want something that i don't have to change for every single instance that i can check to get the terrain type. if i could get the symbol name, each tile could simply check that and have a few if statements for each possible symbol name and have the properties for each kind of terrain within the if statements. can i get the name of a bitmap with AS?
also, i've decided to give all attacking units the name "offence_unit#", all non-attacking units the name "passive_unit#" all buildings the name "passive_structure#", and all defensive buildings like turrets the name "defense_structure#". this way, if a unit is surrounded by enemies and buildings, it can distinguish one from another and choose what to attack easier.
one more question, do you guys like the way buildings snap to tiles in most RTS's and if so, how would i do that?
TOdorus
July 14th, 2009, 06:42 PM
alright, it doesn't necessarily have to be the symbol name, i just want something that i don't have to change for every single instance that i can check to get the terrain type. if i could get the symbol name, each tile could simply check that and have a few if statements for each possible symbol name and have the properties for each kind of terrain within the if statements.
But if the terrain is static, it will never change properties right (no health or energy parameters)? I supplied you with code that could actually do that. I don't understand why you insist on looking through a 2D array with movieClips if integers could do the same. It actually makes no sense to do that with bitmaps actually as you would only use one bitmap with one bitmapdata. The movieClips would only take up memory AND cpu. You really need to switch paradigma if you want to be able to pull off the game you have in mind to be somewhat playable. Right now I feel like I'm talking to a wall. Please read through Tonypa's tilebased tutorials (http://tbg.tonypa.pri.ee/)first, before doing anything else.
You don't need to change anything inside your tile classes. You just say that a 1 = a grasstile so when the engine encounters a 1 it will load in the grasstile properties. No need to go through every tile class to add a integer. If you've actually made maps already using objects, then give them up, as your game will be very very slow. In this case your model and view are seperate. The tile you see onscreen is just a representation of a tile in the engine. It isn't the actual tile in the engine. It's completely seperate. Especially with bitmaps.
First you update your game logic (model). Then you loop through the appropiate cells in your grid (the cells that are going to be displayed) and you copypixel everything to the screen in order. No symbols, just pixels which have no meaning for your model. It's just so that humans know what's going on.
You need at least two grids: one for your tiles and one for your units. Buildings can be done by having an exception on the tile grid, but you could also use a third grid. When a unit looks around to choose a target. It checks the cells around him and chooses a target. How would it identify a good target? Simple it loops through the array of all those units around him and compare their HP, their ATT, their ATT/HP etc.
About snapping to grid: just convert the coordinates of the mouse to tilecoordinates and display the building on the actual coordinate of the tile.
therobot
July 14th, 2009, 06:46 PM
why wouldn't you assign a 'type' property to all your objects, whereas type is an int that refers to what object it is.
var TYPE_UNIT:int = 0;
var TYPE_BUILDING:int = 1;
var UNIT_TYPE_ATTACKER:int = 0;
var UNIT_TYPE_DEFENDER:int = 1;
var BUILDING_TYPE_NORMAL:int = 0;
var BUILDING_TYPE_DEFENSE:int = 1;
var turret:Object = {type:TYPE_BUILDING, subType:BUILDING_TYPE_DEFENSE};
var axeman:Object = {type:TYPE_UNIT, subType:UNIT_TYPE_ATTACKER};
Then, you can still assign a unique Id to each object, if you want.
flyingmonkey456
July 14th, 2009, 07:52 PM
@todorus
maybe i'm misunderstanding something. would or wouldn't your code require me to go through every single tile and assign an integer to tell it the tile type? i want to avoid long tedious things like that because there's too much room for error.
@therobot
i'm doing it that way because i can have four different loops running in a certain order to check enemy units. it's easier to check every offensive unit, then every defensive structure, then every passive unit, then every passive structure than to check every unit several times, checking a variable within each unit each time.
therobot
July 14th, 2009, 08:03 PM
@todorus
would or wouldn't your code require me to go through every single tile and assign an integer to tell it the tile type?
No, you wouldn't have to hand code every single tile if you didn't want to. You can assign the type in each class, so you could have 100s of Grass tiles, for example, that are all based off of the Grass class, which you have only assigned a type var one time for.
Even if you were hand-coding your map data, writing ints are still going to be faster than writing out whatever tile it is.
Once you make a map editor, assigning tile types like this becomes trivial.
[[1, 1, 1, 1],
[1, 0, 0, 1],
[1, 1, 1, 1]]
vs.
[["Wall", "Wall", "Wall"],
["Wall", "Grass", "Wall"],
["Wall", "Wall", "Wall"]];
i'm doing it that way because i can have four different loops running in a certain order to check enemy units. it's easier to check every offensive unit, then every defensive structure, then every passive unit, then every passive structure than to check every unit several times, checking a variable within each unit each time.
Your tiles can have a pointer to whatever object(s) inhabit it. Then, if a unit attacks whatever unit is to the left of him, you don't need to loop through every single object in your game to find out what is there. Instead, you would just look to see if the tile is occupied, figure out what unit type it is, and deal out the damage accordingly.
TOdorus
July 14th, 2009, 08:09 PM
@todorus
maybe i'm misunderstanding something. would or wouldn't your code require me to go through every single tile and assign an integer to tell it the tile type? i want to avoid long tedious things like that because there's too much room for error.
That is the case. It is by far more efficient then an array full of objects that would have the same function. You can go ahead and try to keep doing it the way you're doing now, or swith to using integers. I predict much, much lag when you get to coding AI, if you don't optimize your logic in other places. That's why I feel so strongly about you not trying to force your way on Flash as it's quite the cpu intensive method. Me bieng tired for kicking the *bleep* out of a kickbag may also have added to a bit premature response.
Btw: this is why I always do my levels at the end. If you just use a testlevel, you only need to optimze that data if you decide that a certain way of storing is more effective. This not only goes for tilemaps, but also AI instruction and the like.
@therobot
i'm doing it that way because i can have four different loops running in a certain order to check enemy units. it's easier to check every offensive unit, then every defensive structure, then every passive unit, then every passive structure than to check every unit several times, checking a variable within each unit each time.
Actually you'd only need one loop where you check multiple things at once.
Get all the units, structures etc around the unit in an array. Just update the most something type everytime. Like: if it is a defensive building, check if it is a better defensive building than the best one found yet. If it is a offensive unit, check if it is a better offensive unit then the bes one found yet. Do note that this can also return no best defensive building or best offensive unit when there are none around.
Another way would be to ***** how good a target something is. Store a score for targetitbilty and again, update it when you find a better target.
EDIT: a-s-s-e-s is censored? Hilarious:hugegrin:
TOdorus
July 14th, 2009, 08:14 PM
No, you wouldn't have to hand code every single tile if you didn't want to. You can assign the type in each class, so you could have 100s of Grass tiles, for example, that are all based off of the Grass class, which you have only assigned a type var one time for.
That is the case. It is by far more efficient then an array full of objects that would have the same function. You can go ahead and try to keep doing it the way you're doing now, or swith to using integers.
Before we go miscommunicating here.
By coding a tile, do you mean editing a tile on a map, or coding the tile class?
flyingmonkey456
July 14th, 2009, 09:38 PM
okay, i should explain my targeting system. each unit will be checking the tiles in its vision for enemy units. if a unit is sighted, it's name is set as a variable called "target". "target" is then attacked by the unit until it is dead, and a new target is chosen. i need four different loops so that it can check for offensive units first, then offensive structures, then passive units, then passive structures. that way he will always attack the biggest threat first. the only problem i have with this is if unit1, unit2, and unit3 all come into the vision of an enemy unit at the same time, that enemy unit will always attack unit1 because the loop would be checking them in order of their number. perhaps i could add them to an array and pick a random one to attack...
i will probably have a "strategy" panel where you can set how you want units to act. things like attacking the first thing it sees, attacking the thing with the lowest/highest hp, attacking the closest thing, attacking buildings before units, not doing anything unless you tell them, etc. i'll have to write a different set of loops for each of these. i will have manual targeting also. if the player clicks an enemy unit or structure, all selected units will attack it until it has either died or a new target has been selected.
bluemagica
July 14th, 2009, 10:55 PM
I think you should slow down a bit, and plan the thing a bit more before you dive into coding this!
1) If you are using AS3, good, otherwise go bang your head three times on the keyboard, then get as3!
2) Make a "tile_ref" class, this is not an object class, rather you should use this as a lookup table for the various tile types! You can always make a "tile" class, and give properties to your tile objects, but well, that approach can be a bit memory heavy! And you don't exactly need that for a normal RTS game!
3) Next, generate you map array! You can use algorithm based generation like AoE, or a tile editor, it's upto you, but the important thing is the map format! Typically you will use the 2d numerical array like theRobot said up there, or if your map needs saving or is getting heavy, you can move to bytearray later!
4) For each enemy, run 1 loop, create a temp array, and push info about every object is sees in that array! Then once you have done one loop(cheacked 360 degrees), pick one target from the array based on the priority!
flyingmonkey456
July 15th, 2009, 12:10 AM
@bluemagica
i do have it planned out, i have a giant list of every unit, building, weapon, upgrade, etc. this is just an engine though, so i really only need 2 or 3 buildings and units.
1) i'm currently learning as3, there are a lot of differences from as2 and i don't know it well enough to switch.
2) i'm still figuring this part out, i'm trying to avoid long tedious things like adding a different variable to each tile, that leaves a lot of room for error. i'll probably even have the tiles instance name themselves based on their position.
3) this is just an engine, i'm not using a very advanced tileset. it's all solid-color isometric squares. i don't need random terrain generation or anything.
4) it's only going to check the tiles in it's vision. there's a formula i can use to find the tiles in its vision and no others. every tile will store any unit touching it in an array. the unit can tell what enemies are touching the tiles it can see and adds them to an array of visible units. i just got an idea, i'll store offensive units in one array, defensive structures in another, etc. this way there is no looping involved. i can simply choose a random unit from the first one unless it's empty, then i go to the second one, etc. anyone see any problems with that system?
@todorus
assess? you spelled it wrong :)
and my method didn't involve arrays, each tile would get its symbol name and determine its properties through if statements. all of this would only happen once on load so it only lags a little at the very beginning of the level. i still don't know if it's even possible to get the symbol name. i've done google searches and got nothing useful, and nobody on here seems to know how. i still don't know how the bitmap thing would work, code can't be added to them (can it?) so i would have to have several arrays containing the properties of each tile. then i would have to have more arrays storing what units are touching what tiles. i don't see how that's better than my method.
i just realized something. i hate coding walls, and i don't have to in this game. all of the units will use ai to move, so i just have to pathfind around walls, buildings, units, etc. :)
btw, this will be a standalone game. otherwise, there would no doubt be lag. i'll probably upload trailers online that show some cutscene type stuff once it's completely finished, but the rest will only be downloadable.
TOdorus
July 15th, 2009, 07:22 AM
assess? you spelled it wrong :)
Oops :)
and my method didn't involve arrays, each tile would get its symbol name and determine its properties through if statements. all of this would only happen once on load so it only lags a little at the very beginning of the level.
I still have to assume you're using movieclips as you keep referring to symbols. TheRobot already gave you a way to determine the class of an object. This could also be done by extending the movieClip class.
i still don't know if it's even possible to get the symbol name. i've done google searches and got nothing useful, and nobody on here seems to know how. i still don't know how the bitmap thing would work, code can't be added to them (can it?) so i would have to have several arrays containing the properties of each tile. then i would have to have more arrays storing what units are touching what tiles. i don't see how that's better than my method.:)
I can tell some here have had experience with making advanced tilebased games. We keep telling you this is not going to be fast enough, but that still makes you totally ignore them. Instead you have a method which I still don't understand. You're having a set of movieclips in a level, each movieClip bieng named after it's position? (tile1_4 woule be at position (1,4)) I can only guess. If that's the case the engine is artbased as it functions on art rather then a model.
Two of your questions show me you won't be able to grasp the concepts needed to pull of a rts with a decent framerate.
"so i would have to have several arrays containing the properties of each tile"
One 2D array filled with integers. I've posted the code that you'd need to make that work with one 2D array.
"i don't see how that's better than my method"
Speed for one thing. Not only is an array much faster then a movieClip, a 2D array doesn't need to be rendered to the screen even if it's offscreen.
Smaller data size.
Easier to edit.
You can easily check units bigger and smaller then a tile.
You can easily wipe an array, by creating a new empty one. (You'll see the advantage when you start to get to pathfinding)
You've obviously didn't read Tonypa's tutorials which explains the concepts we try to hammer into to you. You can say that we should help you develop your method, but there's a reason why some methods have become the standard. I've tried using named movieClips to get positions. It failed horribly and abondened it real quick. I've tried using a 2D array with integers and movieClips for display and found it can't handle to much on the side(we're not even talking an algorithm here, it really can't have anything on the side). I've tried using a 2D array and a bitmapData for display and found it to not even use 1% of processing power when there's no AI. If you insist on repeating that mistake then fine, but I've come to the conclusion that further posting in this thread is useless as this isn't a discussion, it's a debate.
Either explain your concepts clearly, because it's obviously far from the standard methods known for tilebased games, or try to understand the concepts Gnoll, therobot and I are trying to explain to you. If not this thread has become useless in my opinion.
EDIT: Lag doesn't only apply to a network connection. If the Flash application has trouble doing it's calculations in one frame, the gametime "lags behind" realtime.
flyingmonkey456
July 15th, 2009, 08:59 AM
@todorus(obviously)
i'm not ignoring you. i'm just trying to find the best way. you haven't really explained your method well enough either, or i would understand it. i did read part of the tutorial, maybe 3 or 4 pages of it, all of the other stuff in the side bar looked like it was specifically for an rpg.
i'm not very familiar with bitmapdata, i've only used it for very small things. if you know any good tutorials on it, link please :)
i think i'm starting to understand your method a little more, but i'm still a little bit confused. you said you would only need one array, but doesn't that array contain several arrays? also, would i have to "draw" the entire map with code? because that leaves a LOT of room for error and i really, really want to avoid lots of alpha testing.
Gnoll
July 15th, 2009, 09:43 AM
you said you would only need one array, but doesn't that array contain several arrays?A 2d array (Also called multidimensional or an array of arrays), so yes, an array containing several arrays
I now think you are manually drawing the map or something? Actually I would say this is going to be WAY more time consuming, and has A LOT more room for error. How will drawing the map with code have any room for error once you have perfected the method, and really it is just going to be something like (If you insist on using MovieClips):
ActionScript Code:
//map is a 2d array [[1,1,1][1,0,1][1,1,1]] or something
private function draw(map:Array):void
{
for (var y:int = 0; i < map.length; i++)
{
for (var x:int = 0; i < map[y].length; i++)
{
//switch to decide which movieclip etc (TIle is your movieclip or somethin)
var tile:Tile = new Tile();
stage.addChild(tile);
tile.y = y * tile.height;
tile.x = x * tile.width;
}
}
}
Something along those lines anyway, and if all your tiles are the same size, it should be perfect. This is what a real tilemap is, else you are just manually drawing an image, with the use of tiles. It is also much much easier to then change a tile, and create your own editor etc.
Good luck,
Gnoll
p.s For a big rts you will most likely need to go with AS3 (and it is great and easy to learn anyway), and if you are thinking about using really large maps, use the new Vector class (People say no, but most users will / can get FlashPlayer 10 now) I have heard it increases speeds by 3-4 times.
var map:Vector<int>;
TOdorus
July 15th, 2009, 09:52 AM
@todorus(obviously)
i'm not ignoring you. i'm just trying to find the best way. you haven't really explained your method well enough either, or i would understand it. i did read part of the tutorial, maybe 3 or 4 pages of it, all of the other stuff in the side bar looked like it was specifically for an rpg.
(...)
i think i'm starting to understand your method a little more, but i'm still a little bit confused. you said you would only need one array, but doesn't that array contain several arrays? also, would i have to "draw" the entire map with code? because that leaves a LOT of room for error and i really, really want to avoid lots of alpha testing.
Well TonyPa does a good effort to explain it ;) . Well technicly you're right. A 2D array is an array containing lots of other arrays. An even more effecient way would be to use just one array and use modulation, but that is some optimizing that is saved for later on when your engine works like you want. The thing with stuff that has fast execution, is that it most of the time isn't really easy to read by a human. So a pc has less trouble with it, but a human has. But you really can build a test level quite easily by creating an array full of 1's (if 1 is a standard grass kind of tile) and copy that array a few times. Then you can add some water/walls or other terrain you can use for testing. Later on you can build a level editor or use an existing editor, to make editing bigger levels feasable. I never gotten the 3rd pary editors to work for me, as I couldn't understand how to edit the mapformat it exported, but you could always try.
The thing is, that your engine may work for now and save you some trouble, but I think you'll be dissapointed when you get to a phase when you start to add AI and particle effects and whatnot and you notice that your game starts to lag. Instead of chucking it or be very demotivated to go back to the drawingboard and try again, you could do the extra trouble now and have an engine that you can actually finish (and is easy to port to AS3 too btw). So you say you don't want to do that much Alpha testing, then I say you're going to have to scale down your goals quite a bit. The goals you've defined (256x256 maps, some advanced AI) needs some work in setting up a engine with a solid basis.
i'm not very familiar with bitmapdata, i've only used it for very small things. if you know any good tutorials on it, link please :)
TonyPa goes into it in those tile tutorials. 8bitrocket is known to have the best tutorials (plural) on this subject. Last and least I've posted something on here in this thread (http://www.kirupa.com/forum/showthread.php?t=324447).
p.s For a big rts you will most likely need to go with AS3 (and it is great and easy to learn anyway), and if you are thinking about using really large maps, use the new Vector class (People say no, but most users will / can get FlashPlayer 10 now) I have heard it increases speeds by 3-4 times.
var map:Vector<int>;
I've actually looked around the internet a lot for benchmarks on this subject a few eeks ago doing some research to improve my own engine. At the moment my conclusion is that vectors seem to be just as fast as arrays when using an array like this:
var theInt:int
var i:int
var Length = theArray.length
for(i = 0; i < Length; i++){
theInt = theArray[i]
}
The advantage of vectors are that they're hardtyped, so the program doesn't first have to figure out what type it is dealing with. By using a hardtyped variable this problem is circumvented and the array and vector lookups are about as fast. Since I already coded this way (makes it easier to debug), there's yet no need for me to switch to vectors for tilemaps.
Gnoll
July 15th, 2009, 09:56 AM
Yes, and making the program not having to figure out the type increases speeds :P I saw a good benchmark on using int / number / untyped for storing numbers, and I think int was like 40 * faster than untyped, and uint was surprisingly around 200 * slower or something :P
Going to bed now but I will see if I can find it tommorow,
Gnoll
Charleh
July 15th, 2009, 10:02 AM
In most games out there, the level data is saved into some file format, then loaded at run time to generate the level procedurally (in code).
I get the impression that you are thinking of hand dropping every single tile onto the map and typing the instance name into the box etc etc.
This is not the way forward. You want a file format that your game can interpret, which then generates the level based on the contents of the file.
You can then create your own editor which can be a visual representation of the level which you drag/drop tiles onto, which then generates your level files. Of course you don't NEED it to begin with, this can be some of the later things you do once your engine is rendering tiles properly.
I think you need to gain some background understanding in the methods presented by the posters here and ask questions, and I think everyone needs to step down a little on the technical notch and start with the basics, as I get the impression that some of these are not grasped yet..!
TOdorus
July 15th, 2009, 10:40 AM
I think everyone needs to step down a little on the technical notch and start with the basics, as I get the impression that some of these are not grasped yet..!
Ah yes hindsight. I think we all realize that now. It's just that TonyPa has done so much for tilebased gaming in Flash that I just assume everybody that wants to create a tilebased game is up to speed with some concepts. Especially if you want to up it a level and go for a rts.
PS: gnoll, I'm looking forward to that link
Charleh
July 15th, 2009, 12:32 PM
I think with all good intention people have posted their methods but we all first need to establish whether the OP knows the best methods for creating a rendering engine and understands the concepts of separating engine/graphics/behaviour etc into distinct layers, as well as the concept of 'virtual' objects and their visual representation on screen.
Often new games programmers that begin using flash are spoiled so much by the flash canvas, and the readily available drag and drop and instance naming functionality that they don't understand the concepts behind what's going on in the IDE. The fact that Flash is creating a set of objects in memory which contain the positions and names of all the movieclips etc and the code within, is important to help understand the concepts utilised when creating a game engine and your own object structure and potential 'level' format.
Also the Flash IDE is optimised to use vector graphics and supports a very useful 'movieclip' object for this purpose, which implements scaling, rotation etc etc (due to it's vector nature). Of course, this is fine for very simple gaming, but performs very badly compared to sprite based rendering which is needed for a tile based game due to the number of discreet objects which need to be rendered. The Flash IDE is primarily a designers tool - it should not be used as a level editor for a tile based game. Of course there is always the possibility of your engine parsing a flash 'frame' object which you have placed movieclip instances on, removing these instances then creating the proper game objects in their places - but of course you need to make sure your objects are correctly positioned and this is best done via the same rendering pipeline and using the same content placement rules that the engine (e.g. snapping to grid of tiles in the editor etc).
So in essence, the OP needs to understand that they must implement a tile based engine which uses bitmapdata objects for rendering (emphasis.. for rendering) and doesn't rely on Flashes stage object for the positioning of tile data as it's not the correct tool for the job. People have tried using movieclips for rendering, and as everyone has posted, they do not perform well. Yes they are convenient, but they are SLOW. Get 20 tanks on the screen and you are asking for low frame rates.
Optimisation is very important for Flash games as at the moment, no rendering is done in hardware so vector rendering is expensive (does FP 10 support hardware accel yet?)
flyingmonkey456
July 15th, 2009, 04:05 PM
@all
i was originally going to place every tile by hand, i'm a more visual person. with this way, you're saying to make an array that contains all of the data for every tile and have the code draw the map based on that. i have figured out a way, thanks to charleh, that i can combine both of these ways. i will draw the code with numbers and letters in a notepad document or something and use that to draw the map :D
i would have a number that tells the height first, then "draw" the map in a single line (i can use word wrap to keep it square), then just break it up and get the tile type and position with hardly any work at all:D
and hardly any alpha testing on the maps :D :D :D
@gnoll
i didn't insist on using movie clips for any better reasons than you've given for using bitmaps. thanks to todorus, i know WHY bitmaps are better. oh, and is flash 10 the same as cs4? because that's what i've got.
@todorus
thanks for the links, i must have missed something in tonypa's tutorial. i read a little bit on bitmapdata, but not anything i couldn't gather from posts i've read and the little bit i've used already.
@charleh
thanks :D
@todorus(again)
i have a firm grasp on the logic behind everything, i'm just kind of new to AS. i've known AS for a little more than 6 months, but i knew C++ before that.
@charleh(again)
when i used C++, i did a lot of command prompt stuff with no canvas or visual representation or anything. i was actually a little deterred from using the canvas at first, but it's just so darn useful :P
Sirisian
July 15th, 2009, 05:10 PM
So in essence, the OP needs to understand that they must implement a tile based engine which uses bitmapdata objects for rendering (emphasis.. for rendering) and doesn't rely on Flashes stage object for the positioning of tile data as it's not the correct tool for the job.
Exactly. If you are using movie clips or sprites stop. You should have only 1 object on the stage. A single bitmapdata object the size of the game screen. Rendering bitmaps to that bitmap is insanely efficient. (Especially if you cache rotations if you have them. I highly recommend this).
Also bitmap rendering isn't just for making rendering faster. It greatly reduces the complexity of your code. Not sure if you're implementing a spatial partitioning for entities, but if you are you end up just iterating through the objects after culling them to the camera.
Also since you started programming an RTS, I'll assume you have a solid understanding of OO design patterns. In an RTS you'll run into the factory pattern probably along with others. If you don't run into them chances are you are doing things the hard way, so look them up and read them and see if any fit. (Stay away from singleton, if you don't know why you will in time).
Oh yeah and if you choose to dynamically load your images then you can always look at my old texture manager class (http://www.assaultwars.com/flash/texturemanageras3.zip) for loading images one after another.
I'll probably look in on this thread from time to time. Looks like an interesting project. Can't wait until you get to generating the pathfinding graph. It's always interesting how people tackles those for RTS scale pathfinding. (Not to mention the AI involved. Not sure if you've ever seen an influence map. It's a neat optimization for quickly deciding spheres of influence for groups).
Good luck :)
Charleh
July 15th, 2009, 05:24 PM
Not a fan of singletons Sirisian? Why's that?
I tend to use them when I want global access to a set of objects (usually application settings etc)
TOdorus
July 15th, 2009, 05:36 PM
Not a fan of singletons Sirisian? Why's that?
I tend to use them when I want global access to a set of objects (usually application settings etc)
Same here. Also when I use tiles with static properties I use singletons the way I've posted in this thread.
flyingmonkey456
July 15th, 2009, 05:53 PM
okay, i have this almost figured out :)
if i had just immediately agreed that your way was the right way, i never would have to had the idea to draw it with text and i would currently be writing a very long series of arrays.
just a few questions.
1) how do i get and parse a file?
2) can you link to a tutorial on bitmapdata in general, i can't find one anywhere T_T
3) should buildings and units be bitmaps too?
i'll keep posting updates on how it's going, i don't think it will take very long.
the next thing i need some help on is map scrolling. just reading a bitmapdata tutorial would probably be enough for me to figure out how to do that, though.
Gnoll
July 15th, 2009, 06:52 PM
Here is a tutorial on blitting (rendering your bitmap data in an efficient way) http://www.8bitrocket.com/newsdisplay.aspx?newspage=13430
You will also find tutorials on tile maps on that site,
theRobot linked this: http://www.8bitrocket.com/newsdisplay.aspx?newspage=17171 which might help with your scrolling. Buildings and units should be bitmaps to.
Loading and parsing a file? URLLoader? If you use plaintext you can split the text with a predefined width (or use a header with the width) or use xml which will be larger but probably easier to define settings for your map. In the end you will want to create a map editor in flash which exports the text etc for you, you don't really want to depend on wordwrap for editing maps :P
Good luck,
Gnoll
therobot
July 15th, 2009, 07:03 PM
i don't think it will take very long.
:D
Sirisian
July 15th, 2009, 07:07 PM
2) can you link to a tutorial on bitmapdata in general, i can't find one anywhere T_T
You're not going to find any. Why? Because it's so trivial. Read this fully. (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html) Done? Okay you saw the function copy pixels. You might be wondering why this is fast. It's optimized. Notice how it says "Provides a fast routine to perform pixel manipulation between images with no stretching, rotation, or color effects." There's something special about that. When you need scaling and rotating you have to perform a per pixel matrix operation basically to transform the image. This is why BeginBitmapFill in the graphics object has overhead. Also it doesn't do any pixel color transforms. Without doing this you are basically just copying some memory over another set of memory. This means it's fast. So in conclusion copy pixels.
You might be wondering what I meant by caching rotations. Basically rotate an image and render it to a bitmap data. The operation is pretty easy. If you need it just ask and I'll explain it.
3) should buildings and units be bitmaps too?
Yes. All objects should be stored in a bitmapdata so that you can copy them to the main render bitmap.
Not a fan of singletons Sirisian? Why's that?I'd rather not go into it. If you aren't seeing any drawbacks (http://en.wikipedia.org/wiki/Singleton_pattern#Drawbacks), then don't worry.
// Edit too slow. Looks like there are some tutorials. Things have changed. But yeah they just show copy pixels.
Gnoll
July 15th, 2009, 07:16 PM
Yea it is pretty simple, long as he understands the concept of having a 'Bitmap Stage' per se,
I found a similar benchmark to the one I read here http://www.gskinner.com/blog/archives/2006/06/types_in_as3_in.html,
16777215 iterations of a for loop:
int: 24-26ms
Number: 31-36ms
uint: 105-225ms
untyped: 380-430ms
Sirisian
July 15th, 2009, 08:07 PM
Yea it is pretty simple, long as he understands the concept of having a 'Bitmap Stage' per se,
I found a similar benchmark to the one I read here http://www.gskinner.com/blog/archives/2006/06/types_in_as3_in.html,
16777215 iterations of a for loop:
int: 24-26ms
Number: 31-36ms
uint: 105-225ms
untyped: 380-430msHere's a tip. Don't worry about micro optimizations. Your time is better spent on algorithm design. Instead of worrying about what type you use to iterate you'd be better questioning why you need 16777215 iterations of a for loop.
Gnoll
July 15th, 2009, 08:34 PM
Maybe he uses really small tiles and has a 16,000 * 1000 map :D
I was just demonstrating that typing makes a difference,
Gnoll
Charleh
July 16th, 2009, 11:09 AM
i don't think it will take very long.
Famous last words :D
flyingmonkey456
July 16th, 2009, 10:32 PM
Famous last words :D
i don't mean the entire engine if that's what you're thinking, just the map generator.
Charleh
July 17th, 2009, 05:36 AM
Haha, it's pretty much a rule in development in general, always multiply the amount of time you think it will take by three, then add half again :D
flyingmonkey456
July 20th, 2009, 10:16 PM
Loading and parsing a file? URLLoader? If you use plaintext you can split the text with a predefined width (or use a header with the width) or use xml which will be larger but probably easier to define settings for your map. In the end you will want to create a map editor in flash which exports the text etc for you, you don't really want to depend on wordwrap for editing maps :P
Good luck,
Gnoll
i have the map typed out now, can you explain urlloader a little more? can it load a file from your computer or does it have to be online? is there a way to get a set number of characters from a string or only the characters from a certain line? i need to include the map width in the text file so it knows how to arrange the tiles. if i can get a set number of characters, i can have the width be the first 3 characters, and every single number after that represent a single tile. if i can get only a single line, it would make it much easier as i could simply separate the width value by putting it on a different line.
Gnoll
July 20th, 2009, 11:17 PM
You can load local files or online files if you allow network access in your compile options. You could put commas in your text file and use string.split(','). Alternatively you could save your maps as xml allowing you to add properties like map width etc easily (+ map id, name or whatever).
Gnoll
Here is a short example: http://theflashblog.com/?p=242
flyingmonkey456
July 21st, 2009, 02:43 AM
You can load local files or online files if you allow network access in your compile options. You could put commas in your text file and use string.split(','). Alternatively you could save your maps as xml allowing you to add properties like map width etc easily (+ map id, name or whatever).
Gnoll
Here is a short example: http://theflashblog.com/?p=242
thanks for the link, how would i put the information in an array? nothing in the link says anything about that, and you only told me how to break it up.
Gnoll
July 21st, 2009, 03:08 AM
That link is for xml, if I was using plain text I would do something like this:
My text file:
1,1,1%
1,2,1%
1,1,1
Code to make it an array:
var str:String = e.target.content;
var map:Array = [];
for each(var i:String in str.split('%'))
{
map.push(i.split(','));
}
Didn't test that so I might have made a mistake but you get the general idea
Gnoll
Edit. That was horribly wrong, fixed I think
flyingmonkey456
July 21st, 2009, 03:59 AM
@Gnoll
lol, i was replying to better walls so i didn't even read the wrong post. that makes sense, thanks. does is have to be commas and percent signs, or can i just replace the red text with any character?
Gnoll
July 21st, 2009, 04:04 AM
Any character, just two different characters that won't interfere with your tile id's or whatever :) You could use multiple characters to like \n for each line or whatever you want.
Gnoll
flyingmonkey456
August 24th, 2009, 09:20 PM
i haven't posted here in a while, i've been busy with other projects. i've come up with a possible solution for fog of war that i hadn't thought of before.
one bitmap is used, the visible fog of war bitmap. every frame, the program finds the units and their sight ranges and changes transparency of the pixels based on their distance from the unit. the ones close to the edge would start fading to completely opaque. this can be determined by mathematical equations. the pixels being viewed would be added to a 2d array along with their transparencies. if they are already in the array, their transparencies are checked. if the transparency of the one being added is higher than the one already in the array, the old transparency is spliced and the new one is pushed in it's place. this way, the edges of areas that are not currently visible, but have been seen, can still be fuzzy.
before any of that happens though (i'm saying is out of order because the last thing has to happen before the first one can work) it goes through the array and changes the transparencies of the pixels in it to the stored transparencies, plus about 50% transparency to make them darkened. this way, it's making all of the shaded pixels first, then making all of the transparent ones so it doesn't erase the visible ones when it goes back over.
i hope i'm not missing anything holes in this, it sounds pretty solid to me. if anybody sees any problems or thinks that having isometric black tiles of variable transparency with glow filters over every tile would be faster, let me know :)
TOdorus
August 25th, 2009, 07:21 AM
are you talking about doing the distance calculations on a per pixel basis? That's mighty ineffecient as say you would have a tilewidth and height of 16, you would need to check 16^2 times as much. You can still use tiles in a bitmapdata, just have a tilesheet of different transparancies and copypixel from it.
flyingmonkey456
August 25th, 2009, 06:20 PM
my problem with the method with glowing black tiles is that glow filters use a lot of memory, don't they? the bitmap tiles is a good idea. one question, though. i'm trying to keep the fog of war as one solid bitmap, if i copypixels something with transparent or translucent parts will it show what's behind the transparent/translucent pixels like looking through a window or would it just be transparent/translucent like what i'm copying?
TOdorus
August 29th, 2009, 07:36 PM
my problem with the method with glowing black tiles is that glow filters use a lot of memory, don't they? the bitmap tiles is a good idea. one question, though. i'm trying to keep the fog of war as one solid bitmap, if i copypixels something with transparent or translucent parts will it show what's behind the transparent/translucent pixels like looking through a window or would it just be transparent/translucent like what i'm copying?
Just look as them as layers and you keep putting layers on top with every copypixel. So if you have a bitmapData which is totally white opaque, than you won't see what's behind it. If you copypixel on that of a transparent graphic, then you will see the white opaqua background through the graphic. You could use a totally transparent bitmapData instead, but you'd probably need to create a new one each frame. Not mighty efficient, but it still beats going over every pixel.
flyingmonkey456
August 30th, 2009, 09:34 AM
Just look as them as layers and you keep putting layers on top with every copypixel. So if you have a bitmapData which is totally white opaque, than you won't see what's behind it. If you copypixel on that of a transparent graphic, then you will see the white opaqua background through the graphic. You could use a totally transparent bitmapData instead, but you'd probably need to create a new one each frame. Not mighty efficient, but it still beats going over every pixel.
i do need to use a transparent bitmap, you have to be able to see the map under the fog :P
TOdorus
August 30th, 2009, 12:46 PM
You could use a totally transparent bitmapData instead, but you'd probably need to create a new one each frame. Not mighty efficient, but it still beats going over every pixel.
Total brainfart. You should still be able to use fillrect to make it transparent again.
i do need to use a transparent bitmap, you have to be able to see the map under the fog :P
I know, but I though you were talking about using a bitmapData filled with a certain tile (like explored with fog of war), as that tile would probably be needed most of the time. Then you would replace the tiles with transparant tiles. As far as I know, that isn't possible.
flyingmonkey456
August 30th, 2009, 01:28 PM
I know, but I though you were talking about using a bitmapData filled with a certain tile (like explored with fog of war), as that tile would probably be needed most of the time. Then you would replace the tiles with transparant tiles. As far as I know, that isn't possible.
i don't want to be keeping track of a thousand different bitmaps every frame, but i guess it would be more efficient than keeping track of every pixel. if i put a bitmap with transparent parts over another bitmap, i know i'll be able to see the bitmap underneath through the bitmap on top. that's the way i'll do it, then.
oh, by the way. i decided that the terrain tiles will be squares so the bitmaps will be easier to work with. they'll still look isometric when you put them together, though. i'll also be using squares for the pathfinding. nothing in the code will have to deal with isometric tiles other than the fog.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.