XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

-- scaling images for screen resolution

Last post 11/1/2007 11:27 AM by Ronzan. 5 replies.
  • 5/29/2007 3:10 PM

    -- scaling images for screen resolution

     Hey,

     Any one have a technique to scale images depending on screen resolutions? I've notice, I am creating screens in 800x600 and 1024x768, which well.. Is there away to speed this up so making a 1920x1600 can be scale between all resolutions?

     Second questions, is there a param for setting images to be center, depending on the resolutions. I guess, I could write the code to determine the center of the resolution, which might be the best way to figure that out.!

     

     

  • 5/29/2007 7:53 PM In reply to

    Re: -- scaling images for screen resolution

    You can set the target rectangle to whatever size you want.  For example:

    Rectangle rect = new Rectangle(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);
    spriteBatch.Draw(mySpriteTexture, rect, null, Color.White, 0.0f, new Vector2(0, 0), SpriteEffects.None, 1.0f);

    The code above will stretch or shrink the sprite to fit the target viewport regardless of the size of the sprite.

    As for centering, the usual way is to calculate the center position with something like:

    (graphics.GraphicsDevice.Viewport.Width - mytexture.Width)/2

    and

    (graphics.GraphicsDevice.Viewport.Height- mytexture.Height)/2
    --
    Gamer Outfit - XNA News and Reviews
    Maker of Exisled - Helicopter 2d/3d Shooter available now!
  • 5/29/2007 10:28 PM In reply to

    Re: -- scaling images for screen resolution

    I set an orhtonormal projection and render in that space. For example, you can make 0 be the left, and 1 be the right, and same thing for bottom and top.

    Or you can take advantage of the fact that the output projection is -1 through 1 across and something less than that (based on aspect ratio) from down to up, and just emit vertices that you don't transform at all. On XNA, your shader would look like:

    VSOut Transform(pos : POSITION, tex : TEXCOORD0) {
      VSOut out;
      out.pos = pos;
      out.tex = tex;
      return out;
    }

    technique t {
      pass p {
        VertexShader = compile vs_1_1 Transform();
      }
    }




    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 11/1/2007 9:39 AM In reply to

    Re: -- scaling images for screen resolution

    U can make your own sprite Class, where u can define the positions in percent 0f-1f

    so 0.5f is always the center of the screen.

     

    I need help with question 1, too

  • 11/1/2007 10:15 AM In reply to

    Re: -- scaling images for screen resolution

    Check out the Marblets sample for one way to do it:
    In this I created a scalable sprite class which takes non screen based coordinates converts them to the current screen size and used them to feed a regular spritebatch

    and then....

    Check out the SpaceWar sample for another way to do it:
    In this they draw everything to a fixed size render target no matter what the screen res. Then they draw the render target in a single shot scaling and positioning it to give letterbox bars where necessary.

    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 11/1/2007 11:27 AM In reply to

    Re: -- scaling images for screen resolution

    If you are talking about 2D graphics using the SpriteBatch.Begin() overloads might help.
    There is one overload taking a transformation matrix, I use this method and it gives ok results.

    SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None, mTransformMatric);

    See XNA MSDN Docs:
    ms-help://MS.VSExpressCC.v80/MS.VSIPCC.v80/MS.XNAFX.1033/XNA/2DGraphicsHowTo_Scale_Sprites_Matrix.htm

    /Ronzan

Page 1 of 1 (6 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG