jasu's blog
블로그 메뉴검색결과 리스트
rotation에 해당되는 글 1건
- 2012.01.12 Starling 이미지 로드 및 scale & rotation
글
Starling 이미지 로드 및 scale & rotation
Programming/Framework
2012. 1. 12. 10:52
package { import starling.events.Event; import starling.core.Starling; import starling.display.Sprite; import starling.display.Button; import starling.display.Image; import starling.textures.Texture; import starling.events.Touch; import starling.events.TouchEvent; import starling.events.TouchPhase; import starling.animation.Tween; import starling.animation.Transitions; import starling.utils.deg2rad; import starling.display.DisplayObject; import starling.text.TextField; import starling.utils.HAlign; import starling.utils.VAlign; import utils.TouchSheet; import flash.geom.Rectangle; import flash.geom.Point; import flash.display.Bitmap; import flash.net.URLRequest; import flash.display.Loader; import flash.events.Event; public class Demo extends Sprite { private var _loader:Loader; private var _image:Image; private var _posText:TextField; private var _sheet:TouchSheet; public function Demo() { _loader = new Loader(); _loader.load(new URLRequest("https://t1.daumcdn.net/cfile/tistory/11252E424F0ADA1C06")); _loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, onLoadedHandler); } private function onLoadedHandler(e:flash.events.Event):void{ var bitmap:Bitmap = _loader.content as Bitmap; var texture:Texture = Texture.fromBitmap(bitmap); _image = new Image(texture); var description:String = "- touch and drag to move the images \n" + "- pinch with 2 fingers to scale and rotate \n" + "- double tap brings an image to the front \n" + "- use Ctrl/Cmd & Shift to simulate multi-touch"; var infoText:TextField = new TextField(300, 75, description); infoText.x = 10; infoText.y = 35; infoText.fontSize = 12; infoText.color = 0x999999; infoText.vAlign = VAlign.TOP; infoText.hAlign = HAlign.LEFT; addChild(infoText); _sheet = new TouchSheet(_image); _sheet.scaleX = 0.2; _sheet.scaleY = 0.2; setAlignCenter(_sheet); _sheet.addEventListener(TouchEvent.TOUCH, onTouchHandler); addChild(_sheet); _posText = new TextField(400, 480, ""); _posText.x = 10; _posText.y = 105; _posText.fontSize = 12; _posText.color = 0xBBBBBB; _posText.vAlign = VAlign.TOP; _posText.hAlign = HAlign.LEFT; _posText.touchable = false; addChild(_posText); stage.addEventListener(starling.events.Event.RESIZE, onResizeHandler); } private function onTouchHandler(e:TouchEvent):void{ var touches:Vector.<Touch> = e.getTouches(_sheet); _posText.text = "_sheet.x : "+_sheet.x+"\n"+ "_sheet.y : "+_sheet.y+"\n"+ "_sheet.width : "+_sheet.width+"\n"+ "_sheet.height : "+_sheet.height; var len:int = touches.length; for(var i:int=0;i<len;i++){ var touch:Touch = touches[i]; var currentPoint:Point = touch.getLocation(_sheet); var previousPoint:Point = touch.getPreviousLocation(_sheet); _posText.text +="\n\n"+"touches["+i+"]========================\n"+ "previousGlobalX : "+touch.previousGlobalX+"\n"+ "previousGlobalY : "+touch.previousGlobalY+"\n"+ "globalX : "+touch.globalX+"\n"+ "globalY : "+touch.globalY+"\n"+ "getLocation().x : "+currentPoint.x+"\n"+ "getLocation().y : "+currentPoint.y+"\n"+ "getPreviousLocation().x : "+previousPoint.x+"\n"+ "getPreviousLocation().y : "+previousPoint.y; } } private function onResizeHandler(e:starling.events.Event):void{ } private function setAlignCenter(inTarget:DisplayObject):void{ inTarget.x = stage.stageWidth >> 1; inTarget.y = stage.stageHeight >> 1; } public override function dispose():void { super.dispose(); } } }