|
-
Senior Member
[CS3] Tutorials on making a game with proper OO
Hi there
I'm writing a series of tutorials on making a space shooter from the bottom up, but the focus is on proper Object Orientation and encapsulation. So this won't be a quick fix. These tutorials are aimed at pre-intermediate programmers who more-or-less understand AS3 but don't know how to organise their code.
If you're a really good coder, I'd love you to have a look at these tutorials and point out any glaring errors or stupidly organised code. It would be much appreciated.
Anyway, the tutorials so far are here:
http://www.flashgametutorials.blogspot.com/
There are five tutorials so far, but many more to come. Hope they come in handy!
-
Senior Member
nice tutorials, continue the good work!
And i have a question too....why did you use getter/setter instead of a public var? I mean, what is the utility of doing this?
And is it a good idea to export graphics to the "first frame"? I think you should do something about it from the very start!
-
Senior Member
Thanks a lot bluemagica!
I answered your question about getters and setters in the blog by accident, this is what I wrote:
I use getters and setters because it makes life much easier in the future - Before the Tragedy I wasn't using them, and it caused all sorts of nightmares as I realised more and more things needed to be done when a change was made to a variable, and I was writing "changeTarget()" functions when really it could have just been a setter. (as in Player.target = someShip as opposed to Player.changeTarget(someship)).
Though this might not be true for all my private variables, I prefer to be safe. If I ever get to a final version of this game, I might make some variables public if they don't need any extra actions performed when changed, because getters and setters are more expensive, from what I've been able to gather...
Maybe somebody could tell us more about this if they're reading.
As for "export to the first frame" I presume you're talking about the blueLightFighterImage symbol. To be perfectly honest, I don't what that option does, other than the game doesn't work if it isn't checked. What's wrong with it?
-
Senior Member
Looks pretty solid, other than CS3 obviously being a terrible code editor
-
Senior Member
Is it so bad? I find it quite nice - automatic indentation, code hints... it's no Visual Studio, but I can't afford both Flash and visual studio...
What would you recommend?
-
Senior Member
It doesn't have even basic features like code completion. Why make beautiful classes when you can't see what they contain without opening the source :P
FlashDevelop -> http://www.flashdevelop.org/ is widely used and free and kicks the crap out of the IDE
-
Senior Member
Oh that looks fantastic.
Unfortunately I'm using a mac, which I know is not the right machine for flash generally, but hey, we all have our crosses to bear.
You are right though - I would love to have my class variables appear as I type. It seems like such an obvious thing to add. Instead I'm stuck with having to give my variables easy-to-remember names, and even then I'm too stupid to remember them...
I'll have a look around for a mac application that does this (doubt it exists, though...)
-
WohOoooooo
Hello, just read your tutorials and they look great. Well written This would have been perfect when i started trying out actionscript 3. good job!
-
Senior Member
Just to answer your "Export in First frame" problem.
What it does is load all the symbols in the library so you can attachMovie them. The main problem this creates is simply for preloaders, as in if you're linking a lot of big images, it will take a while before your preloader even appears!
The work around this is to uncheck "Export in first frame", and then put all the symbols you did this to on the first couple of frames in your movie (but they MUST be put in a frame before the one you actually use them in (I think at least...) ).
NOTE: The movie doesn't actually need to play through the frames, they just need to be there. For example, you can put them all in different frames between your preloader and your menu, and from the preloader you can just gotoAndStop to your menu frame...
Hope that explains well enough! If not, then just give me a shout.
P.
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
Senior Member
This is an interesting problem...
The thing is, I won't have anything on my main timeline - it's all done in actionscript files. I was hoping to have the pre-loader just be another class that is called before everything else, but I don't know how I can call it before the symbols are loaded.
Are the symbols loaded into the movie before the constructor for the document class is called? If not, then I don't have a problem, but if so, I need to figure out a solution...
Thanks for the heads up
-
Senior Member
Hmmm...well I was basing my answer on Flash 8, and...now I realize, non-OOP programming...
Then I think that you need to have them exported in the first frame...not sure though. There might be some AS3 function that allows the dynamic loading of library symbols.
This usually isn't a big deal, and I've never ran into a situation where it really does a noticeable pause between the loading of it. As for as the users will be concerned, the .swf is still actually loading into the HTML.
P.
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
Senior Member
Even in a oop based method, flash isn't going to change how it handles its resources! And hence even if you write a document class for preloader at a higher level than your actual game, it will still delay the preloading, because flash will always load its library instances exported to first frame, first......that is what i have seen in the last game i tried to make! But i guess we will see as you progress.....I suggest you make a small prototype for preloading and see for yourself!
Oh and another thing, you should use event handlers like in cases where you will not remove the handler manually,
addEventListener(event,func,false,0,true);
The last three params will direct it to be automatically cleaned up by flash, after use!
Now, since i have said that, lets get back to my problem:-
What are the "nightmares" that you had with public vars? it helps to know of some possible disaster scenarios, if i want to avoid them!
So far, I have only used getter method, but whenever there was a need for setter, i make it a public var, and have never had a problem with em!
-
Oh and another thing, you should use event handlers like in cases where you will not remove the handler manually,
addEventListener(event,func,false,0,true);
The last three params will direct it to be automatically cleaned up by flash, after use!
very dangerous stuff,- I used to digg 1 month for a issue related to that- in general yes its best to always set your events on low priority so it gets sweeped propper- HOWEVER
never do it with loading dynamic assets as I expierenced it would delete in bigger loops the events for content I loaded. The result was that it stopped loading sometimes sometimes not but quite often online.
The deal was often to load 10-30 images at once or at least multiple ones at once and it kept interupting once uploaded online. So setting the events for the loading assets without the low priority did it for me in the end.
-
Senior Member
Ah yes, good point renderhjs! And thanks for explaining....in my game experiment, i made a avatar system and loaded external images, which sometimes failed to load...after i rewrote the thing with normal type event handlers, the thing worked....but i didn't knew how it got fixed till now!
-
its a bug in the player and the sweep comes to early. What pissed me off is that I found no info on that on the internet even though I searched like crazy. Then someday another AS developer told me about it when we worked together on a project.
-
Heli Attack!
 Originally Posted by renderhjs
its a bug in the player and the sweep comes to early. What pissed me off is that I found no info on that on the internet even though I searched like crazy. Then someday another AS developer told me about it when we worked together on a project.
It is by no means a bug, but it is a repeated problem because of early GC.
You can do a quick solution by creating an array, and when you create your Loader/URLLoader instances, push them into the array.
Once all loading is complete, null the Array.
This allows you to use "false, 0, true" event listeners, but have no fear about the GC taking away your loaders.
-
Senior Member
Hey guys!
Thanks to bluemagica and Pazil I went off on a journey of discovery regarding preloading. Unfortuntately I've had to admit defeat and use the main timeline technique, and this has been the subject of my latest tutorial.
bluemagica and Pazil, you're both mentioned in the tutorial, and I thought I'd link your names to your profile pages on this forum, but I don't want to invade your privacy. Would you mind if I do that? At the moment there's no linking...
And bluemagica, the problems I had with public variables was that I would be modifying the variables from all sorts of other classes, and later this would cause mystery bugs.
This is what would happen in my game before:
ship A targets ship B. so shipA.target = shipB. No problem. shipA.target is a public variable. Then shipA targets shipC. ShipA.target = shipC. Again no problem. Now there are lots of different reasons for shipA to change target - maybe the human player tells it to, maybe it is attacked by shipC and needs to retaliate, maybe it decides shipB has enough other ships attacking it. All of these will access shipA.target.
But then later in development I decided that each ship should have an array of ships targeting it. so when shipA targets shipB, shipB.targetedBy has shipA added to it. But then for some reason shipA.target = shipC. But shipB still thinks shipA is targeting it. So I had to write a function assignTarget, and remember all the places I had written shipA.target = shipC, and replace it with shipA.assignTarget(shipC), and this funciton will tell shipB to stop worrying about ShipA.
I'm sure that didn't make any sense. Just learn from this that getters and setters would have made my life much easier in this context.
Also, as for the GC problem you guys are talking about, I've also experience such unpleasantness with tweens... I prefer to have complete control over when a tween or event listener is ready to be garbage collected...
-
Senior Member
i still don't see how getter/setter made life easier than public variable!
anyway:
About the preloading, i believe the timeline approach wouldbe the simplest and quickest approach, but if you are going oop way, then forget the flash IDE....I love a pretty little thing now, called "flashdevelop", its opensource(+free), and is made with programmers in mind. And its best feature is, it has no timeline(which is the root of confusion in the flash IDE). Next, you can make a class that loads each individual resource externally! And add a preloader to it! I myself haven't experimented much with this so i don't know if you can get a combined bytesTotal for all the resources needing loading, but there are other tricks to hide that detail
-
Senior Member
Alrighty! Just link to: http://psvilans.wrongbananas.net/
Since I just made the site today, there's nothing on there, except my contact address, just so people can ask my questions and stuff...
bluemagica: getters and setters are made to perform other things than just change the variable. It changes the variable, and then the getter/setter methods take care of custom changes to other properties of the object etc.
Thanks Awoogamuffin, and I'll start using your tutorials as soon as I get Flex + Flash Develop set up, so I can start learning AS 3.0!
P.
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
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
|