I’ve been doing a lot of really cool stuff with WiiFlash at the Bank – but I can’t really share any of the code. So, to help any aspiring WiiFlash developers out there, I’ll post a few tips over time with things that would have helped me out. If you don’t know anything about WiiFlash, take a look at their site, it’s a pretty cool hack. Now that I’ve got a good working class system, I just want to sit around and create mini-games. I wish that I had the free time!
Tip #1 -Using the Wii Controller as a mouse in Flash
The toughest problem that I’ve come across so far: “how do you use the controller as a mouse (click on buttons) in a Flash movie without relying on WiiFlash’s crappy mousemode?”The “mousemode” feature takes over control of the system mouse pointer and uses the controller to point and click. I didn’t want this – I just wanted a nice Flash sprite moving around and still allow the user to click on things with their real mouse. But I wasn’t quite sure how to have this sprite fire off mouse events.
Solution: Senocular’s VirtualMouse class.
Once you’ve figured out how to read the IR points from a sensor bar (a future tip), and have a pointer moving around the screen, just set your virtual mouse instance’s X and Y values to the same as the pointer sprite. Trap the A button press event to fire off a virtual mouse CLICK event and that’s it! Well, I guess there are a few details to fill in still – but you get the general idea. Get it working properly and you can interact with your movie/game with the mouse and the Wii controller.
[…] I posted the Wii mote as a mouse tip, I’ve seen the same method pop up on a few blogs. Unic8 has a good demo with source of […]
Hi,
at the moment, i use the mouseControl function. For adding a nice sprite, you could use the static class CursorManager and for hide the mouse set Mouse.hide(). It works also fine and is realy fast.
I didn’t want to take complete control of the user’s mouse – it’s “friendlier” to the user to let them have their mouse and just have the Wii mote control it’s own cursor. It’s also not as confusing.
Another one of my goals was to have an interface that could be controlled (to a degree) by either the mouse or the Wii controller.
ah, okay thats logical. If WiiFlash open here server, i am hopefull that i could manipulate this function.
[…] February, I posted about using the Wii remote as a virtual mouse in Flash. While that approach seems to work just fine in a simple single player application, I […]
Hey guys:
After all the open source code that’s helped me out, I figure I owe everyone this. While this solution might not be perfect, it will give you guys out there just starting with WiiFlash a starting point.
Use the IR sensor information and convert it to screen coordinates:
if you open the demo of the wii remote that came with WiiFlash and scroll to the bottom of the actionscript, you’ll find the function onUpdated. Place the following code inside this function:
var mouser.x = ((pEvt.target.ir.x1 * stage.stageWidth)*-1)+stage.stageWidth;
///traces the x position
var mouser.y = pEvt.target.ir.y1 * stage.stageHeight;
//traces the y postion
//Now create a movieClip instance on the stage, and onEnterFrame, set it’s x and y coords to mouser.x and mouser.y.
//warning: mousing offstage produces NaN. As I literally just discovered what the heck this was doing a minute ago, I haven’t solved this problem, but this shouldn’t be a difficult solve.
//Happy experimenting, and I hope I’ve repayed my debt.
Great stuff guys. Luke, which specific file in the WiiFlash samples are you referring to? I’m trying to build some more simplistic mouse control (or even fake mouse control). Simply enabling mouseControl causes my mouse cursor to immediately pin to the right edge of the screen for some reason… The gestures and motion could be used I guess…