After writing a couple of new classes, I noticed how weak my small library of classes is. I figured maybe we could start a collection of classes for anyone here to use.
So here's one of my very early classes. This arrow class acts like a bullet but is affected by gravity and rotates towards the ground accordingly.
It's super basic, but does the job nicely I'd like to think - it should be a nice addition to anyone just starting to build up on their library.
If anyone's willing to share a class or two, I think we could get a pretty sweet FK collection happening. It doesn't matter how easy or complicated the class is; if you think someone will find it handy then upload it.
Viza.
P.S. Sorry about my bad coding habits and lack of OO principles. Hopefully after seeing some 'proper' OOP from anyone else's classes I'll be able to improve.
What a great idea ( An even better one would be to set up a svn somewhere to put all these ).
I've attached my soundClass, which has been making beeps beep easily for quite a while ( I think it was first coded for Polarity, and has managed to see me through to Landfill of Doom without any major updates ).
The one really nice method in there is createPlayAndDispose() which is just a really simple way to trigger those one off sounds, for when you're feeling lazy or rushing to get something done.
I've attached it as a txt file 'cause of the nature of the board, and as a caveat it's as2 ( I need to port all these old library classes to as3. Joy ).
Great idea, Viza!
This is the class I've reused the most, BitmapScroller. Only thing that
kind of sucks is that it requires a 2d array for the map, but this could
easily be changed.
Here's a modest polygon class that supports clipping to an arbitrary convex window using the Sutherland-Hodgman algorithm. It also can compute the convex hull of a set of polygons using the gift-wrapping algorithm (Jarvis march). There's an example driver program too.
Lesli, SVN is not an FTP server. The features that SVN offers are very interesting for these kind of projects. Especially when things get bigger and you loose track of everything.
Maybe someone could set up an SVN on sourceforge or GoogleCode (is it GoogleCode? I dunno).
I was thinking of organizing it somehow like this:
flashclasslibrary.as2.etc
flashclasslibrary.as3.etc flashclasslibrary.testbed.as2.etc
flashclasslibrary.testbed.as3.etc
I've used SVN. I know what it can do. It's horrible.
It's taken me a whole morning to rename a folder using svn, and I've lost work that didn't get put in the recycle bin (svn doesn't put anything there because it thinks it's clever enough to stop you from losing your work... even work it tries to delete from your system that you haven't checked in)
Sure, I can roll back my work to seven versions previous. But there's no need because of all the copies I've saved outside of svn because the svn server kept crashing or a designer wanted to review my work and didn't know what version control was.
Of course, svn does allow two coders to edit a class at the same time and merge their updates into one class file that doesn't work any more. Useful for making projects go on for longer and charging the client more.
Hmmm... Seems like not many have the sharing spirit.
Here's a Ball class. You could use this for all sorts of things ( mainly ball-on-ball collisions). Attached in the .zip file is a fully commented class, .fla file containing temp gfx, and also demonstration code to get something working instantly.
I'd like to take credit for all of the smart things in that class, but unfortunately this clas was mainly written by someone else and I've just made personal adjustments and small function additions. I'm sure he wouldn't mind me sharing this, since I obtained it through his blog which was freely distributing it anyway.
While I think this is a great idea, Viza, I don't have any classes that aren't custom for the content I'm using them for. Not too many of the classes I've wrote have been reusable.
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
I've had some bad times with svn too ( Makes it sound like it touched me when it was drunk, and was then all apologetic in the morning ).
But for something like this I think it's pretty ideal. We've recently set up a repository for gyw where Olli and I are going through the hell of porting existing code to as3 ( We're trying to avoid re-inventing the wheel. Twice over ).
To just share common code it's pretty good, it's just when you're doing a huge project with it it's a mare and easy to really badly mess things up.
Also, this thread is a bit lacking in content. No one else wanting to share ? Surely after all the recent as3 advocates around here, loving the oop'ness of it, there should be a ton more general classes out there which are easy to re-purpose.
Y'see this is the thing, I've got loads of code snippets and functions I re-use. About half mine, half not, few of which are game related. The ones that are game related are real simple (shuffle an array, get distance between points etc)
That said, I'm working on a RecordedObject Class, which simply takes the MovieClip class and makes it east to store all of its properties per frame so it can be rewound, played back etc. A RecordedScene class will handle the whole thing and store information and govern playback controls.
If I ever finish it and put it to use, I'll post it here.
This thread, or one like it, without all the ranting, would be ideal for a sticky, as it'll take a while for people to post to it, and people will need to come back to it over again.
Also, this thread is a bit lacking in content. No one else wanting to share ? Surely after all the recent as3 advocates around here, loving the oop'ness of it, there should be a ton more general classes out there which are easy to re-purpose.
Squize.
I've got a couple of useful classes, but they're usually more of a package than a stand alone class. My scrolling engine is 8 classes right now, and even though it's very useuable, it's not finished. Same with my platform engine, or my tweening stuff, or my (now a bit dated) pathfinder. (EDIT: sounds like I'm bragging with my stuff, but just wanted to say that while I want to share something useful, I don't have many single classes that are useable without context, and most of my stuff is designed for eachother).
But just because I want to share something, here is my Key class. It uses the same mechanim as Senocular's class, but fixes a weird problem when the keys suddenly stopped working after removing an event listener somewhere else. There's still a problem with the contextual menu, if anyone knows how to fix that...
/**
* Debug
* -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
* @author Igor Vasiliev aka The Helmsman
* @version 0.3
* to setup debug sections
* @usage var myDebug:Debug = new Debug(new Array(["system manager", "off", 1]), output_txt);
* to initialize
* @usage myDebug.initDebug();
* to print message
* @usage Debug.printMsg("Hello world", 1);
*
* DESCRIPTION:
* -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
* Debug module responsible for printing debug messages to pre-defined output text field area.
*/
package utils {
import flash.text.TextField;
import flash.utils.setInterval;
public class Debug {
// -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
// public properties
// -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
// private properties
// -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
private var iid:int; // queue check id
private var queCheckInterval:int = 1000; // queue check interval
private static var msgQue:Array; // stores debug messages
private static var isInitialized:Boolean = false; // init flag - if initialized: start check queue
private var debugArray:Array = new Array(); // stores debug settings
private var output:TextField; // text field to represent debug messages
private var lineCnt:Number; // line counter
// -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
// public methods
// -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
/**
* Debug class constructor
* @param debugArray - debug array with initial settings
* @param output - reference to a text field used for debug output
*/
public function Debug(debugArray:Array, output:TextField) {
this.lineCnt = 0; // reset line counter
this.output = output; // save reference to output text field
this.debugArray = debugArray; // save debud settings data
}
/**
* Initialize debug module to start queue processing
*/
public function initDebug():void {
msgQue = new Array(); // reset messages queue
isInitialized = true; // update initialization flag
var obj:Object = {msg:"Debug is initialized", lvl:0}; // create new message
msgQue.push(obj); // add message to queue
iid = setInterval(queProcessing, queCheckInterval); // start processing
}
/**
* Save incoming messages in queue for future print
* @param msg - string contains message
* @param lvl - number represents section of code
*/
public static function printMsg(msg:String, lvl:Number):void {
if(!isInitialized) return; // check initialization flag
var obj:Object = {msg:msg, lvl:lvl}; // create new message
msgQue.push(obj); // add message to queue
}
// -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
// private methods
// -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
/**
* prints trace messages according to the output settings
*/
private function queProcessing():void {
if(msgQue.length == 0) return; // check for new messages
for(var i:int=0; i<msgQue.length; i++) {
for(var j:int=0; j<debugArray.length; j++) {
if(debugArray[j][2] == msgQue[0].lvl && debugArray[j][1].toString() == "on") {
lineCnt++; // update line counter
// show debug message in output textfield
if(lineCnt == 1) { // first message
//output.htmlText = "<font color='#990099'>"+lineCnt+" "+debugArray[j][0]+" -> </font>"+msgQue[0].msg+"\n";
output.text = lineCnt+" "+debugArray[j][0]+" -> "+msgQue[0].msg+"\n";
} else {
//output.htmlText += "<font color='#990099'>"+lineCnt+" "+debugArray[j][0]+" -> </font>"+msgQue[0].msg+"\n";
output.appendText(lineCnt+" "+debugArray[j][0]+" -> "+msgQue[0].msg+"\n");
}
output.scrollV += output.maxScrollV; // scroll up
}
}
msgQue.shift(); // remove message from queue
}
}
}
}
This code I use in every project during last three years (now it is written in AS 3.0). The purpose of this class to debug different parts of Flash application simply by changing initial settings of debug array.
For example, you have three classes in your project:
- ApplicationManager.as
- Clock.as
- ClockRepresentator.as
The initial settings of Debug array can be:
Code:
var myDebug:Debug = new Debug(new Array(["ApplicationManager", "off", 1],
["Clock", "off", 2], ["ClockRepresentator", "off", 3]), output_txt);
Then you need to add following code to each class where you want to use Debug module:
Code:
import utils.Debug;
private function pm(msg:String):void {
Debug.printMsg(msg, $N);
}
where $N must be 1, 2 or 3 depending on class where it is used.
Now when you need to print something inside the class, you must use pm("your message"); instead of trace("your message"); and it will be seen on the output text area (in case when you set print option to "on").
The code can be easily modified to use with different Flash debug plug-ins available today (for example Flash Tracer + Flash Player debug version).