Created
May 19, 2016 04:00
-
-
Save james4k/113f33e6a176b6e3b37c91faea9f1034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import openfl.display.Bitmap; | |
import openfl.display.BitmapData; | |
import openfl.display.Sprite; | |
import openfl.events.Event; | |
import openfl.geom.Rectangle; | |
import openfl.Assets; | |
class Main extends Sprite { | |
public function new () { | |
super (); | |
var container = new Sprite (); | |
container.x = 20; | |
container.y = 20; | |
container.scrollRect = new Rectangle (0, -150, 500, 250); | |
addChild (container); | |
var bitmap = new Bitmap (Assets.getBitmapData ("assets/openfl.png")); | |
container.addChild (bitmap); | |
var scrollRectOutline = new Sprite (); | |
scrollRectOutline.graphics.lineStyle (1, 0x000000, 0.1); | |
scrollRectOutline.graphics.drawRect (container.x, container.y, container.scrollRect.width, container.scrollRect.height); | |
addChild (scrollRectOutline); | |
var actualBoundsOutline = new Sprite (); | |
addChild (actualBoundsOutline); | |
var hits = new Sprite (); | |
addChild (hits); | |
addEventListener (Event.ENTER_FRAME, function (event:Event):Void { | |
var bounds = bitmap.getBounds (this); | |
actualBoundsOutline.graphics.clear (); | |
actualBoundsOutline.graphics.lineStyle (1, 0xff0000, 1.0); | |
actualBoundsOutline.graphics.drawRect (bounds.x, bounds.y, bounds.width, bounds.height); | |
hits.graphics.clear (); | |
hits.graphics.beginFill (0xff0000); | |
for (y10 in 0...Std.int(stage.stageHeight/10)) { | |
for (x10 in 0...Std.int(stage.stageWidth/10)) { | |
var x = x10*10; | |
var y = y10*10; | |
if (bitmap.hitTestPoint (x, y)) { | |
hits.graphics.drawRect (x, y, 1, 1); | |
} | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment