سؤال

i wanted to develop a game which can support all types of display sizes, so i am using following code to multiscale.

   graphics.PreferredBackBufferHeight = 768;
   graphics.PreferredBackBufferWidth = 1024;
   shootrect = new Rectangle( 900,650  , 100, 100);
   touchrect = new Rectangle(mouse.X, mouse.Y, 0, 0);

         if (mouse.LeftButton == ButtonState.Pressed && !jump && shootrect.Intersects(touchrect))
            {
                jump = true; 
            }

using this code i am trying to intersect the mouse coordinates with shootrect (which is shoot button for make player to jump) if i touch in that rect intersection is working but somewhere else in the same width and height touch is working

when i remove graphics.PreferredBackBufferHeight = 768; graphics.PreferredBackBufferWidth = 1024; those lines from code intersection is working fine but my scaling is not proper for other size of screens

هل كانت مفيدة؟

المحلول 2

actually graphics.PreferredBackBufferHeight = 768; graphics.PreferredBackBufferWidth = 1024; because of this rectangle intersection is working properly if set my screens resolution to 1024 x768 then it works well but my resoolution is 1980x1020 so its not working

نصائح أخرى

You need to scale your logic by hand (rectangles for instance) if you use those magic numbers creating them. I suggest create those relative to the screen width and height.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top