コード例 #1
0
ファイル: MCSprite.cs プロジェクト: kaoken/mc2d-stage-editor
 /// <summary>
 /// テクスチャーを指定し、分割スプライトを作成する
 /// </summary>
 /// <param name="app">アプリ</param>
 /// <param name="spriteName">スプライト名</param>
 /// <param name="texture">テクスチャー</param>
 /// <param name="divW">分割時の幅</param>
 /// <param name="divH">分割時の高さ</param>
 /// <param name="anchorType">
 /// MC_SPRITE_ANCHOR_CUSTOM の場合 アンカー位置は \a centerX および \a centerY の値によってきまる。
 /// MC_SPRITE_ANCHOR_CENTER の場合 自動的にアンカー位置になる
 /// </param>
 /// <param name="centerX">中心座標 X anchorTypeの値が \ref MC_SPRITE_ANCHOR_CUSTOM の時だけ有効</param>
 /// <param name="centerY">中心座標 Y anchorTypeの値が \ref MC_SPRITE_ANCHOR_CUSTOM の時だけ有効</param>
 /// <returns>成功した場合は、インスタンス を返す。失敗した場合は、nullを返す。</returns>
 public static MCSprite CreateSpriteDiv(
     Application app,
     string spriteName,
     MCBaseTexture texture,
     int divW, int divH,
     MC_SPRITE_ANCHOR anchorType = MC_SPRITE_ANCHOR.CUSTOM,
     float centerX = 0.0f, float centerY = 0.0f
     )
 {
     return(CreateSpriteDiv(
                app,
                spriteName,
                texture,
                0, 0,
                divW, divH,
                anchorType,
                centerX, centerY));
 }
コード例 #2
0
ファイル: MCSprite.cs プロジェクト: kaoken/mc2d-stage-editor
        public static MCSprite CreateSprite(
            Application app,
            string spriteName,
            MCBaseTexture texture,
            MCRect rc,
            MC_SPRITE_ANCHOR anchorType = MC_SPRITE_ANCHOR.CUSTOM,
            float centerX = 0.0f, float centerY = 0.0f
            )
        {
            MCSprite sp = new MCSprite();

            // 登録済みのスプライトか?
            if (app.SpriteMgr.IsSprite(spriteName))
            {
                return(sp);
            }

            sp.SetTexture(texture);

            // テクスチャーの情報を取得する
            Texture2DDescription d2TxDesc = texture.GetDesc().D2;


            sp.flags.AnchorType = (uint)anchorType;
            sp.flags.SpriteType = (uint)MC_SPRITE_DATA.SIMPLE;
            sp.Name             = spriteName;
            sp.Width            = rc.Width;
            sp.Height           = rc.Heith;

            if (anchorType == MC_SPRITE_ANCHOR.CUSTOM)
            {
                sp.Anchor = new MCVector2(centerX, centerY);
            }
            else
            {
                sp.Anchor = new MCVector2(rc.Width >> 1, rc.Heith >> 1);
            }

            // UV座標作成
            float fFW = 1.0f / (d2TxDesc.Width);
            float fFH = 1.0f / (d2TxDesc.Height);

            sp.TextureInvW = fFW;
            sp.TextureInvH = fFH;
            sp.spl         = new MCSauceSprite();
            sp.spl.StartU  = rc.left * fFW;
            sp.spl.StartV  = rc.top * fFH;
            sp.spl.EndU    = (rc.right + 1) * fFW;
            sp.spl.EndV    = (rc.bottom + 1) * fFH;
            // 基準となる球体を作る
            float r = (float)System.Math.Sqrt(sp.Width * sp.Width + sp.Height * sp.Height);

            sp.Sphere = new Sphere(
                new MCVector3(r * 0.5f, -r * 0.5f, 0.0f),
                r
                );
            // 登録
            if (app.SpriteMgr.RegisterSprite(spriteName, sp))
            {
                return(sp);
            }

            return(sp);
        }
コード例 #3
0
ファイル: MCSprite.cs プロジェクト: kaoken/mc2d-stage-editor
        public static MCSprite CreateSpriteDiv(
            Application app,
            string spriteName,
            MCBaseTexture texture,
            int baseW, int baseH,
            int divW, int divH,
            MC_SPRITE_ANCHOR anchorType = MC_SPRITE_ANCHOR.CUSTOM,
            float centerX = 0.0f, float centerY = 0.0f
            )
        {
            MCSprite sp = new MCSprite();

            // 登録済みのスプライトか?
            if (app.SpriteMgr.IsSprite(spriteName))
            {
                return(sp);
            }


            sp.Texture00 = texture;

            // テクスチャーの情報を取得する
            Texture2DDescription ImgInfo = sp.Texture00.GetDesc().D2;

            sp.Name   = spriteName;
            sp.Width  = ImgInfo.Width;
            sp.Height = ImgInfo.Height;

            if (anchorType == MC_SPRITE_ANCHOR.CUSTOM)
            {
                var a = sp.Anchor;
                a.X = -centerX;
                a.Y = centerY;
            }
            else
            {
                var a = sp.Anchor;
                a.X = -(float)(divW >> 1);
                a.Y = (float)(divH >> 1);
            }


            //
            sp.flags.AnchorType = (uint)anchorType;
            sp.flags.SpriteType = (uint)MC_SPRITE_DATA.DIVISION;
            sp.div        = new MCSauceConsecutiveSprite();
            sp.div.DivW_U = (float)divW / ImgInfo.Width;
            sp.div.DivH_V = (float)divH / ImgInfo.Height;
            if (baseW == 0 || baseH == 0)
            {
                // 行と列の数
                sp.div.Col = ImgInfo.Width / divW;
                sp.div.Row = ImgInfo.Height / divH;
            }
            else
            {
                // 行と列の数
                sp.div.Col = baseW / divW;
                sp.div.Row = baseH / divH;
            }
            // 球体を作る
            float fWW = (float)(divW) * 0.5f;
            float fHH = (float)(divH) * 0.5f;
            float r   = (float)System.Math.Sqrt(fWW + fHH);
            var   s   = sp.Sphere;

            s.r       = r;
            s.c       = new MCVector3(r * 0.5f, -r * 0.5f, 0.0f);
            sp.Sphere = s;

            // 登録
            if (app.SpriteMgr.RegisterSprite(spriteName, sp))
            {
                return(sp);
            }

            return(sp);
        }