コード例 #1
0
        /// <summary>
        /// ウィンドウサイズを画像の何倍かに合わせる
        /// </summary>
        void FitWindowSize()
        {
            // 0ならサイズ調整なし
            if (m_fitScale <= 0)
            {
                return;
            }

            // 最大化されているときは調整なし
            if (m_uniwin.IsMaximized)
            {
                return;
            }

            // 画像が読み込まれていなければ何もしない
            if (currentBitmap == null)
            {
                return;
            }

            var formerSize = m_uniwin.GetWindowSize();
            var pos        = m_uniwin.GetWindowPosition();

            int width  = (int)(currentBitmap.Width * m_fitScale);
            int height = (int)(currentBitmap.Height * m_fitScale);

            // Windows向けに、ウィンドウサイズ変更後左上が固定となるよう位置調整
            pos.y = pos.y + formerSize.y - height;

            //this.ClientSize = new Size(width, height);        // Formの機能でサイズ変更する場合

            m_uniwin.SetWindowSize(new UniWinCSharp.Vector2(width, height));
            m_uniwin.SetWindowPosition(pos);
        }
コード例 #2
0
        void UpdateJumping()
        {
            // ジャンプ中でなければ何もしない
            if (!isMoving)
            {
                return;
            }

            // 終了時間以降ならばジャンプ終了とする
            double now = (stopwatch.ElapsedMilliseconds - startedMilliSeconds) / 1000.0;

            if (now >= duration)
            {
                uniwin.SetWindowPosition(initialPosition);
                EndJumping();

                if (random.Next(5) == 0)
                {
                    // 0.2 程度の確率で、ジャンプ後に反動っぽい小ジャンプ
                    height *= 0.5;
                    BeginJumping();
                }
                return;
            }

            // 頂点が t == 0 となるようにした経過時間 [s]
            double t = now - duration / 2.0;

            // 高さ[m]は y = H -1/2 * g * t^2
            double y = height - ((0.5 * standardGravity * t * t) * pixelPerMeter);

            Vector2 pos = initialPosition;

            pos.y += (float)y;
            uniwin.SetWindowPosition(pos);
        }