Friday, 27 January 2012

New screenshot

A screenshot from something I'm working on. Yes, it has circles in it.



And a tip, if you're developing on a Mac. Turn on Web Sharing (under Sharing in System Preferences), then set the path Flash builds the SWF and HTML to something like "../../Sites/xxx", where xxx is the file name of each. Then you can access it in the browser using the IP address of your machine and the HTML file name, as above. No need to upload it to a separate site for network testing. It's still a local file so will work locally in the debugger or standalone Flash player just fine.

Thursday, 26 January 2012

Circle-line intersection

Yesterday's method for determining whether a circle crosses a line can also be used to find where the crossing points are. The approach uses the distance calculated in the hitLine function with some simple circle geometry.

Wednesday, 25 January 2012

Circle-line incidence

Problems involving circles and lines can be straightforward, if handled the right way. The main reason for this is the fact that the distance from a circle to a line is just the distance from its centre to the line minus the radius. I.e. if a circle radius 100 touches a line the circle's centre must be 100 units from the line.

Tuesday, 24 January 2012

More on circles


Yesterday I described circle-point and circle-circle intersection tests. These are very straightforward to do, and it is interesting to look at why this is so, as it can help solve other problems with circles.

Monday, 23 January 2012

Circles

Circles are used for many things in 2D games. Not only for things that are inherently circular (wheels, balls) but for many effects and to describe many situations. For example the range of a gun is often a circle, or at least circular.

Friday, 20 January 2012

Fast path member access

I noted on Wednesday that accessing members by repeatedly doing a lookup in a Vector is slower than doing that lookup once. But it was slower even than I expected. The code was doing the lookup eight times more than necessary, but was over twelve times slower (i.e. it took over twelve times as long). So I forked the code and re-wrote the tests to find out what was going on. The results of this are especially interesting.

Thursday, 19 January 2012

Wednesday, 18 January 2012

Dereferencing array members

The title refers to code like this


iSum += aData[iIndex];


Looking up in an Array (or Vector) requires the code to find the address of the object or value requested then retrieve whatever's at that address. It might also check whether it exists, and whether it is in range (and if not whether it should grow the Array or Vector to accomodate it).

Tuesday, 17 January 2012

Accessing members by name

One sometimes misunderstood feature of ActionScript is that as well as accessing members of a class directly and using accessors it's possible to do so using the name of the member, passed as a String to the class. Misunderstood as there is a right way to use this and a wrong way to use this. And the wrong way is incredibly slow, so much so it should be avoided at all times.

Monday, 16 January 2012

More on angles

In a recent post I asserted that angles are rarely needed for game mathematics. There are a few exceptions but far fewer than many people realise. But it's easy to doubt this assertion. What is there theory behind it? Is there a way to check when angles can be avoided? Not only can both questions be answered but the answer to them is the same.