Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthorpyiap
- CommentTimeApr 7th 2008 edited
I'm tying to integrate the particle system into a game I've been working on and I've run into an issue with mouse events. I've created a new class that extends a MovieClip which manages emitters. A problem occurs when I put the particle layer above any layer that that utilizes mouse events but it works fine when it is put below layers that have mouse events. Any help with this problem would be much appreciated. -
- CommentAuthorericr
- CommentTimeApr 7th 2008
What layer is it that's "between" the working and not working layers? Does that layer's MouseEvent handler capture the events? -
- CommentAuthorpyiap
- CommentTimeApr 7th 2008 edited
Here's an example of what the stage looks like
-> particle place holder layer movieclip (basically an empty movieclip object)
----> particle manager movieclip object
---------> particles are physically added here
-> mouse handler layer place holder movieclip
----> movieclip with mouse event handlers
If i swap the particle place holder layer with the mouse handler layer mouse events are captured. So in essence I can only capture mouseEvents if the particles are layered below any layers that need to trigger them.
Here's a project example
http://students.washington.edu/pyiap/ParticleLayer.zip
http://students.washington.edu/pyiap/WorkingProject.swf
http://students.washington.edu/pyiap/NotWorking.swf
In the example, the test image in the center of the screen should turn blue on the MouseOver event. The only difference between the working and not working swf is the layering order. -
- CommentAuthorRichard
- CommentTimeApr 8th 2008
The BitmapRenderer creates a Bitmap object in which to draw the particles. When the Renderer is above your button the BitmapRenderer will receive the mouse events rather than your button. The solution that springs to mind (there may be another better option) is to track the mouse and use a hit test to check when it interacts with your button. Like thispackage
{
import flash.display.MovieClip;
import flash.events.Event;
public class myButton extends MovieClip
{
public var over:Boolean = false;
public function myButton()
{
mcOver.visible = false;
addEventListener(Event.ENTER_FRAME, myButtonTest);
}
public function myButtonTest( event:Event ):void
{
var newOver:Boolean = mcOn.hitTestPoint( stage.mouseX, stage.mouseY, true );
if( newOver != over )
{
over = newOver;
if( over )
{
myButtonOver();
}
else
{
myButtonOut();
}
}
}
public function myButtonOver():void
{
mcOver.visible = true;
mcOn.visible = false;
}
public function myButtonOut():void
{
mcOver.visible = false;
mcOn.visible = true;
}
}
} -
- CommentAuthorericr
- CommentTimeApr 8th 2008
The other thing to do is make sure that all of your MovieClips have the appropriate enabled settings.
Also, look at this:
Additionally, consider whether you want the children of your sprite to be mouse enabled. Most buttons do not enable mouse interactivity for their child objects because it confuses the event flow. To disable mouse interactivity for all child objects, you must set the mouseChildren property (inherited from the DisplayObjectContainer class) to false.
The above is from the Sprite->buttonMode explanation. Check out the DisplayObjectContainer->mouseChildren information. I find that Adobe's "Default" values don't always play out as such. Try setting this explicitly yourself and see if it helps.
The scenario mentioned by Robert would only occur if the BitmapRenderer was set to Capture the mouse events. It may be set to do so by default (something may get confused in the creation of new objects within the BitmapRenderer definition). Read up on Flash's Event Flow. Also, make sure that you have the MouseEvents registered with the appropriate MouseHandler object and not the BitmapRenderer.
Sweet. -
- CommentAuthorpyiap
- CommentTimeApr 8th 2008 edited
Thanks for the replies.
I've tried setting the enabled, buttonMode, and mouseChildren properties on every different level I could do (place holder movieclip, manager movieclip, even inside the BitmapRenderer class) and the mouse events still doesn't seem to register. I've also tried explicitly setting those values to true for the movieclips that need to them to be. Though adding the ENTER_FRAME event and checking the state of the mouse would solve the issue, it seems very inefficient to add that to all the interactive objects within the game.
I'm not very familiar with the inner workings of flash, but I'm don't understand why the bitmap object would capture mouse events since it can't dispatch mouse events, even when you disable the container class from receiving mouse events.
Bitmap -
- CommentAuthorericr
- CommentTimeApr 8th 2008 edited
I'm not very familiar with the inner workings of flash, but I'm don't understand why the bitmap object would capture mouse events since it can't dispatch mouse events, even when you disable the container class from receiving mouse events.
I see your point. The BitmapRenderer is, however, a Sprite (via inheritance). That's what I meant to check out :)
As for the rest of it, how exactly are you adding all of these to the scene? There may be something wrong with the way you're defining stuff such that your mouseHandler layer look like Child2Node in the diagrams in the Event Flow documentation.
I.e. by this:-> particle place holder layer movieclip (basically an empty movieclip object)
----> particle manager movieclip object
---------> particles are physically added here
-> mouse handler layer place holder movieclip
----> movieclip with mouse event handlers
do you mean this:// Particle stuff.
particlePlaceHolder:MovieClip;
Stage.addChild(particlePlaceHolder);
particleManager:MovieClip;
particlePlaceHolder.addChild(particleManager);
particles:SomeRenderer;
particleManager.addChild(particles);
// Mouse stuff.
mouseLayer:MovieClip;
Stage.addChild(mouseLayer);
mouseEventHandlers:MovieClip;
mouseLayer.addChild(mouseEventHandlers);
mouseEventHandlers.addEventListener(MouseEvent:UP, mouseUpfunction);
// etc.
Does your code look like that? What's added to what? If it does look like that than I have to say that you've got a lot of [expensive] wasted objects. For instance, the entire mouseLayer architecture could be redundant because particlePlaceHolder is a MovieClip and can thus receive Mouse Events.
Also note that, provided you're using the default BitmapRenderer, the Sprite you define by using the BitmapRenderer code is immediately resized to the size of the Stage. If you don't have the mouseLayer directly between the Stage and the BitmapRenderer in the Event Flow structure and your BitmapRenderer is above the MouseHandler then you're not going to receive any messages anywhere. You'll be looking at the "Child2 Node" scenario from the Event Flow docs.
How are you calling all of the addChild() calls? Can you post them all?
Before you respond to this, see the next post. -
- CommentAuthorericr
- CommentTimeApr 8th 2008 edited
@Richard:
The way I would do it would be:- 1) In a simple project, use the Stage for handling mouse events.
- In a complex project, explicitly turn off Mouse Event handling in the WhateverRenderer object and then add the particle emitter in the right event flow space (depends on project).
@pyiap:
Come to think of it, did you ever try explicitly turning those values off for the BitmapRenderer? I bet that's the problem. By removing that object from the Mouse Handling code it allows the mouse to 'go through' it. Try something like:particlePlaceHolder.mouseEnabled = false;
particlePlaceHolder.mouseChildren = false;
Where particlePlaceHolder is the object you add to the Stage and into which you add the ParticleManager and whatever.
The above code explicitly disables MouseEvents for the objects - the clicks should go right through. -
- CommentAuthorpyiap
- CommentTimeApr 8th 2008
Wow thanks.
particlePlaceHolder.mouseEnabled = false;
particlePlaceHolder.mouseChildren = false;
did the trick.
I was calling
particlePlaceHolder.enabled = false;
particlePlaceHolder.mouseChildren = false;
Also I'm really digging the particle system. Keep up the great work you're doing. -
- CommentAuthorericr
- CommentTimeApr 8th 2008
Nice, glad you got everything worked out!
Definitely props to Richard for his work on Flint. Such a fantastic resource! -
- CommentAuthorRichard
- CommentTimeApr 9th 2008
renderer.mouseEnabled = false;
is definitely better than my long winded solution. I thought there should be a property like this and hoped someone would find it for me. Now I'm wondering if this should be the default setting for renderers. What's your opinion on this? -
- CommentAuthorericr
- CommentTimeApr 9th 2008
@Richard:
I definitely agree with that sentiment. If someone wants to interact directly with the particles (and not with, say, something they're mounted to) then they should specify that. Perhaps you could set it as such and then toss up a note in the ASDocs?
1 to 12 of 12
