I first tried using gradient fills (via the beginGradientFill method of the Graphics class) in Bug Tunnel Defense. I wanted to use them for shading along the tunnels but could never get them to work, and eventually did it the long way by drawing a series of differently coloured rectangles. The problem was the createGradientBox Matrix function, which no matter what I passed to it would never return the right matrix for a linear fill.
Showing posts with label Circles. Show all posts
Showing posts with label Circles. Show all posts
Monday, 26 March 2012
Friday, 17 February 2012
Why circles (and spheres)?
One interesting question is: "Why are circles (and by extension spheres) better for games?". I don't just mean computer games but a wide variety of games and sports use balls: marbles, billards, tennis, pétanque and football. Still more use circles: curling, shuffleboard and air-hockey.
Monday, 13 February 2012
drawCircle is slow
This is something I discovered at the weekend. I already knew that the drawCircle function of the Graphics class is slow, slow enough that you don't want to be using it to draw too many circles at once at runtime. Instead render them into a BitmapData using BitmapData.draw wherever possible.
Friday, 3 February 2012
Circle-circle intersection
Intersecting circles can be done in a number ways. One approach is algebraic: take the formulae for the circles and solve them to obtain values for the x and y coordinates. Another approach derives the line that joins the points of intersection then intersects that line with the circle.
But the method I use is more direct, and I think mathematically more robust. By direct I mean it calculates the result directly and does not depend on intermediate results, such as calculating the line or one of x and y first. As such there's much less chance the order of calculation will affect the result.
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.
Subscribe to:
Posts (Atom)
