In a place where your fantasy can roam free, there won't be any boundaries to what your imagination can create.
Misha’s Tech Playground
graphics, fun and code play
I'm crazy - but who cares? My ideas are constantly dwelling and this is the place for them to pour out and form into something good. Only active participation will ultimately make this place come to life.
Safari wins , Opera lost (real life JS performance)
To check performance on large maps in my level editor I included a little function that generates a map of a given size filled with random tiles. I am lazy I know, but try to click your way through a 200 x 200 (40000 tiles) map and you know what I am talking about
So while testing I found out that there are vast performance differences between the various browsers on my system[1]. I also rectified en Error with Event handling in Opera 9.5* while I was at it.
The test I ran was pretty simple, I used all three browsers to create a random 100 x 100 map and took the time before the function started and after it finished. The difference was output in an alert which you see here. (more…)
Tags: code performance, Firefox, Opera, Safari
Progress monitoring with JavaScript
If you ever happen do develop a web application using Javascript you might stumble upon the occasion where a process might take a fair amount of time to calculate.
The Problem
If your script needs more than a couple of seconds, most likely this fact will result in a message like this:

Okay, you might think just drop in some code to output something while your script processes an array with say… 40k Elements (200 x 200). The issue we face is that JavaScript in Browsers is single threaded.
So the output code you have in your processing loop will be stored in a queue until the processing is done. This of course looks like your browser is stalled until suddenly there is a huge amount of data on your page.
Several JavaScript applications offer an approach that is not very user friendly. Until the script is finished you’ll see an animated gif of a spinning circle or a phrase like waiting… (usually with an animated ellipsis). The real solution is only slightly more complicated but gives far more feedback to the user.
Real Progress Bars (or other shapes) are something all modern desktop applications offer. Web Applications made with Flash or other Technologies offer this as well.
How to do this in JavaScript is what we look at next … (more…)
Tags: code performance
Level Editor Redux
I have dedicated more of my sparse spare time and refined my level editor quite a little bit.
I have found some very cool and useful information about tile based games on the net this week and parts of it are already directly influencing the current codebase. The latest somewhat stable version is 0.92b which rectifies some problems with Firefox 2 and implements all features listed as current. Once I have a chance to cleanup the code I’ll make it available for download in a new post.
The current development milestone is 0.95a which incorporates already some of the planned features.
It still has to go a long way to be complete but the progress is going well. (more…)
Tags: Games, level editor, tile graphics
Generating Tile Maps
About nine months ago I discovered Open Sword Group’s Pixen a really neat image editor for OS X, perfectly suited for Pixel Art. I was working on my BA thesis by that time and investigated the possibility of tile based graphics for the thesis project.
Though it turned out that tiles were not feasible. However this application and the sites I discovered through my research had sparked fond memories of long lost games and an idea was planted.
For a couple of months now I am working on my very own little game project. Initially I was trying to use RepTile to create my maps. But after trying to contact the author without getting any response it seems the project is abandoned. Though the concept of this little application is still neat.
It works like any other tile map generator in the way that you can paint your map using the tiles you provide. A great addition however is that you can already assign properties to map tiles. For example, the stone wall is not walkable and the grass has less movement cost than the dirt . You get what I mean.
As badly as I wished to use this little program, I am no Cocoa programmer and can therefore not ad features I need.
But luckily I can do JavaScript and this seems to be the perfect playing field for it. Since tile based games are mostly web related, why not create the maps straight in the browser. So I took the great RepTile idea and moved it over to JavaScript and the outcome was this (click to see the full image):
The generator is working and can perform the basic tasks of painting tiles and assigning properties to them. Clicking the generate button will present you an xml file which you can use with an appropriate engine (such as the one I am working on). However, the code is a bit messy right now.
But if there’s enough interest I’ll clean it up and post it here.
P.S. The tiles used in this screenshot aren’t mine. Danc made them. Anyone interested can find the link in the Sprites, Sprites, Sprites post.
Tags: Games, level editor, tile graphics
Dynamically loading external Javscript Files
Some weeks ago I read a short tutorial over at JavaScript Kit about how to load JavaScript files into your document on demand. This was a thought that I already pursued for some time as I had seen something similar already in the Scriptaculous Library. The difference on the Scriptaculous side was that you appended the additional files you wanted to load as a parameter to the main scripts url (scriptaculous.js?load=effect,dragdrop).
The idea is basically great. In modern languages you have the ability to import or include files for compilation (i.e. the C Family Languages, Java and Actionscript) or at runtime (i.e. Python and PHP).
So why should JavaScript be any different ?
Mainly it is because JavaScript wasn't designed with such behavior in mind . JavaScript wasn't supposed to build big applications like the now so popular Web 2.0 Apps (i.e. Google Maps, Google Calendar and others).
Why would I want that?
Once you start to develop larger Applications with JavaScript (or other languages for that matter) you usually end up having the same functionality in different places. But you also have bits of code that are unique to certain parts.
What makes sense in my opinion is to split up your monolithic JavaScript files into pieces that are:
- easier to maintain
- faster to load
- more reusable
But once you split up your files it can get messy rather quick too. On some occasions I had 6 or more Script nodes in one HTML file. Also keeping track of dependencies gets difficult.
Wouldn't it be a lot easier to have just a single script node where you would define what you need? Or better yet, let the script itself take care of what it needs.
How to do it?
I stumbled upon a great concept today that takes the initial idea a bit farther. A few days ago Remy Sharp blogged how to do On Demand Script Loading. Since I was working on the same idea I found this extremely interesting.
His idea is basically probes for the existence of an object and if it isn't found loads it.
My idea however was more similar to the initially mentioned Scriptaculous or Java approach.
You would need just a single script node in your html file to load either some
-
<script src="_js/opencsg/opencsg.js?load=event,input,util" [more attributes]></script>
for all your scripts.
-
<script src="_js/opencsg/opencsg.js" [more attributes]></script>
Okay, up until now this doesn't work different from Scriptaculous. So what I did further was to add a check for script dependencies.
For example I have one script that deals solely with event handling. Though this script is dependent on methods to check for different browsers and searching for nodes. I make a check if this object exists and if not I'll simply load it.
-
if (!CSG.CLASSES.util) {
-
CSG.include('util');
-
};
These checks are implemented in each file to make sure all dependencies are met. And since these checks are performed only when the script is loaded there is no performance hit.
The include function in turn looks like this:
-
include: function(libName) {
-
var src = CSG.path + libName + ".js";
-
-
if ((document.createElement && document.getElementsByTagName("head")[0].appendChild)) {
-
// insert script nodes to head node in all compatible browsers
-
var s = document.createElement("script");
-
s.setAttribute("type","text/javascript");
-
s.setAttribute("src", src);
-
document.getElementsByTagName("head")[0].appendChild(s);
-
} else {
-
// inserting via DOM fails in Safari 2 and other older browsers
-
document.write('<script type="text/javascript" src="' +src+ '"><\/script>' );
-
}
-
CSG.CLASSES[libName] = true;
-
}
Only the script name is submitted as parameter. Anything else is already stored in the object at the initial load.
Also note the fallback for browsers that have problems with inserting nodes via DOM.
This is just part of the whole script, though you could use this function independently. Once I have removed the kinks and quirks of this library I'll post the full version here too.
Tags: dynamic loading, JavaScript Library
Experimental Javascript
Javascript Benchmark
While it my not make a big difference for most people, I care about the performance of the code I write. Somtimes there are multiple ways to get to the same result, butto find out which way is better is not always easy.
Sometimes you'll probably decide to use a certain function or concept because it is easier to implement or read, but that doesn't necessarily make it faster to interpret for your browser.
To have some aid in what I do I developed a small Javascript Benchmark.
Searching through the internet I found some benchmarks that test the performance of Interpreters themselves but rarely one that is intended to compare performance of different functions or concepts. If you find it in anyway useful feel free to use it. Though there is no guaranty that the results are correct measures.
Javascript Starfield
Back in the days of my trusty Atari 800 or later my Amiga, a starfield animation was a very popular effect. Unlike the Starfield screensaver that later shipped with versions of Microsoft Windows these starfields were depicted from the side as if you flew by and not into it.
Trying to replicate this vintage look I quickly found out that Javascript and DOM might not be the ideal companions to do so. While the effect is quite nice in my opinion, the processor load to calculate the 150 stars' position is quite high. Maybe I should look into SVG and the canvas tag to replicate this effect and probably have less processor load.
For the time being check out this probably first serious Javascript experiment of mine I did early in 2007.
Tags: code performance, starfield effect
Sprites, Sprites, Sprites
This is a repost of some posts to my old website from May to June 2007
Animated Sprites and Tile Mapping with Javascript
Based on a previous post about Javascript Sprite Animation I decided a while back to create a little tile map and have a sprite move about it using keyboard controls.
Below is the original context:
Yesterday while surfing the net I found some very cool tile graphics. Luckily Danc the creator of these graphics released them to the open public. These will prove a rich learning resource for me.
Anyone who is interested might visit his blog at lostgarden.com
The game tiles are available from this post > more free game graphics
Javascript Sprite Animation with Tiles
* * *
Javascript Sprite Shading Algorithm
My curiosity led me to try my hand at simulating a light source with Javascript. While I had done this previously to fake a 3d lighting effect (use this link for the JS version) with just 5 layered graphics, I wanted to try a different approach this time.
My goal was to create the illusion of a light source fading with distance - much like a point light source, a light bulb for example.
The algorithm or one that is similar was probably used in tile based games that tried to simulate light sources. Some that I played myself were "Jagged Alliance 2" and the original X-Com strategy games.
To see the algorithm in action click the link below:
Javascript Sprite Shading Algorithm
Tags: Games, lighting, tile graphics
Javascript Sprite Animation
How To Use Javascript To Animate
This is a repost from playground.3d-m.de from May 19th, 2007
Coded up in about 10 minutes, this is just a test to check the performance of script based animation. The sprite consists only of one continuos image strip which is animated using a Javascript Interval.
So Why No Animated GIF?
Well, first of all this image is a PNG – but it could be a JPG or any other format also. Further this could be used to make extremely efficient rollovers because there is no need to load two separate images. And finally, it was just plain fun to make it
What wasn't so much fun was the PNG behavior in IE 6. But using an ugly css hack and slightly more difficult DOM tree it works in IE 5.5+ also.
Link: javascript sprite animation
Tags: Games, tile graphics
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
