本文介绍了AS3:定义命中区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含位图的影片剪辑,我不想增加命中区域.我知道我可以在它后面添加一个透明的形状,但这是为 ios 编译的,我不想导致不必要的重绘.

I have a movieclip which contains a bitmap and I wan't to increase the hit area. I understand I can add a transparent shape behind it but this is to be compiled through air for ios and I don't want to cause unnecessary redraws.

有没有办法将矩形定义为命中区域或其他解决方案?

Is there a way to define a rectangle as the hit area or another solution perhaps?

推荐答案

有一个特殊的 hitArea 字段用于此目的.

There is a special hitArea field for that purposes.

  const MOUSE_ZONE_SIZE:Number = 10;
  const hitArea:Sprite = new Sprite()
  hitArea.graphics.beginFill( 0xFFFFFF );
  hitArea.graphics.drawRect( -MOUSE_ZONE_SIZE, -MOUSE_ZONE_SIZE, MOUSE_ZONE_SIZE* 2, MOUSE_ZONE_SIZE* 2 );
  hitArea.mouseEnabled = false;
  hitArea.visible = false;
  hitArea.x = bitmap.x
  hitArea.y = bitmap.y
  bitmap.hitArea = hitArea;
  addChild( bitmap );
  addChild( hitArea );

不幸的是,即使您覆盖 InteractiveObject 的 hitTest* 函数,它们也不会用于鼠标事件调度:( 如果有人知道如何强制 Flash 使用覆盖的方法 - 我也想知道.

Unfortunately even if you override hitTest* function of InteractiveObject they will not be used for mouse-events dispatching :( If somebody knows how to force Flash to use overridden methods - I'd like to know it too.

这篇关于AS3:定义命中区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 20:19