Today, when I was packing for my old files, I suddenly found out a flash game that was implemented by me 8 years ago. I was using Flash 4 at that time and the coding is really horrible.
It’s a memorable application and I got you here for the complete rewritten version. The original Flash 4 source is also included inside the zip file.
For your reference, Stray Sheep is my favorite Japanese cartoon character when I was young. I hope you will love it as well.
Comparison
Flash implementation: 40 minutes (Implemented First)
Silverlight implementation: 80 minutes
What’s the difference?
- Keyboard Event: KeyboardEvent [AS3] vs KeyEventArgs [C#]
Source codes
Stray Sheep [Flash 9, AS3] (42.7 KiB, 994 hits)
Stray Sheep [Silverlight 2, C#] (38.4 KiB, 1,099 hits)
Flash
Silverlight
KeyboardEvent [AS3] vs KeyEventArgs [C#]
Adding keyboard event is very easy in AS3. However, it will become very complicated when many keys are pressed at the same time. If you are game developer, I think you probably understand what I mean.
// AS3
stage.addEventListener(KeyboardEvent.KEY_DOWN, on_key_down);
private function on_key_down(e : KeyboardEvent):void{
switch(e.keyCode){
case Keyboard.LEFT:
// do something after pressing left arrow
break;
case 70:
// do something after pressing the "f" key
break;
}
}
The code is similar in C#. The main difference is that the keyboard event seems work only for the RootVisaul Control. I will try to figure it out later on.
// C#
this.KeyDown += new KeyEventHandler(Page_KeyDown);
void Page_KeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Left:
// do something after pressing left arrow
break;
case Key.F:
// do something after pressing the "f" key
break;
}
}

September 25th, 2008 at 4:33 am
I can’t turn left with the flash version.
September 25th, 2008 at 5:23 am
Yep the Left arrow in Flash version doesn’t work :)
Maybe u need a tester ? :) huh I’m kidding :)
September 25th, 2008 at 12:20 pm
I played extractly that desktop sheep when I was in win9x time :)
September 25th, 2008 at 12:25 pm
use mouse to drag the sheep around? and the sheep can really walk around?
September 25th, 2008 at 2:52 pm
Alan and JoKe, I have uploaded a wrong version of swf. The problem is fixed.
unruledboy, the desktop version is really great. I hope I could have time to implment a similar version and depoly in to AIR.
September 26th, 2008 at 12:53 am
Why does the Sliverlight one scroll the page everytime i push up or down? (Mac FF)
September 26th, 2008 at 1:30 am
[...] Silverlight vs Flash: Stray Sheep FlashとSilverlightとの違いについて、同じゲームを元に比較しているページ (tags: flash silverlight 比較) [...]
September 27th, 2008 at 2:23 am
Jared, I am not sure as well. But I think its the Microsoft’s responsibility to solve out that. haha.
September 30th, 2008 at 5:06 pm
This method of reading keyboard input is not useful for games though.
Right now you’re just reacting on the keyDown event, which is fired by your keyboard.
When the user holds down a key, you’re receive 1 keypress, a small delay and then the same keypresses repeatedly.
the duration of the delay, and the speed of the repeated keypresses is user defineable on their own computer.
In games you should (in flash) put your keyboard reading function in your main game loop, so it gets called every frame, and instead of waiting for key events, just check which keys have been pressed using (for example) Key.isDown(Key.RIGHT)
This also enables you to read out more than 1 key at a time.
there should be something like that in silverlight too, but i’m not sure.
December 12th, 2008 at 9:14 pm
Very Interesting for both of them, try to use two key!? up+right or …
March 6th, 2009 at 9:10 pm
This is cool!
November 19th, 2009 at 7:12 pm
This is a great post and its very creative indeed but if only you people would properly give cubefield a shot. Its a great game. Very addicitve and very entertaining to all age groups.
March 31st, 2010 at 5:13 pm
Nice game but why dont you guys try poptropica counterfeit island instead. Its a great game and im doing a blog with all the cheats. Pls check it out
May 24th, 2010 at 8:47 am
Feels great that there is still good content on the internet
August 26th, 2010 at 12:45 pm
Today I made some delicious Dukan diet Mexican chicken fajitas. I fancied the whole works
August 28th, 2010 at 6:29 pm
Awesome article. I am bookmarking this on my Digg & Reddit accounts right away.