Select Page

Previous work

This is the first in a series of posts showing sites built and/or worked on.

shell.com

On this project I used the casaframework to create a dynamic font loader that enables font loading of specific language and character sets for individual fonts. This is driven by a config XML file.

shell.jpg

Methods on Strings

I just discovered you can run methods directly on Strings. Not particularly exciting but interesting nonetheless.
Try this one:

trace('upper case'.toUpperCase());

It will trace out this:

UPPER CASE

I’m yet to discover a scenario where this would be useful but it is fun to know all the same!

Emdedding Fonts

Flash and Fonts. Who wold have thought it could get so bad?
I remembered to put some text in the textfield on the stage. I remembered to embed all the characters I needed. I remembered to set embed fonts to true. I remembered to test that the characters I wanted were displaying in the field on the stage. Yet when I imported it and tried to set the text dynamically, my Thai characters were not displaying.
Flash was substituting the font I wanted on the stage so although it looked like my font had support for these characters, it didn’t. It was only displaying boxes at runtime. Next time I’ll remember also to check the Character Map to see that the font I want supports the characters I want.

VXR Trackday game

Here is the game I had that rotation problem with. Use the mouse to control the steering. Post your best times in the comments!

trackday;

Rotation problem

I was building a nice little car racing game last week and got stuck on a problem to do with rotation. Getting the car to follow the cursor wasn’t a problem but as I put a restriction on the amount the car could turn, I couldn’t just make the angles equal each other. This meant that I had to calculate the difference between the angles and then rotate in the right direction a maximum amount each frame. Everything is going well until we go past 9 o’clock and suddenly rotation jumps from 180 to -180. Now my math difference calculations are out the window and my car is spinning back the wrong way! This is the solution:

if (Math.abs (difference) > 180) {
difference = difference > 0 ? difference - 360 : 360 + difference;
}

And in context:
(150 and 125 represent the centre point of the 300×250 MPU)

public function setAngle():Void{
var angle:Number = Math.round(Math.atan2((_ymouse-150),(_xmouse-125)) *180/Math.PI);
  var difference:Number = Math.round(angle - car._rotation);
if (Math.abs (difference) > 180) {
  difference = difference > 0 ? difference - 360 : 360 + difference;
  }
  if(difference > 5){
  car._rotation += 6 * speed/16;
  } else if (difference < -5){
  car._rotation -= 6 * speed/16;
  } else {
  //do nothing
  }
}

looks like I have to work out how to post code in this WYSIWYG editor…