As I've used it in two posts I should mention what wonderfl is. It's simply one of the best resources available for Flash developers, in particular ActionScript programmers. It lets developers upload and run ActionScript, for testing or to demonstrate it. Code on the site can be modified, even if you did not write it, by creating a copy (or a 'fork') and working on that. Editing and testing all takes place in the browser, making it often much quicker than setting up a similar project in Adobe Flash CS or a similar environment.
Saturday, 17 December 2011
Friday, 16 December 2011
A faster random
Although ActionScript has its own random number function, Math.random(), like most library calls it is not especially fast. But it is easy to replace, to provide a significant speed up, as well as make it easier to do other optimisations.
The basic idea is very simple: instead of calling Math.random()while the game is running call it a number of times at startup to populate a list, then at runtime pull values out of that list. This would not work in all games: it might produce predictable or repetitive outcomes in some cases. But in games where random numbers are used for effect or to provide some variability in a number of ways it is often indistinguishable from Math.random() (which is not truly random anyway).
The basic idea is very simple: instead of calling Math.random()while the game is running call it a number of times at startup to populate a list, then at runtime pull values out of that list. This would not work in all games: it might produce predictable or repetitive outcomes in some cases. But in games where random numbers are used for effect or to provide some variability in a number of ways it is often indistinguishable from Math.random() (which is not truly random anyway).
Thursday, 15 December 2011
One decimal place
This is a small function I wrote to print Numbers to one decimal place. Most user-visible values used in Bug Tunnel Defense were whole numbers and so were stored as int. But a few needed more precision and so were stored as Number. So they did not overflow their TextField they were displayed to one decimal place, using this function.
Wednesday, 14 December 2011
Bug Tunnel Defense release notes
I discussed these in detail on the blog I ran for Bug Tunnel Defense's release. Rather than repost those posts separately I'll summarise them, with links to the originals.
Tuesday, 13 December 2011
Matrices
The Matrix class in Flash is a two-dimensional matrix, used to draw and display objects on the stage. It is difficult to avoid as it is needed for some calls, especially the draw function of the BitmapData class. The Matrix if something is to be drawn without moving, but generally it's required.
The simplest use is to offset something as it is drawn. I find this is also the most common use, so it's useful to have a quick way to do it. Here's an example of that, drawing a wall block into a layer based on its grid position.
The simplest use is to offset something as it is drawn. I find this is also the most common use, so it's useful to have a quick way to do it. Here's an example of that, drawing a wall block into a layer based on its grid position.
Saturday, 10 December 2011
Buttons
This is a simple tip about how to do buttons in Flash. You can make them however you like, using code (as I usually do) or in Flash CS's editor. But always make them dynamic.
Friday, 9 December 2011
My 2D Vector class - and why I no longer use it
For Bug Tunnel Defense I created a 2D vector class. The nearest thing built in to Flash is the Vector3D class, but that with four elements is twice as big as I needed, and also uses Number rather than int as I wanted. I wanted something to store 2D grid positions, for game logic, so I created my own class. Then barely used it.
Thursday, 8 December 2011
My TextField class
This is a class I added to replace all instances of TextField in Bug Tunnel Defense, to eliminate half a dozen lines of near identical code after each call of new TextField();
The constructor for TextField for some reason takes no parameters, even though you pretty much have to set some properties for an instance you create in code. I added parameters for the defaultTextFormat, x and y which I was always setting, as well as an optional Boolean to make it right aligned. For those text items that were fairly dynamic and so could change alignment I also added functions to set the alignment and position at the same time.
The constructor for TextField for some reason takes no parameters, even though you pretty much have to set some properties for an instance you create in code. I added parameters for the defaultTextFormat, x and y which I was always setting, as well as an optional Boolean to make it right aligned. For those text items that were fairly dynamic and so could change alignment I also added functions to set the alignment and position at the same time.
Wednesday, 7 December 2011
Bug Tunnel Defense: Names
(originally posted 25 May 2011)
The game had at least four names during development, that roughly trace the history of its design.
Monday, 5 December 2011
Ballistics
Ballistics concerns projectiles such as darts, balls and bullets that move through the air unpowered, after being fired or launched from a gun or by hand. There are many ways to do this but it's common to make two simplifying assumptions.
First it's normal to assume that air resistance doesn't matter, because the projectile is heavy, it is aerodynamic, or the time of flight is so short that air resistance makes no difference. This may be unrealistic but it is good enough for game simulations, and makes the mathematics solvable.
The other assumption is that the target is no higher or lower than the launcher, so they are at the same height. This is more a constraint than a simplifying assumption but it's one that works well for many game types, where e.g. all combatants fight on the same level. It greatly simplifies the mathematics.
Subscribe to:
Posts (Atom)