Cannot Implicitly Convert Type in XNA

前端 未结 4 1819
夕颜
夕颜 2021-01-24 20:19

i have a bouncing ball, and i tried to make so when it bounces once, the speed gets higher.

In my ball class, i have a float speed;

and i initialize

4条回答
  •  孤街浪徒
    2021-01-24 20:47

    The speed needs to be float. If you want to keep the speed as a float, you could create your own rectangle structure. You could do something like this:

            public struct RectangleF
        {
            float w = 0;
            float h = 0;
            float x = 0;
            float y = 0;
    
            public float Height
            {
                get { return h; }
                set { h = value; }
            }
    
            //put Width, X, and Y properties here
    
            public RectangleF(float width, float height, float X, float Y)
            {
                w = width;
                h = height;
                x = X;
                y = Y;
            }
    
            public bool Intersects(Rectangle refRectangle)
            {
                Rectangle rec = new Rectangle((int)x, (int)y, (int)w, (int)h);
                if (rec.Intersects(refRectangle)) return true;
                else return false;
            }
        }
    

    The intersection checking won't be absolutely perfect, but at least your rectangle's X and Y could have 0.5 added on to them. HTH

提交回复
热议问题