package
{
import flash.geom.Point;
import starling.display.Quad;
import starling.display.Sprite;
import starling.events.Event;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
public class Game extends Sprite
{
public function Game()
{
super();
addEventListener( Event.ADDED_TO_STAGE, onAdded );
}
private function onAdded( e:Event ):void
{
removeEventListener( Event.ADDED_TO_STAGE, onAdded );
// 绘制一个矩形区域
var q:Quad = new Quad( 50, 50, 0x000000 );
q.x = stage.stageWidth << 2 - q.width << 2; // 对于是2的倍数最好采用位运算更加高效
q.y = stage.stageHeight << 2 - q.height << 2;
q.addEventListener( TouchEvent.TOUCH, touchHandler );
}
private function touchHandler( e:TouchEvent ):void
{
var touch:Touch = e.getTouch( stage );
var pt:Point = touch.getLocation( stage );
var target:Quad = e.target as Quad;
if ( touch.phase == TouchPhase.MOVED )
{
target.x = pt.x - ( target.width << 2 );
target.y = pt.y - ( target.height << 2 );
}
}
}
{
import flash.geom.Point;
import starling.display.Quad;
import starling.display.Sprite;
import starling.events.Event;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
public class Game extends Sprite
{
public function Game()
{
super();
addEventListener( Event.ADDED_TO_STAGE, onAdded );
}
private function onAdded( e:Event ):void
{
removeEventListener( Event.ADDED_TO_STAGE, onAdded );
// 绘制一个矩形区域
var q:Quad = new Quad( 50, 50, 0x000000 );
q.x = stage.stageWidth << 2 - q.width << 2; // 对于是2的倍数最好采用位运算更加高效
q.y = stage.stageHeight << 2 - q.height << 2;
q.addEventListener( TouchEvent.TOUCH, touchHandler );
}
private function touchHandler( e:TouchEvent ):void
{
var touch:Touch = e.getTouch( stage );
var pt:Point = touch.getLocation( stage );
var target:Quad = e.target as Quad;
if ( touch.phase == TouchPhase.MOVED )
{
target.x = pt.x - ( target.width << 2 );
target.y = pt.y - ( target.height << 2 );
}
}
}
}
最后你还得在bin-debug文件夹下更改【项目名称.html】,在 params.allowfullscreen = "true";后面加上params.wmode = "direct";就可以允许了