1

I've been trying to get my game to scale every sprite based on screen size and I found this site.

However it seems that they used XNA 3.1 so in spriteBatch.Begin they used some code that does not work in XNA 4.0 like SpriteBlendMode.AlphaBlend. Now I found a website that converts 3.1 code to 4.0 and I've done that. But it says

"No overload for method spriteBatch.Begin() takes 3 arguments"

in the draw method.

At the moment it looks like this:

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SpriteScale);

What more does it want? Can I just put null,null after SpriteScale? Or is there an eaiser way to Scale the game based on your screen size? Please help! :)

pinckerman
  • 4,115
  • 6
  • 33
  • 42
user2429201
  • 21
  • 1
  • 4
  • There is a version for XNA 4.0. [Scaling Sprites Based On Screen Size](http://msdn.microsoft.com/en-us/library/bb447674\(v=xnagamestudio.40\).aspx). I suggest using MonoGame with WindowsGL project. – Dustin Kingen May 28 '13 at 15:50
  • Omg didn't see that they had 4.0 aswell xD Thanks Romoku. Now this seems to work alot better, but when i press A or the B button the game doesn't scale down so you can see the whole game in 800x600, instead you can just see small parts of the game. I don't know if that was intendent or if i have missed something. Also does this scale down objects from other classes that uses their own scale and draw method? – user2429201 May 28 '13 at 16:04
  • 1
    Check down in the comments of the MSDN document. It looks like the `spriteBatch.Begin();` should be `spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, SpriteScale);`. See if this fixes your problem. – Dustin Kingen May 28 '13 at 16:06
  • To answer the second part of your question, I don't think this will scale custom Scale/Draw. You'll need to pass the global scale to each object that needs it. – Dustin Kingen May 28 '13 at 16:08
  • I've done that and it still doesn't work. Have you tried the code yourself? – user2429201 May 28 '13 at 17:42
  • Yeah it's probably missing the code where it updates the Scaling Matrix inside the `Update` method. – Dustin Kingen May 28 '13 at 19:16
  • Did they mention that on the site that you linked? because the only code they have in update is the code that changes your resolution. Or did i miss something? Do you know what code its missing? – user2429201 May 28 '13 at 20:14
  • No they don't have the code in the update loop. I'll try to work on the problem tomorrow. – Dustin Kingen May 28 '13 at 23:42
  • hmm.. Im not sure if i have done this right but i put 'float screenscale = (float)graphics.GraphicsDevice.Viewport.Width / 800f;' and SpriteScale = Matrix.CreateScale(screenscale, screenscale, 1); in update instead and now it seems to work. It scales down all my objects however i don't think that the background scales aswell because it doesn't cover the entire screen so there are black emptiness around the background. One thing i notic is that it also scales objects that uses their own draw/scale method so it does work, does the code scale height aswell or only witdh? – user2429201 May 29 '13 at 13:03
  • Yeah it doesn't preserve the aspect ratio since `Matrix.CreateScale(screenscale, screenscale, 1);` uses the width twice. You can solve the black emptiness by introducing a camera and clamping its view to the edges of the view. – Dustin Kingen May 29 '13 at 13:37
  • Changing the BackBuffer is only going to change how much the user can view from within the window. It doesn't actually scale the ViewPort. – Dustin Kingen May 29 '13 at 13:51
  • Yeah that explain everything :D, is there any other way to change aspect ratio of the game without using a camera? Or is using a camera the best option? :) – user2429201 May 29 '13 at 15:14
  • The camera is just an abstraction to decouple the Drawing logic from the ViewPort. There is a good implementation from another question: [XNA 2D Camera Engine That Follows Sprite](http://stackoverflow.com/questions/712296/xna-2d-camera-engine-that-follows-sprite) – Dustin Kingen May 29 '13 at 15:18
  • Thanks i will look into it, well i guess that solves my question Thank you so much for all your help! :D – user2429201 May 29 '13 at 15:35

1 Answers1

0

Changing the BackBuffer will only change the amount of area the user can view.

Look into using a camera to separate your ViewPort from your Drawing which will allow the sprites to scale with the screen size.

See: XNA 2D Camera Engine That Follows Sprite

Community
  • 1
  • 1
Dustin Kingen
  • 20,677
  • 7
  • 52
  • 92