Smash Hits Badminton Beta

October 20th, 2011 by Rick

Yesterday I lauched my new badminton game, which is still in beta. It’s now available to the public with a couple of features already available, but with much more to come in the next months, including a much needed online multiplayer mode.

With already near 100 users and 200 games played in less than 48 hours, I hope this will be the game that fills the need of a complete badminton game on the web.

Feel free to come by and try it.

Play Smash Hits Badminton Online!

Flash – French Custom Character Embedding

April 15th, 2010 by Rick

These files contains character sets that you can embed in your dynamic textfields :

C:\Program Files\Adobe\Adobe Flash CS4\en\First Run\FontEmbedding\UnicodeTable.xml
C:\Users\{user}\AppData\Local\Adobe\Flash CS4\en\Configuration\FontEmbedding\UnicodeTable.xml

Add this set of unicode characters to add a French set of characters in the Character Embedding dialog :

Read the rest of this entry »

AS3 – Detect when mouse leaves stage

March 4th, 2010 by Rick

1
2
stage.addEventListener(Event.MOUSE_LEAVE, mouse_offstage);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouse_onstage);

AS3 – External Font Loading Class

February 10th, 2010 by Rick

There is an easy way of loading external fonts embedded in swf files, using the etcs.ru.utils.FontLoader class. It loads the swf file, extract the font data directly at the bytes level, and register it to the Font class.

Here is a great tutorial for using the etcs.ru.utils.FontLoader class : http://www.thetechlabs.com/tutorials/flash/dynamically-loading-fonts-with-fontloader-and-applying-styles-with-css-stylesheet-in-as3/

I’ve put together a FontManager class that manages multiple swf files with this FontLoader class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package revoke.ca.fonts {
   
    import ru.etcs.utils.FontLoader;
    import flash.text.Font;
    import flash.events.EventDispatcher;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.events.IOErrorEvent;
    import flash.net.URLRequest;
   
    public class FontManager extends EventDispatcher {
       
        private var _font_loaders:Array;
        private var _data:Array;
        private var _cur_font:Number = -1;
       
        public function FontManager() {
            _font_loaders = [];
        }
       
        public function init(data:Array) {
            trace("FontManager::init");
            _data = data;
           
            for (var i:uint = 0; i < _data.length; i++) {
                var font_loader:FontLoader = new FontLoader();
                font_loader.addEventListener(ProgressEvent.PROGRESS, load_progress);
                font_loader.addEventListener(Event.COMPLETE, load_complete);
                font_loader.addEventListener(IOErrorEvent.IO_ERROR, load_error);
                _font_loaders.push(font_loader);
            }
            loadNext();
        }
       
        private function loadNext(){
            _cur_font++;
            if (_cur_font >= _data.length){
                trace("FontManager::total_load_complete");
                dispatchEvent(new Event(Event.COMPLETE));
                return;
            }
            _font_loaders[_cur_font].load(new URLRequest(_data[_cur_font]));
        }
       
        private function load_progress(event:ProgressEvent) {
            var ratio:Number = (event.bytesLoaded / event.bytesTotal + _cur_font) / _data.length;
            trace("FontManager:: PROGRESS : " + ratio);
        }
       
        private function load_error(event:IOErrorEvent) {
            trace("FontManager::load_error");
            dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR));
        }
       
        private function load_complete(event:Event) {
            trace("FontManager::load_complete");
            loadNext();
        }
       
        public function get_font_list():Array {
            var fonts:Array = [];
            for (var i:uint = 0; i < _font_loaders.length; i++){
                var cur_fonts:Array = _font_loaders[i].fonts;
                for each (var font:Font in fonts) {
                    Log.log("FontManager:: FONT LOADED : " + font.fontName);
                }
                fonts.splice(fonts.length, cur_fonts);
            }
            return fonts;
        }
    }
}

Usage :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;

var font_data:Array = ["fonts/arial.swf", "fonts/helvetica.swf"];
var font_manager:FontManager = new FontManager();
font_manager.addEventListener(Event.COMPLETE, fonts_complete);
font_manager.addEventListener(ProgressEvent.PROGRESS, fonts_progress);
font_manager.addEventListener(IOErrorEvent.IO_ERROR, fonts_error);
font_manager.init(font_data);

function fonts_complete(event:Event):void {
    trace("Fonts Complete : " + font_manager.get_font_list());
}

function fonts_progress(event:ProgressEvent):void {
    trace("Fonts Progress : " + (event.bytesLoaded / event.bytesTotal));
}

function fonts_error(event:IOErrorEvent):void {
    trace("Fonts Error");
}

PHP – Calculating execution time

January 25th, 2010 by Rick

Here is an easy way of calculating the time elapsed during some script execution in PHP, using microtime() :

1
2
3
4
5
$exec_start = microtime(true); // 'true' returns the seconds of type double

// ... do stuff

echo (microtime(true) - $exec_start) . ' seconds';