Tag Archive for 'actionscript'

Page 3 of 4

Simple terrain generator experiment

Just great how easy it is to make a simple terrain generator :D

This evening I started an experiment to try and create a terrain generator (like the one in my all-time favourite SimCity2000). So far I don’t really have use for it but it might come in handy in the future.

I managed to work out the basics in just 3 to 4 hours. Now I need to find a way to get smoother edges and get rid of all the really small islands. I recon that’s gonna take a bit more work.

 I used an enterFrame event to get the animated effect. Just to see what happens.

Check the first results here:
http://www.powerupmedia.nl/#/exp070702

PS: this is the first time I used actual flash components since I don’t have a slider or spinner ready in as3; boy do those things SUCK!!! :roll:

UPDATE (2007-07-09):
I managed to remove the majority of the small (one or two px) islands by tweaking the algorithm a little. The result is now a bit more realistic.

Also I increased the max world size to 960×960 (to illustrate: SimCity2000 has a mapsize of 128×128).

Finally I added the world wrap option (because it took me just 2 minutes to add :D ).

UPDATE (2008-03-09):
Here is a short explanation of how the code works:

The general trick is to place a first pixel somewhere on the map and than check each of its neighbours to see if they need to be filled with the same “terrain-type”. You can do this by checking a random value against a fixed limit value (in this case represented by the “spread”).
When a certain pixel on the map is filled you place it in an array so you can always check if a pixel is already occupied and you can also use it to check if the maximum number of a certain type is reached (in this case represented by the “pct”).
After this whole sequence you repeat the same process for the newly generated pixels (there is your recursion). If there are no more pixels left to check and the maximum is not reached yet, you just place a new pixel somewhere on the map and start again.

I hope this will help you along.

Flash experiments

justGREAT! I organized some of my flash experiments for you to play with…

ribbon #1 (2003?)
soap (2005)
particles #1 (2005)
particles #2 (2006)
particles #3 (2006)
mouse #1 (2006)

Let me know what you think of them…

I hope to convert some older experiments in to as3 in the near future. I’ll keep you posted!

Update (2007-12-05)
I moved my experiments to a new domain and I renamed them because their numbers became too overwhelming :P
You can find these and other experiments on http://labs.powerupmedia.nl

I want actual sizes!

Just great! yet another weird Flash “feature”. When I tried to get the width of a rotating MovieClip I got wildly variating values. This surprised me because the MovieClip only contained exact round shape. The circle was 25 px in diameter, but when I started to trace the width in an interval I got values ranging from 25 to 35.4px.

As it turned out, the width and height of the MovieClip only represent the bounding box of the original shape (when it still had a rotation of 0). The only way to get the actual width and height of the MovieClip was to use the getBoundsmethod. This method calculates the boundingbox according to the current shape and orientation of the MovieClip giving the trrue width and height.

To test this create a movieclip width a circle in it and place the code below on the first frame (I’m no fan of timeline-code but it’s ideal for testing purpose :D ).

1
2
3
4
this.onEnterFrame = function(){ 
	this._rotation += 15; 
	trace("boundingbox-width: "+(this.getBounds().xMax-this.getBounds().xMin)+"\t\twidth: "+this._width); 
}

The sample is as2 but the problem and solution are the same in as3.

I hope this helps some of you who were wondering why a 25px circel suddenly had a 35.4px width :| .

allowFulSceen vs. transparent wmode

Just great when you waste half an hour figuring out why you can’t get your flash to run in fullscreen mode :|

To save you the time and frustration, here is why it didn’t work:
You can’t use the allowFullScreen = true and wmode = transparent together :?

Somehow the flashplayer is not smart enough to simply make the background opaque when you set the player to fullscreen mode.

Lets hope they fix this in the next player update…

Garbage Collector troubles using the Loader class.

Just great :( another weird Garbage Collector issue in AS3:

When I load an image using the Loader class and unload it later on. It won’t be disposed by the garbage collector.
There are no references to neither the Loader nor the (weak) eventlisteners. After loading the image a couple of times the memory goes sky high :| .

Here is a (simple) example: loadertest.zip

Does anyone have an explaination on why the GC doesn’t clean the loaded content? I would be very grateful!

UPDATE 1 (2007-06-19):
I made the example even less complicated by using the same Loader instance when loading new images.

As I work around I tried to dispose the loaded BitmapData but unfortunately it had no effect.
I assume the leak is somewhere within the Loader (or even deeper in the code) and that the loaded (binary) data is not removed after it’s converted into a BitmapData.

UPDATE 2 (2007-06-19):
I found the solution on in this post:
http://www.webforumz.com/macromedia-flash/42690-memory-leak-when-loading-swf-in.htm

It seems that the unload() method has a bug when used in the flash IDE. Once I ran the test in a browser there seem to be no more problems and the GC nicely clears the memory…

Lets hope Adobe fixes this problem in the next Flash 9 update.