Thoughts are our internal ideas, opinions and creative musings.

Our Senses

Mouse Cursors — ButtonMode — on Sprites in Papervision Materials

Jason Farrell on April 10th, 2009

Papervision (the awesome 3D engine for ActionScript 3) is limited when it comes to standard flash interactivity. Specifically something called buttonMode. When you put buttonMode = true on a 2D sprite in flash, it puts a nice cursor over your sprite, hence making it look like a button or a link.

We use Pv3d’s MovieMaterial to texture most of our interactive 3D elements. The MovieMaterial is usually made from a sprite with children that could contain links. Pv3d doesn’t render a cursor when you hover over it, but does allow event listeners when you set interactive = true on the MovieMaterial. This gives us room for applying some unconventional methods to give us a nice pointer cursor when moving the mouse over the buttons.

My first idea was to dispatch an event and have my controller class listen and then change the mouse cursor to be an image of a mouse pointer. This ended up really clunky, especially when I have heavy 3D that slows down the frame rate. So the Faux mouse cursor moved very slowly and I axed the idea.

Then I came up with an idea that actually works very smoothly. Instead of loading in a fake cursor that replaces the mouse, I wrote a 2D sprite class that follows the mouse when the mouse hovers over the interactive sprites in 3D. This sprite would then have buttonMode = true so the mouse turns to a pointer. After that I set the sprite’s alpha to 0 so the user sees nothing happening except for their mouse cursor changing. When the user clicks, it hides the sprite so the mouse event inside the 3D material is still active. Just be sure to make your links in 3D on MOUSE_UP instead of MOUSE_CLICK

_contentLink.addEventListener(MouseEvent.MOUSE_UP, onContentLinkClick);

Download the Cursors.as class

Usage:

private function onSpriteLinkOver(e:MouseEvent):void{

      _cursors.start();

}

private function onSpriteLinkOut(e:MouseEvent):void{

      _cursors.stop();
}
Post comment as twitter logo facebook logo
Sort: Newest | Oldest

Can you share a code sample of a basic hello world of a Sprite panel with links and buttons (form elements) inside of a Papervision3d context using your cursor class?

Understanding the PV3D event integration of 2D stuff rendered in 3D is troublesome.

Thanks
Tony

viewport.buttonMode = true;

that should do it for you.. no?

i would assume if u have something interactive within your moviematerial you have some sort of MouseEvent.MOUSE_OVER associated with it. simply add the above code in the listener function. i dont see why you would be making class's just to hand a cursor when it does it for you quite easily

I found a better solution here: http://www.kirupa.com/forum/showthread.php?t=310708

Aha, remember to add this cursor to the stage after you add viewport.

@ Rebekah:
Papervision isn't design software. It's an Actionscript class library that provides a 3D engine for Flash.

I'd try to comment but I fell off the wagon at "Papervision..." I definately don't know design software...

Awesome man. This helps! I'm using your Cursors class. Thanks for this tip! :)

Blog Categories

Blog Archives

Our Activity

UA5 on FB

Our Newsletter

Strategy Design Dev