Starling のスクロール領域の問題を 2 日連続で解決できません。これが私のコードです:
protected function onTouch(event:TouchEvent):void
{
var touches:Vector.<Touch> = event.getTouches(this, TouchPhase.MOVED);
if (touches.length == 1)
{
// one finger touching -> move
var delta:Point = touches[0].getMovement(parent);
x += delta.x;
y += delta.y;
}
else if (touches.length == 2)
{
// two fingers touching -> rotate and scale
var touchA:Touch = touches[0];
var touchB:Touch = touches[1];
var currentPosA:Point = touchA.getLocation(parent);
var previousPosA:Point = touchA.getPreviousLocation(parent);
var currentPosB:Point = touchB.getLocation(parent);
var previousPosB:Point = touchB.getPreviousLocation(parent);
var currentVector:Point = currentPosA.subtract(currentPosB);
var previousVector:Point = previousPosA.subtract(previousPosB);
if (_enableRotation)
{
var currentAngle:Number = Math.atan2(currentVector.y, currentVector.x);
var previousAngle:Number = Math.atan2(previousVector.y, previousVector.x);
var deltaAngle:Number = currentAngle - previousAngle;
}
// update pivot point based on previous center
var previousLocalA:Point = touchA.getPreviousLocation(this);
var previousLocalB:Point = touchB.getPreviousLocation(this);
pivotX = (previousLocalA.x + previousLocalB.x) * 0.5;
pivotY = (previousLocalA.y + previousLocalB.y) * 0.5;
// update location based on the current center
x = (currentPosA.x + currentPosB.x) * 0.5;
y = (currentPosA.y + currentPosB.y) * 0.5;
if (_enableRotation)
{
// rotate
rotation += deltaAngle;
}
// scale
var sizeDiff:Number = currentVector.length / previousVector.length;
var diffSize:Number = scaleX * sizeDiff;
if(( diffSize>= _minScale) && (diffSize <= _maxScale))
{
scaleX *= sizeDiff;
scaleY *= sizeDiff;
}
}
var touch:Touch = event.getTouch(this, TouchPhase.ENDED);
if (touch)
{
//here is my problem!
}
}
最後に、子オブジェクト (画像) がどこにあるかを確認したい場合、このオブジェクトが画面の外にある場合は、スクロール領域 (スプライト) を画面の中央に移動します。しかし、どうすればこれができるのかわかりません。