はどのようにスプライトに登録ポイントを設定するか、ActionScriptを使用してシェイプ(私はこれはFlashを使用して簡単ですけど、私は、ActionScriptで純粋にそれを行う必要があります)あなたにAS3:DisplayObjectの登録ポイントをactionscriptで設定しますか?
答えて
がインデックスを意味するのでしょうか?
コメントをフォローすると、次のように簡単に実装できます。 これは、お子様ごとに異なるアラインメントを設定することはできないので、あなたが望むものと正確には異なります。 私はちょうどあなたがそれを必要とする理由によっては...それはあなたのアイデアを与えるために、より「労働擬似コード」のようなものだ、それはあまりにも複雑にするために
package
{
import flash.display.DisplayObject;
import flash.display.Sprite;
public class SpriteWithRegistration extends Sprite
{
private var _regV:String = "T";
private var _regH:String = "L";
private var _width:Number = 0;
private var _height:Number = 0;
public function SpriteWithRegistration(width:Number, height:Number, registrationPoint:String = "TL")
{
this.width = height;
this.height = width;
this.registrationPoint = registrationPoint;
}
public function set registrationPoint(p:String):void
{
if(p.length != 2) return;
var regV:String = p.toUpperCase().substr(0, 1);
var regH:String = p.toUpperCase().substr(1, 1);
_regV = (regV == "T" || regV == "C" || regV == "B") ? regV : _regV;
_regH = (regH == "L" || regH == "C" || regH == "R") ? regH : _regH;
alignChildren();
}
override public function addChild(child:DisplayObject):DisplayObject
{
alignChild(child);
super.addChild(child);
return child;
}
override public function set width(value:Number):void
{
_width = value;
alignChildren();
}
override public function get width():Number
{
return _width;
}
override public function set height(value:Number):void
{
_height = value;
alignChildren();
}
override public function get height():Number
{
return _height;
}
private function alignChildren():void
{
for(var index:int = 0;index < numChildren; index++)
alignChild(getChildAt(index));
}
private function alignChild(disp:*):void
{
switch(_regH)
{
case "L": disp.x = 0; break;
case "C": disp.x = _width*.5 - disp.width * .5; break;
case "R": disp.x = _width - disp.width; break;
}
switch(_regV)
{
case "T": disp.y = 0; break;
case "C": disp.y = _height*.5 - disp.height * .5; break;
case "B": disp.y = _height - disp.height; break;
}
}
}
}
Flash Player APIはこれを公開していません。これは、SWFがSWFを作成するときに、Flashが実際に登録ポイントをシェイプデータに焼き付けてしまうからです。したがって、実際の登録ポイントはありません(Flash Playerでシェイプデータを編集できる場合はシェイプデータを移動します)。
私はスプライト/シェイプを別のDisplayObjectに親子処理するだけで、これを常に解決します。私はspriteAを持っているし、(15、35)への登録ポイントを設定したいのであれば、私はこれを行うだろう:
var spriteB:Sprite = new Sprite();
spriteB.addChild(spriteA);
spriteA.x = 15;
spriteA.y = 35;
そして、その後からどこでもspriteBを参照してくださいに私は、以前spriteAに言及していました。
これは間違いなく最も簡単で簡単な方法です。しかし、最もエレガントではありません。あなたが余分なコンテナを持っていることのオーバーヘッドが問題ではないならば、ブー。 –
これは可能です。ここにはthis siteにあるこの優れた実装があります。
public function setRegistrationPoint(s:Sprite, regx:Number, regy:Number, showRegistration:Boolean)
{
//translate movieclip
s.transform.matrix = new Matrix(1, 0, 0, 1, -regx, -regy);
//registration point.
if (showRegistration)
{
var mark:Sprite = new Sprite();
mark.graphics.lineStyle(1, 0x000000);
mark.graphics.moveTo(-5, -5);
mark.graphics.lineTo(5, 5);
mark.graphics.moveTo(-5, 5);
mark.graphics.lineTo(5, -5);
s.parent.addChild(mark);
}
}
これをもっと詳しく説明できますか? – Vishnu
リンクが切れています。おそらくそれを説明する方が良いことでした。 –
私はこれが誰かを助けることを望んでいます。 Starlingフレームワークには、 "alignPivot()"という素晴らしいメソッドがあります。私は彼らのコンセプトをとり、それをFlash DisplayListに適用しました。基本的にスプライトに左、右、中央、上、下に登録を変更するよう伝えます。このコードは、スプライトをコンテナスプライトに配置し、適切に配置します。内部に元のスプライトが含まれているコンテナスプライトを返します。
「位置」と呼ばれる別のコードに格納されたコード。
public static function alignPivot(s:DisplayObject, horizontalAlign: String = "center", verticalAlign: String = "center", showRegistration: Boolean = false, _color: uint = 0x000000): Sprite {
//create a container sprite to house the sprite you'd like to move
var _container: Sprite = new Sprite();
//add your sprite to the continer sprite (the container sprite is what will be returned)
_container.addChild(s);
//using getBounds(), find the x,y,width,and height of your sprite within the continer.
var bounds:Rectangle = _container.getBounds(s);
//create variables for x and y cooridnates
var xVal: Number;
var yVal: Number;
//I have a separate class called Align which contains public static constants for positiong.
//Check the values passed above and get the correct x value;
if (horizontalAlign == Align.LEFT) xVal = -bounds.x;
else if (horizontalAlign == Align.CENTER) xVal = -bounds.x - bounds.width * .5;
else if (horizontalAlign == Align.RIGHT) xVal = -bounds.x - bounds.width;
else throw new ArgumentError("Invalid horizontal alignment: " + horizontalAlign);
//Check the values passed above and get the correct y value;
if (verticalAlign == Align.TOP) yVal = -bounds.y;
else if (verticalAlign == Align.CENTER) yVal = -bounds.y - bounds.height * .5;
else if (verticalAlign == Align.BOTTOM) yVal = -bounds.y - bounds.height;
else throw new ArgumentError("Invalid vertical alignment: " + verticalAlign);
//apply the new x and y cooridnates to your sprite (the one moving within the container we created above)
s.x = xVal;
s.y = yVal;
//optional - this will create a small X at the 0,0 position of the container.
//This is helpful if you want to see where your registration points are
if (showRegistration) {
var mark: Sprite = new Sprite();
mark.graphics.lineStyle(1, _color);
mark.graphics.moveTo(-5, -5);
mark.graphics.lineTo(5, 5);
mark.graphics.moveTo(-5, 5);
mark.graphics.lineTo(5, -5);
_container.addChild(mark);
}
//return your contianer sprite
//This will replace the sprite that you passed in the first parameter.
//That sprite is inside the container, so you won't notice
return _container;
}
実装:あなたがそれらを自分で記述する必要はありませんので、定数の
//Create your sprite
var _holder: Sprite = new Sprite();
//Create a shape to put in your sprite
var my_shape: Shape = new Shape();
my_shape.graphics.beginFill(0x000000);
my_shape.graphics.drawRect(0, 0, 200, 100);
my_shape.graphics.endFill();
//Add the shape to your sprite
_holder.addChild(my_shape);
//Align the holder (must be done AFTER all children have been added)
//This will put the registration point at the top-center of the sprite.
//_holder is replaced by a sprite (container) that contains _holder.
//The _holder inside the container is positioned appropriately.
_holder = Position.alignPivot(_holder,Align.CENTER, Align.TOP);
//Add the new sprite to your stage.
this.addChild(_holder);
一覧:
public static const CENTER:String = "center";
public static const LEFT:String = "left";
public static const RIGHT:String = "right";
public static const TOP:String = "top";
public static const BOTTOM:String = "bottom";
- 1. ActionscriptのDisplayObjectのイベントリスナーをクリアします
- 2. フレックス:表示オブジェクトの登録ポイントを設定する
- 3. フラッシュビルダーモバイルAS3プロジェクト:センターのDisplayObject
- 4. Facebook登録/ログインプラグインのスタイルを設定できますか?
- 5. AS3 DisplayObjectの特定のプロパティへのアクセスのみを許可します
- 6. ポイント雲の色のブレンドは、登録
- 7. symfony MicroKernelのカスタム設定名前空間を登録します
- 8. AS3:DisplayObjectがステージから削除された時期を判断しますか?
- 9. 春のセキュリティ設定ロールオン登録
- 10. OneDrive authorization redirectURI(アプリケーション登録ポータルの設定)
- 11. ムービークリップの高さを登録ポイントから変更する
- 12. クリックイベントをカスタム設定で登録できません
- 13. SQLトリガーを設定し、それにasp.netを登録しますか?
- 14. AS3のSprite.graphicsからのポイント
- 15. 設定APNSトークンなしのGCM登録を許可する
- 16. WordPress - 登録プロセスでニックネームから表示名を設定
- 17. FlashソースコードをプルダウンAS3のactionscript
- 18. Android:HandlerでSensorEventListenerを登録しますか?
- 19. Structure Mapでのオーバーライド登録を設定する方法4.4
- 20. CastleWindsorを使用してIServiceBehaviorの異なる設定を登録します。
- 21. スコープ内から陥没注入スコープサービスを設定/登録する
- 22. AS3のvoidのポイント
- 23. registerFactoryLocationを使用してmozillaで環境設定を登録できません
- 24. Deviseの登録ビューをモーダルとして設定
- 25. awsでユーザ登録を設定するPHP SDK
- 26. DisplayObjectの特定の領域にフィルタを適用しますか?
- 27. quickbloxを使用しているユーザーを登録/登録しますか?
- 28. 電子メールのSMTPの設定を登録するとコード
- 29. 特定の信号用のシグナルハンドラの登録は、別の登録済み信号を上書きしますか?
- 30. マニフェストにアプリケーションクラスを登録しますか?
なし、登録ポイント。デフォルトでは左上です。 – Ronn
ところで、スプライトとシェイプのデフォルト実装はありません。どのようにあなたのオブジェクトのサイズに完全に依存するので意味があります。 UIフレームワークを使用するか、独自のUIフレームワークを構築するのが最善です。アイデアは、ホルダーのサイズと子供のアライメントを指定することです。 –