Hey it’s Friday so it’s time to try a fun JavaScript hack – Let’s go and precompile some functions! What does “precompiling” mean? In principle, it means we take a function which takes multiple parameters and pre-define some of them. All this is done dynamically, so your code can do it on the fly. Let’s check out how this works …
Using canvas to do bitmap sprite animation in JavaScript
Have you ever thought about writing a game? If you have, you’ve probably wondered how to render animations for your game characters. In this post, I’ll show you how you can use JavaScript to do time-based sprite animations, drawing them on canvas – vital if you want to do a game. You can also apply the same techniques I’ll show …
Unit testing JavaScript
I’ve recently been looking into some JavaScript unit testing frameworks. There are many alternatives, and while many of them seem good, very few of them actually matched my requirements: Must be able to run tests from the commend-line Tests should be relatively easy to write
Weekend coding: Add a character counter as the background of a textarea with JavaScript
Have you ever filled a textarea on a page, which had a limit to how many characters you could type into it? Or maybe you are a Twitter user, and as you know, Twitter only displays 140 characters of your tweets. (Not an actual textarea) The other day I was thinking of this: How to effectively communicate how many characters …
Opera Command, JavaScript based Missile Command game
Firstly I’d just like to let you know that the lack of posts lately is because I have a new full time job which I’m enjoying quite much so far, but it still means I have less time / motivation to write stuff. The unit testing series and other postings will continue (see how I didn’t say “next week”, but …
TankWar Online, my JavaScript based cannons game
Back in late 2006 I wrote my most ambitious JavaScript/game project so far: TankWar Online, which as you may guess from the name was about tanks, shooting stuff, and it had a real-time online game mode – as far as I know, the first such ever in a JS based game. Originally the game was made for an older version …
How WidgetCity does a tile-based map using just CSS
My city building game, WidgetCity, displays the city as a table, each cell of a table representing one tile. The tile map is done purely using just CSS, and CSS classes. The map is also scrollable. How is this all done?
How to pass variable values to JavaScript
A relatively common task in today’s Web 2.0 apps is passing values from a server-side script (or through a link) to JavaScript, affecting the client-side script execution. Not surprisingly, there are a few ways to do that. Let’s look at three and their pros and cons: Embedding scripts into templates Passing variables in URLs Using configurable scripts
Optimizing JavaScript for extreme performance and low memory consumption
While making WidgetCity, I had to use various measures to speed up the code. In this post, I’ll show you the tricks I learned – some of which I haven’t seen mentioned anywhere else before. A lot of performance optimization tips for JavaScript code involve things that you more typically see in web sites, like minimizing the amount of DOM …
I wrote a Sim City clone in JavaScript
This is why I haven’t been updating lately: I have been working on a Sim City clone, written purely in HTML, CSS and JavaScript! The game is called WidgetCity, and I’m participating with it in the Betavine Widget Competition 2009. The game was designed to run in Opera Widgets mode, but it also works in Firefox – only downside is …