Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 is hovered over this object. Therefore call Hovertext:
- if (Game.hoverText.message != name_)
- Game.hoverText.message = name_
- }
- else
- {
- //mouse leaves the object
- trace("hide");
- Game.hoverText.hideMessage(name_);
- }
- }
- var touch:Touch = event.getTouch(this);
- if (touch == null) {
- // Set Object alpha to 0;
- //trace("pois");
- Game.hoverText.hideMessage(name_);
- }
- else if (touch.phase == TouchPhase.HOVER) {
- // Set Object alpha to 1;
- //trace("paalla");
- if (Game.hoverText.message != name_)
- Game.hoverText.message = name_;
- }
- else {
- // for a phase BEGIN/MOVE/STATIONARY case
- // see if the touch is over the bounds of the tile (assuming 'this' is the 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 to 1; over tile
- trace("paalla");
- }
- else
- {
- // Set Object alpha to 0; not over tile
- trace("pois");
- }
- var touchHover:Touch = e.getTouch(this);
- if (touchHover && touchHover.phase == TouchPhase.HOVER)
- {
- trace("show");
- //mouse is hovered over this object. Therefore call Hovertext:
- if (Game.hoverText.message != name_)
- Game.hoverText.message = name_
- }
- if (touchHover == null)
- {
- //mouse leaves the object
- trace("hide");
- Game.hoverText.hideMessage(name_);
- }
- private function isPressed(event:TouchEvent):void
- {
- var touch:touch = event.getTouch(this);
- if(touch.phase == TouchPhase.BEGAN){
- trace("show");
- //mouse is hovered over this object. Therefore 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);
- }
- }
- import starling.events.Touch;
- import starling.events.TouchEvent;
- import starling.events.TouchPhase;
- private var touches:Vector.<Touch>;
- private var touch:Touch;
- private var touchStage:Touch;
- private function onTouch(e:TouchEvent=null):void {
- touches= e.getTouches(DisplayObject(e.target));
- if (touches.length == 1)
- {
- touch = touches[0];
- if (touch.phase == TouchPhase.BEGAN){
- m_TouchTarget = touch.target;
- //HERE IS A MOUSE DOWN
- }
- if (touch.phase == TouchPhase.ENDED){
- m_TouchEndedPoint = new Point(touch.globalX, touch.globalY);
- if (stage.hitTest(m_TouchEndedPoint, true) == m_TouchTarget)
- {
- //HERE IS A MOUSE UP
- }
- }
- if (touch.phase == TouchPhase.MOVED){
- m_TouchEndedPoint = new Point(touch.globalX, touch.globalY);
- //HERE IS A MOUSE OUT
- if (stage.hitTest(m_TouchEndedPoint, true) != m_TouchTarget)
- {
- //HERE IS A MOUSE OVER
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement