Tag Archive for 'actionscript'

Page 2 of 5

0.1*3 = 0.30000000000000004

Isn’t this just great? I stumbled upon this problem in actionscript a while ago, but at that time I just worked around it and never bothered again… until today. A colleague came to me with the same problem and I decided to investigate a little more.

Apparently it is some weird bug when it comes to multiplying decimals values by 3. Take this little script for example:

1
2
3
4
5
var j:Number; 
for(var i:int=0; i<10; i++){ 
	j = i/10; 
	trace(j+"*3 =\t"+(j*3)); 
}

It outputs:
0*3 = 0
0.1*3 = 0.30000000000000004
0.2*3 = 0.6000000000000001
0.3*3 = 0.8999999999999999
0.4*3 = 1.2000000000000002
0.5*3 = 1.5
0.6*3 = 1.7999999999999998
0.7*3 = 2.0999999999999996
0.8*3 = 2.4000000000000004
0.9*3 = 2.7

And it doesn’t stop just there. The same problems occur when adding a decimal value to the double of it’s value:

1
2
3
4
trace(.1+.2) //0.30000000000000004 
trace(.2+.4) //0.6000000000000001 
trace(.3+.6) //0.8999999999999999 
trace(.4+.8) //1.2000000000000002

The problem occurres in Javascript as well as in Actionscript (and probably some other languages too) so it’s probably caused by the way decimal values are treated at byte-level. Because it’s not likely there will be a fix for this soon, here is a little workaround:
i = int(i *10)/10; //use int() in favour of Math.round() to speed up the code

Tiling my Mahjong engine

Just great; a new week and I have only one spare evening do a little experimenting :|
Since my goal was to put up at least one decent experiment a week and since I have little time this week, I decided to upload an experiment that’s almost a year old. It’s an engine for a Mahjong game:

http://labs.justgreat.nl/exp061203.htm

At the time I made the engine I didn’t feel like creating nice graphics so the experiment still looks a bit boring.
Because the engine works fine I thought it would be a wast not to use it, so tonight I created some graphics for the tiles (check them here).
The symbols are taken from a photo of real Mahjong stones. so they should be quite accurate.
The tileset is not 100% complete yet and the current tiles still need a little work on the coloring as well, but I’m sure I’ll finish it somewhere next year :D

Bubble Schmubble beta update

It’s just great to know that after all these years I still got some of my php-programming-skills left. Today I added online highscores to the Bubble Schmubble game using a little php-script which reads and writes the highscores in an xml file. This means you can now compete with your friends or colleagues. Isn’t that justGREAT!?!

I also moved the game to a new location. From now on you can check the game here:
http://games.justgreat.nl/bubbleschmubble/

Besides the online highscore option I also added some sounds (again)  and I animated the creatures inside the bubbles a little (quick and dirty).

Last but not least I removed the MochiAd from the game because it was way too annoying and I needed at least a 1000 players a day (!) to make just a little profit from it :( . Instead of the MochiAd I added normal google-ad-banner though,  in the hope it will pay me off some day :D .

I hope you enjoy playing against each other because your highscore will be visible to everyone who plays the game.

Bubble Schmubble beta

Tonight I launched the first beta version of Bubble Schmubble and it’s justGREAT!

You can try it here: http://games.justgreat.nl/bubbleschmubble/

I already added some functionality to the game like local highscores, but there is still a lot of work that needs to be done:
- some bugfixes on the current code
- overall highscore
- better tweens and animated creatures
- sounds
- a splash screen
- a setting page
- a credits page (so far it’s only gonna contain my own name :P )

I added a MochiAd just to check how it works. If the ad becomes too much of a nuisance or doesn’t bring in enough money (according to the number of players) I will remove it again.

Let me know what you think of the game so far. Also suggestions are always welcome…

Bubbling creatures

Isn’t this justGREAT! Today I created a game engine in about 4 hours :D

The engine is based on a game called “Jawbreaker” which is a real fun and addicting game.

The final game needs a nice scoreboard and a menu and of course some nice sounds, tweens and animations to spice it up…

For the time being I added the result as an experiment to the lab:
http://labs.justgreat.nl/exp071204.htm

Go check it out and let me know what you think of it…