1
Graphics / Re: Need Help with the relationship btwn View, RenderWindow, Aspect Ratios and Jpg
« on: January 07, 2017, 06:46:02 pm »
I figured out a solution - thanks to everyone's help.
Hapax put me on the right track when mentioning sprite.setScale().
http://www.sfml-dev.org/documentation/2.4.1/classsf_1_1Transformable.php#aaec50b46b3f41b054763304d1e727471
-- Bottom Line - You can scale all the sprites by the ratio of the THE USERS DesktopMode
I don't know why the author didn't just explain these concepts in the beginning when setting up the background. Seems like it would be useful because so many people will have different screen resolutions.
Hapax also introduced the idea of a View - which I still need to learn about - perhaps that makes all this scaling easier?
Cheers!
Hapax put me on the right track when mentioning sprite.setScale().
http://www.sfml-dev.org/documentation/2.4.1/classsf_1_1Transformable.php#aaec50b46b3f41b054763304d1e727471
-- Bottom Line - You can scale all the sprites by the ratio of the THE USERS DesktopMode
// Create a video mode object
VideoMode vm = VideoMode::getDesktopMode();
// Create and open a window for the game
RenderWindow window(vm, "XYZ GAME!!!", Style::Fullscreen);
// Create a texture to hold a graphic on the GPU
Texture textureBackground;
// Load a graphic into the texture
textureBackground.loadFromFile("graphics/background.png");
// Determine SCALE factors based on "largest item" and users screen
float SCALE_X = (float)vm.width / (float)textureBackground.getSize().x;
float SCALE_Y = (float)vm.height / (float)textureBackground.getSize().y;
// Create a sprite
Sprite spriteBackground;
// Attach the texture to the sprite
spriteBackground.setTexture(textureBackground);
// Scale based on the games "background" --
// which will presumably be the largest texture
spriteBackground.scale(SCALE_X, SCALE_Y);
... etc ...
// Create a texture to hold a graphic on the GPU
Texture textureBee;
// Load a graphic into the texture
textureBee.loadFromFile("graphics/bee.png");
// Create a sprite
Sprite spriteBee;
// Attach the texture to the sprite
spriteBee.setTexture(textureBee);
spriteBee.scale(SCALE_X, SCALE_Y);
spriteBee.setPosition(vm.width + 10, 250 * SCALE_Y);
etc ...
VideoMode vm = VideoMode::getDesktopMode();
// Create and open a window for the game
RenderWindow window(vm, "XYZ GAME!!!", Style::Fullscreen);
// Create a texture to hold a graphic on the GPU
Texture textureBackground;
// Load a graphic into the texture
textureBackground.loadFromFile("graphics/background.png");
// Determine SCALE factors based on "largest item" and users screen
float SCALE_X = (float)vm.width / (float)textureBackground.getSize().x;
float SCALE_Y = (float)vm.height / (float)textureBackground.getSize().y;
// Create a sprite
Sprite spriteBackground;
// Attach the texture to the sprite
spriteBackground.setTexture(textureBackground);
// Scale based on the games "background" --
// which will presumably be the largest texture
spriteBackground.scale(SCALE_X, SCALE_Y);
... etc ...
// Create a texture to hold a graphic on the GPU
Texture textureBee;
// Load a graphic into the texture
textureBee.loadFromFile("graphics/bee.png");
// Create a sprite
Sprite spriteBee;
// Attach the texture to the sprite
spriteBee.setTexture(textureBee);
spriteBee.scale(SCALE_X, SCALE_Y);
spriteBee.setPosition(vm.width + 10, 250 * SCALE_Y);
etc ...
I don't know why the author didn't just explain these concepts in the beginning when setting up the background. Seems like it would be useful because so many people will have different screen resolutions.
Hapax also introduced the idea of a View - which I still need to learn about - perhaps that makes all this scaling easier?
Cheers!