AS3:HitTest任何对象 [英] AS3: HitTest Any Object

查看:128
本文介绍了AS3:HitTest任何对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将图像用作光标的应用程序.现在我想随时知道光标悬停在哪个对象上.有点像HitTestObject(*),然后我可以在其中看到*表示什么对象.有谁知道我怎么能做到这一点? (并且不能使用鼠标)

I am working on an application where an image serves as cursor. Now i would like to know at any time over which object the cursor is hovering. Sort of like a HitTestObject(*) where i can then see what object the * represents. Does anyone have any idea how i could accomplish this? (and using the mouse is not an option)

推荐答案

我已经解决了这个问题:)因为游标与其他游标不在同一个精灵中,所以我必须这样做,因为我做不到传递对象以将其悬停到数组中.

I have solved the problem already :) since the cursor was in a different sprite than the others, i had to do it this way, because i couldn't pass the objects to hover into an array.

        //First we will create a point that contains the x and y of this cursor.
        var _position:Point = new Point(x + (width/2), y + (height/2));

        //Secondly, we will get an array of elements that are under this point.
        var _objects:Array = parentApplication.getObjectsUnderPoint(_position);

        //If the length of the objectsList is longer than or equal to 2, we may assume that
        //there is an object
        if(_objects.length >= 2)
        {
            //Set the currentObject variable to the object the cursor is hovering over.
            //The minus two is simple. The cursor is always the last object under that point,
            //so we need the object before that.
            _currentObject = _objects[_objects.length - 2];

            //dispatch the event in the object.
            dispatchCursorEventToObject(EyeEvent.CURSOROVER);
        }

这篇关于AS3:HitTest任何对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆