Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-23-2009, 08:24 PM   #1
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,810
Send a message via AIM to abeall
Default hitTestPoint oddity; doesn't work until next frame?

I'm seeing some weird behavior with hitTestPoint. It should be reproducible with the attached code.

If I move a display object and use hitTestPoint afterward on the same frame against a point within the object's new shape bounds, I get false no matter what. On the following frame I get true like I should. If I then move the object away and in the same frame hitTestPoint against a point which is NO LONGER in the current shape (since it moved) but WAS in the shape on the previous frame, I sometimes get true and sometimes get false. This seems totally screwed up. Am I going mad? I've tried the move and hitTestPoint in both mouse handles and enterFrame handlers, but enterFrame handler is the only one I really care about at the moment.

Check out the following code; click to define a new position for the large object, then in the next entetFrame event it will move it and perform hitTestPoint -- object turns orange when hitTestPoint is true. You should see the same weird behavior described above.

Any suggestions other than throwing away hitTestPoint and using some mathematical approximation?

ActionScript Code:
var circ:Shape = new Shape(); circ.graphics.beginFill(0x009900); circ.graphics.drawCircle(0, 0, 30); addChild(circ); var dot:Shape = new Shape(); dot.graphics.beginFill(0xFF0000); dot.graphics.drawCircle(0, 0, 2); dot.x = 250; dot.y = 250; addChild(dot); stage.addEventListener("mouseDown", mouseDown); stage.addEventListener("enterFrame", enterFrame); var clicked:Boolean = false; function mouseDown(e){     clicked = true; } function enterFrame(e){     if(clicked){         clicked = false;         circ.x = mouseX;         circ.y = mouseY;         var hit:Boolean = circ.hitTestPoint(dot.x, dot.y, true);         circ.transform.colorTransform = new ColorTransform(1,1,1,1,hit ? 0xFF : 0);         trace(hit)     } }
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter

Last edited by abeall; 11-23-2009 at 08:27 PM.
abeall is offline   Reply With Quote
Old 11-23-2009, 08:36 PM   #2
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,810
Send a message via AIM to abeall
Default

This seems to only happen when the shapeflag is true. Turning it off isn't a solution in my situation, but in others it might be good info to know...
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Old 11-24-2009, 10:36 PM   #3
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,810
Send a message via AIM to abeall
Default

Well, here's one ridiculous solution that worked in this situation: I performed the hitTestPoint before moving the object and projected the x,y relative to the amount the object is going to move. In other words:
ActionScript Code:
var point:Point = new Point(mouseX, mouseY); var hit:Boolean = circ.hitTestPoint(dot.x - (point.x - circ.x), dot.y - (point.y - circ.y), true); circ.x = point.x; circ.y = point.y;

It works in this case, but it would get hairy if scaling and rotation was involved...
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:23 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.