AuthorTopic: a new, better wiimote flash api in just 24 hours!  (Read 10607 times)

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

a new, better wiimote flash api in just 24 hours!

on: April 01, 2007, 10:27:59 pm
I'm copy-pasting this from TIGF cuz i'm lazy!

Hey guys!  I wanted to show you my new project, and maybe have some people beta test it for free?  This stuff is always browser-sensitive, so I want to make sure I have this junk workin right.  Also, I am not really a flash or javascript guru, I just do what I can to get stuff to work!  Ok, here we go!

MarioToo is a WiiMote API, like the one that seems so popular over at Wiicade, only I'm not squirreling away all my javascript, and I think I've got a much more redundant implementation anyways.  My API, like Wiicade's, is based heavily off of Mario Klingemann's demo from I think December.  Unlike Wiicade, he also made the javascript available for download, and I spent most of last night reengineering it to get the kinks out and make it easier for people to work with.  The result is 'MarioToo', what I hope will become the standard for great Wii Flash games to come!  The best part is its very easy to use, and you can deploy it on ANY website, not just wiicade's ad-fest!

MarioToo is very, very easy to use if you know any flash at all.  It includes a full-featured javascript library that handles all of the HTML and reflector hacks for you; all you have to do is plug it into your flash game, and include my javascript library and flash reflector on your website.  Here is the example site I am currently hosting:

http://www.lastchancemedia.com/mariotoo/

This is a flash file running at 720x480, and all it does is echo button presses, very simple.  It also demonstrates the smart 'classic' mode and the PC-friendly keyboard bindings a la Wiicade's closed library.  Heavy redundancy and a better javascript setup mean I can handle upwards of 7 or 8 simultaneous button presses with no missed events to screw up your game state.  Here is the HTML for that webpage:

Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 strict//EN">
<html>
    <head>
        <title>MarioToo: A WiiMote Flash API</title>
        <script type="text/javascript" src="wiimote.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            CreateHTML('MarioToo_Demo.swf',720,480,'#FFFFFF','#CCCCCC');
        </script>
    </body>
</html>

Very very simple as you can see.  The CreateHTML call does all the heavy lifting for you, setting up and hiding the reflector, bla bla bla.  It takes params for the flash file URL, width, height, page color, and flash background color.  Moving on, here is all the code from the demo actionscript:

Code: [Select]
// MarioToo Wii Flash API Demo
//
// Version 1.0
// Author: Adam Saltsman <adam@lastchancemedia.com>
//
// A simple app to show how the MarioToo WiiMote API functions.

import mx.core.UIObject;
import com.lastchance.mariotoo.WiiMote;

class com.lastchance.mariotoo.MarioToo_Demo extends UIObject
{
var status:TextField;
var txtfmt:TextFormat;
function MarioToo_Demo()
{
WiiMote.init(); //initialize the wiimote
WiiMote.setClassic(true); //rotate the d-pad on the wii
WiiMote.bindDefaults(); //arrow keys, z, x, shift + ctrl
WiiMote.bind(WiiMote.BUTTON_A,65); //the 'a' key on the keyboard

txtfmt = new TextFormat();
txtfmt.size = 72;
txtfmt.color = 0xffffff;
txtfmt.align = "center";

createTextField("status", getNextHighestDepth(), 0, 200, 720, 100);
status.multiline = false;
status.selectable = false;
status.text = "";
}
function draw()
{
        if(!this.onEnterFrame)
            this.onEnterFrame = this.updateImage;
    }
function updateImage()
{
status.text = "";
if(WiiMote.isDown(WiiMote.BUTTON_A))
status.text = "A";
if(WiiMote.isDown(WiiMote.BUTTON_B))
status.text += " B";
if(WiiMote.isDown(WiiMote.BUTTON_1))
status.text += " 1";
if(WiiMote.isDown(WiiMote.BUTTON_2))
status.text += " 2";
if(WiiMote.isDown(WiiMote.BUTTON_PLUS))
status.text += " +";
if(WiiMote.isDown(WiiMote.BUTTON_MINUS))
status.text += " -";
if(WiiMote.isDown(WiiMote.BUTTON_UP))
status.text += " ^";
if(WiiMote.isDown(WiiMote.BUTTON_DOWN))
status.text += " v";
if(WiiMote.isDown(WiiMote.BUTTON_LEFT))
status.text += " <";
if(WiiMote.isDown(WiiMote.BUTTON_RIGHT))
status.text += " >";
if(status.text != "")
status.setTextFormat(txtfmt);
}
}

Again, very very straightforward stuff.  Nice and state-based, and the keyboard bindings mask themselves as regular wiimote buttons.  The 'classic' mode, which tilts the d-pad for NES-style play, is automatically avoided if you are using a keyboard, so no multi-config setups for different browsers, etc etc.

Finally, here is the download for the beta version 1.0:

http://www.lastchancemedia.com/mariotoo/MarioToo_b10.rar

It includes all the actionscript, javascript, compiled .swfs, and all that junk.  To get it to run on YOUR site, all you have to do is make sure you include the WiiBounce.swf and wiimote.js files in the same directory as your HTML.  Then, call CreateHTML to have wiimote.js write out your flash containers for you!  If you want to use the wiimote API in your flash file, just make sure you import wiimote.as.  A final note, all flash files were compiled using free, open source software: mtasc and swfmill.  Special thanks to those guys for making projects like this possible!

I think that's about it!  I'm always open to hearing about new features people would like, but I don't want this thing to get too bloated.  If you find bugs please let me know ASAP and I will fix them if the wii browser lets me :)

Thanks!
« Last Edit: April 02, 2007, 09:48:26 pm by AdamAtomic »

Offline willfaulds

  • 0010
  • *
  • Posts: 217
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #1 on: April 02, 2007, 04:01:41 pm
adam, awesome! I'll look in more detail later but it worked on my wii.

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #2 on: April 02, 2007, 04:47:52 pm
sweeet - I updated the links above but I've made at least a semi-proper home for it here:

http://www.lastchancemedia.com/mariotoo/

Thanks!

EDIT - updated the javascript a little bit to have better support for PC-side javascript detection, new version is available here:

http://www.lastchancemedia.com/mariotoo/MarioToo_b11.rar
« Last Edit: April 02, 2007, 06:43:01 pm by AdamAtomic »

Offline willfaulds

  • 0010
  • *
  • Posts: 217
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #3 on: April 02, 2007, 07:00:40 pm
excellent.

One minor problem i'm running the latest Mac OS X and Firefox for some reason your flash doesn't seem to pickup the CTRL key...

I don't know if you'd be interested but do you fancy trying to collab on a wii game?

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #4 on: April 02, 2007, 07:13:47 pm
hmmmm that's weird...i'm using the flash symbol Key.CONTROL for that, i have no idea why that wouldn't be working correctly, I am kind of a newb to flash!  any mac Flash experts out there have any insight?  also collabs are always interesting to me :D  PM or IM me your thoughts!

Offline snake

  • 0010
  • *
  • Posts: 314
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #5 on: April 02, 2007, 07:16:10 pm
If I had the slightest knowledge of how to program in Flash I'd be all over this.

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #6 on: April 02, 2007, 07:25:05 pm
I felt much the same way til a month or two ago - flash is basically javascript, its a total joke if you've ever programmed anything before.  You can even compile stuff for free using:

http://www.mtasc.org/ (an amazing opensource compiler)

and

http://swfmill.org/ (a not entirely amazing but generally decent asset thingy)

I used those two apps to build the demo in less than a day and this game for a client in less than a week (with no prior knowledge/experience):

http://www.wiimarbles.com/

Basically you compile your code with mtasc and swfmill brings it all together with embedded images etc.  Swfmill is definitely alpha software, but it wasn't that big a deal.  From what I hear game dev is even easier and faster if you bother to actually buy Studio or something.  The only limitation with the Wii (or the main one anyways) is that you are restricted to Flash 7-level of compatilibility.  Swfmill sucks at including sound/video, but music is better streamed anyways as far as flash is concerned, and it supports that happily.

Offline snake

  • 0010
  • *
  • Posts: 314
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #7 on: April 06, 2007, 11:12:25 pm
Coding sadly isn't my best field, being dyslectic. Takes a while to get through.

If flash could run a Multimedia Fusion .exe file, I'd be all set. Don't expect that to happen anytime soon though.

I'm considering a little Shmup project right now, but I reckon it's not going to end up in flash in the end.

Offline Soup

  • 0010
  • *
  • Posts: 182
  • Karma: +0/-0
  • Monkey lovvvvvvve
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #8 on: April 09, 2007, 12:56:09 pm
That's amazing! I wish I had flash. Definently would learn it. But what does the b button do?

Offline Stwelin

  • 0011
  • **
  • Posts: 567
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #9 on: April 09, 2007, 01:38:18 pm
I know actionscript, but i haaate programming in flash when it comes to games. such a pain in the rear.

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #10 on: April 09, 2007, 06:18:43 pm
Soup - there's no keyboard binding for the 'b' button in this demo.  You would add it the way the 'a' button is added. The default bindings are for classic play.

Stwelin - yeah, flash 8 added some blitting support that actually makes it much more friendly, unfortunately the wii only supports flash7.  Which means, in a nutshell, no tilemapping.  At all.  It's a bitch!  I'm working on a new game idea right now that will hopefully be a little more possible than my fleas game...

Snake - shmups, as long as their backgrounds aren't too fancy, are one of the few genres that actually DO work in flash.  If you get a decent amount of art together let me know!

Offline Stwelin

  • 0011
  • **
  • Posts: 567
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #11 on: April 09, 2007, 06:29:29 pm
Yeah, dot-invasion's Meteor Buster is actually a really nice shmup. made in flash! you wouldn't be able to tell, it plays more like an actuall app. than a flash game. very fun too.

Offline Feron

  • 0100
  • ***
  • Posts: 1123
  • Karma: +0/-1
  • Carpe Diem
    • View Profile
    • Pixelheart

Re: a new, better wiimote flash api in just 24 hours!

Reply #12 on: April 09, 2007, 10:59:26 pm
hmmmm that's weird...i'm using the flash symbol Key.CONTROL for that, i have no idea why that wouldn't be working correctly, I am kind of a newb to flash!  any mac Flash experts out there have any insight?  also collabs are always interesting to me :D  PM or IM me your thoughts!

on mac the ctrl key is replaced by the command key.  the other buttons works fine for me - maybe it neds to be mentioned that is your using mac its the apple/command key instead.

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #13 on: April 09, 2007, 11:22:25 pm
i think kenta cho's new weird shmup runs in flash too...also thanks for the update feron I will include that next time i change the documentation or website!

Offline willfaulds

  • 0010
  • *
  • Posts: 217
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #14 on: April 14, 2007, 01:32:17 pm
i think http://www.strille.net/works/misc/platform_demo/ is a very good example of what flash can do in the rights hands

Offline RobHine

  • 0001
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #15 on: July 29, 2007, 01:25:21 am
Hi guys, sorry to reply here but I wish to ask a question about this api and couldn't find any forums on AdamAtomics website, is this possible to integrate using just the open source tools or would I need to have flash mx installed for the event dispatcher, i am very interested in creating flash games using the wii remote and learning from the tutorials on this website, but I don't really know how to start with just these tools. Thankyou for your patience.

ps If this is the wrong place to talk about this i appologise, i couldn't find any threads other than this one about this api.
« Last Edit: July 29, 2007, 01:26:54 am by RobHine »

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #16 on: August 03, 2007, 10:12:16 pm
Ok, with Rob's help comes beta version 1.3:

http://www.lastchancemedia.com/mariotoo/

Cool new features include .fla files in the developer's download, support for up to 4 wiimotes, and a variety of safety/bug fixes!

Offline mikedoty

  • 0001
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #17 on: August 06, 2007, 03:15:21 am
I logged in just so I could mention how poorly documented I find this enterprise.  I've spent too much time in the last couple of days trying to get this thing to work.  The example code in this post, while incomplete, helps me; why isn't it anywhere to be found in the downloads or on its official website?  :?

It looks like it would work great if I could figure out how to implement it in the first place.

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #18 on: August 06, 2007, 05:14:29 am
Heh.  Didn't know it was an enterprise!  And yes, it is poorly documented.  However, the example code featured at the top of this thread is included in the download, in com/LCM/mariotoo/FlashMX/MarioToo_Demo.as, which is part of the mariotoo.fla project file.  Beginner-level knowledge of com paths and either the flash open source software OR the proper flash IDE is definitely recommended if you wish to continue pursuing the use of this API.

Future releases may be better documented, but it is unlikely!

EDIT - Yeah all the source files that you would need are available in both the developer and non-developer downloads for b1.3...the only thing I can think of is that you didn't edit the com path for the mariotoo.fla.  If you go into Publish Settings, Actionscript Tab, and click on Actionscript Settings, just set the com path to wherever you unzipped these files to (e.g. C:\Downloads\WiiMoteCrap\), and it should compile and run just fine, and you can dig through the source to see how everything works.  Best of luck!
« Last Edit: August 06, 2007, 05:17:53 am by AdamAtomic »

Offline RobHine

  • 0001
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #19 on: August 06, 2007, 10:42:11 am
First thing we'll need to know is if you are going down the Flash MX route or via Open Source software, then we may be able to help, The library, while working is still in beta as stated on the site, which basically means there is more to do before it is finished, i.e we have not written proper docs for it as the api is evolving regularly, and maintaining these while we are still adding new features would take away time from programming the library, and with 3 possible development environments there would need to be a lot of writing done to ensure anybody can pick up the library and put it together a game.

Having said that I think the source is fairly easy to understand once you understand the com tree, the wiibounce swfs all come ready built and all you realisticly need worry about is looking at the mariotoo demo and modify the html in the root directory to use the name of your app, the demo honestly has all you need to get going with developing a game.

In light of your comments however I will try and put together a small tutorial on using MTASC and SWFMill to create a basic application the free way, if Adam can host it. I have no access to the Flash IDE so I can't help there.

Good luck.

Rob.

Offline Lee N

  • 0001
  • *
  • Posts: 98
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #20 on: August 07, 2007, 10:48:24 am
Opera has released an official API for the Wiimote now..

http://dev.opera.com/articles/view/the-wii-remote-api/

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #21 on: August 07, 2007, 03:59:43 pm
Yes that's what we're using :)  It's a javascript API, not Flash.  We're working on a new version right now that will include roll and distance from TV using just a single bouncer instead of the 4 it currently uses...