actionscript 3 - Starling mouseover detection -
i'm making point & click game clickable objects. when player moves mouse on object, there appear tooltip beside cursor. works intended code below:
private function added():void { removeeventlistener(event.added, added); this.addeventlistener(touchevent.touch, ontouch); } protected function ontouch(e:touchevent):void { var touchhover:touch = e.gettouch(this, touchphase.hover); if (touchhover) { trace("show"); //mouse hovered on object. hence phone call hovertext: if (game.hovertext.message != name_) game.hovertext.message = name_ } else { //mouse leaves object trace("hide"); game.hovertext.hidemessage(name_); } }
however, has unusual problem don't understand. if move mouse on object , move downwards still staying on object, triggers hiding function in every sec frame or so. same thing happens when move cursor right, not when moving or left.
so question wrong code? best way go observe when mouse rolls on object , when rolls away?
edit: have been going through next iterations each of them same problem:
var touch:touch = event.gettouch(this); if (touch == null) { // set object alpha 0; //trace("pois"); game.hovertext.hidemessage(name_); } else if (touch.phase == touchphase.hover) { // set object alpha 1; //trace("paalla"); if (game.hovertext.message != name_) game.hovertext.message = name_; } else { // phase begin/move/stationary case // see if touch on bounds of tile (assuming 'this' tile) helper_point.x = touch.globalx; helper_point.y = touch.globaly; this.globaltolocal(helper_point, helper_point); if(this.hittest(helper_point, true) != null) { // set object alpha 1; on tile trace("paalla"); } else { // set object alpha 0; not on tile trace("pois"); }
} var touchhover:touch = e.gettouch(this); if (touchhover && touchhover.phase == touchphase.hover) { trace("show"); //mouse hovered on object. hence phone call hovertext: if (game.hovertext.message != name_) game.hovertext.message = name_ } if (touchhover == null) { //mouse leaves object trace("hide"); game.hovertext.hidemessage(name_); }
also here swf demonstating problem: http://www.students.tut.fi/~salmi26/scorpionbox.html
private function ispressed(event:touchevent):void { var touch:touch = event.gettouch(this); if(touch.phase == touchphase.began){ trace("show"); //mouse hovered on object. hence phone call hovertext: if (game.hovertext.message != name_) game.hovertext.message = name_ } else if(touch.phase == touchphase.ended){ trace("release"); //stop doing stuff removeeventlistener(event.enter_frame, onbuttonhold); } }
actionscript-3 hover mouseover starling-framework
No comments:
Post a Comment