示例#1
0
        /// <summary>
        /// 初期化
        /// </summary>
        /// <param name="p">画像のファイルパス</param>
        /// <param name = "retu">列の分割数</param>
        /// <param name = "gyo">行の分割数</param>
        /// <param name="x">X位置</param>
        /// <param name="y">Y位置</param>
        /// <param name="margin">画像の当たり判定の余白(当たり判定を調整するとき)(デフォルトは0,0,0,0)</param>
        /// <param name = "AniSpeed">アニメーションの速度</param>
        /// <param name="IsLoop">アニメーションをループするならtrue</param>
        void Init(string p, int retu, int gyo, int x, int y, Rect margin, int AniSpeed, bool IsLoop = true)
        {
            this.filePath = p;
            int TempHandle = DX.LoadGraph(this.filePath);   //一時的に画像を1枚として読み込み

            //読み込みエラー
            if (TempHandle == -1)
            {
                MessageBox.Show(this.filePath + LoadErrHonbun, LoadErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Game.GetInstance().End();   //ゲーム終了
            }

            //一時的に幅と高さを取得
            int TempWidth  = -1;
            int TempHeight = -1;

            //画像のサイズを取得
            DX.GetGraphSize(TempHandle, out TempWidth, out TempHeight);
            DX.DeleteGraph(TempHandle); //画像は廃棄

            //分割最大数を計算
            this.DivMax = retu * gyo;

            //配列をリサイズ
            Array.Resize(ref this.handle, this.DivMax);

            //幅と高さを設定
            //Info作成
            this.info        = new ImgInfo();
            this.info.x      = x;
            this.info.y      = y;
            this.info.width  = TempWidth / retu;
            this.info.height = TempHeight / gyo;

            //画像を分割して読み込み
            DX.LoadDivGraph(this.filePath, this.DivMax, retu, gyo, this.info.width, this.info.height, this.handle);

            //読み込みエラー
            if (this.handle[0] == -1)
            {
                MessageBox.Show(this.filePath + LoadErrHonbunBunkatsu, LoadErrTitleBunkatsu, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Game.GetInstance().End();   //ゲーム終了
            }

            //当たり判定の円の半径は、幅と高さのどちらか大きい方
            if (this.info.width > this.info.height)
            {
                this.info.circle.radius = this.info.width;
            }
            else if (this.info.width <= this.info.height)
            {
                this.info.circle.radius = this.info.height;
            }

            //描画する
            this.IsDraw = true;

            //当たり判定の余白を設定
            this.info.margin = new Rect(0, 0, 0, 0);

            //アニメーションのスピード
            this.AnimCnt    = 0;
            this.AnimCntMAX = AniSpeed;

            //アニメーションのループをするか
            this.IsAnimLoop = IsLoop;

            //画像の当たり判定の位置を更新する
            this.info.CollUpdateRect();
        }