From 8f337e26d9089898a419f11fd8575ccaad797c94 Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Tue, 17 Aug 2010 17:06:54 +0000 Subject: [PATCH] Wire up for hit-testing just like object tiles. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@986 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/cast/CharacterSprite.as | 12 +++++------- src/as/com/threerings/cast/MultiFrameBitmap.as | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/as/com/threerings/cast/CharacterSprite.as b/src/as/com/threerings/cast/CharacterSprite.as index cfe6f044..39c70be9 100644 --- a/src/as/com/threerings/cast/CharacterSprite.as +++ b/src/as/com/threerings/cast/CharacterSprite.as @@ -274,6 +274,11 @@ public class CharacterSprite extends Sprite } } + public function hitTest (stageX :int, stageY :int) :Boolean + { + return _framesBitmap == null ? false : _framesBitmap.hitTest(stageX, stageY); + } + /** The action to use when at rest. */ protected var _restingAction :String = StandardActions.STANDING; @@ -297,13 +302,6 @@ public class CharacterSprite extends Sprite /** The currently active set of bitmaps for this character. */ protected var _framesBitmap :MultiFrameBitmap; - /** The offset from the upper-left of the total sprite bounds to the - * upper-left of the image within those bounds. */ - protected var _ioff :Point = new Point(); - - /** The bounds of the current sprite image. */ - protected var _ibounds :Rectangle = new Rectangle(); - /** The orientation of this sprite. */ protected var _orient :int = DirectionCodes.NONE; diff --git a/src/as/com/threerings/cast/MultiFrameBitmap.as b/src/as/com/threerings/cast/MultiFrameBitmap.as index 0333e470..60daae28 100644 --- a/src/as/com/threerings/cast/MultiFrameBitmap.as +++ b/src/as/com/threerings/cast/MultiFrameBitmap.as @@ -22,6 +22,8 @@ package com.threerings.cast { import flash.display.Bitmap; import flash.display.Sprite; +import flash.geom.Point; + import flash.events.Event; import com.threerings.media.Tickable; @@ -73,6 +75,22 @@ public class MultiFrameBitmap extends Sprite return _frames.length; } + public function hitTest (stageX :int, stageY :int) :Boolean + { + if (_curFrameIndex == -1) { + return false; + } else { + var frame :Bitmap = getFrame(_curFrameIndex); + if (frame.hitTestPoint(stageX, stageY, true)) { + // Doesn't even hit the bounds... + return false; + } + // Check the actual pixels... + var pt :Point = frame.globalToLocal(new Point(stageX, stageY)); + return frame.bitmapData.hitTest(new Point(0, 0), 0, pt); + } + } + protected var _frames :Array; protected var _bitmap :Bitmap;