- #1
yungman
- 5,755
- 293
Hi
I am just starting to studying games with C++ by Horton for a few days. It uses SFML for graphics, sound and fonts. I am puzzled with the screen map location. In the program below, you can see the resolution is 1920 X 1080 full screen. But there are something funny when I create a sprite and put it in specified location. I actually took a picture with camera and screen capture and write the coordinates where I put the tree (810, 0)and the bee(400,510). But if I count on the resolution of 1920 X 1080, as I labeled top left is (0,0), bottom right is (1920, 1080), it way off!
This is the program
you can see I see the coordinates of the sprite of tree at (810,0) in line 18. and sprite of bee is (400, 510) in line 24. Why the sprites display so off on the screen? Got to have a very simple explanation why I am off that I missed.
Thanks
I am just starting to studying games with C++ by Horton for a few days. It uses SFML for graphics, sound and fonts. I am puzzled with the screen map location. In the program below, you can see the resolution is 1920 X 1080 full screen. But there are something funny when I create a sprite and put it in specified location. I actually took a picture with camera and screen capture and write the coordinates where I put the tree (810, 0)and the bee(400,510). But if I count on the resolution of 1920 X 1080, as I labeled top left is (0,0), bottom right is (1920, 1080), it way off!
This is the program
C++:
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace sf;
using namespace std;
int main()
{ VideoMode vm(1920, 1080);//set screen resolution 1920 X 1080
RenderWindow window(vm, "Timber!", Style::Fullscreen);//create window object
Texture textureBackground;//Create texture to hold graphic on GPU
textureBackground.loadFromFile("graphics/background.png");//load graphic into texture
Sprite spriteBackground;//create a sprite
spriteBackground.setTexture(textureBackground);//attach texture to sprite
spriteBackground.setPosition(0, 0);//set sprite to cover the screen
Texture textureTree;
textureTree.loadFromFile("graphics/tree.png");
Sprite spriteTree;
spriteTree.setTexture(textureTree);
spriteTree.setPosition(810, 0);//810 should put a little left from center
Texture textureBee;
textureBee.loadFromFile("graphics/bee.png");
Sprite spriteBee;
spriteBee.setTexture(textureBee);
spriteBee.setPosition(400, 510);
bool beeActive = false;
float beeSpeed = 0.0f;
Texture textureCloud;
textureCloud.loadFromFile("graphics/cloud.png");
Sprite spriteCloud1;
Sprite spriteCloud2;
Sprite spriteCloud3;
spriteCloud1.setTexture(textureCloud);
spriteCloud2.setTexture(textureCloud);
spriteCloud3.setTexture(textureCloud);
spriteCloud1.setPosition(0, 0);
spriteCloud2.setPosition(0, 250);
spriteCloud3.setPosition(0, 500);
bool cloud1Active = false;
bool cloud2Active = false;
bool cloud3Active = false;
float cloud1Speed = 0.0f;
float cloud2Speed = 0.0f;
float cloud3Speed = 0.0f;
window.clear();
window.draw(spriteBackground);
window.draw(spriteTree);
window.draw(spriteBee);
window.draw(spriteCloud1);
window.draw(spriteCloud2);
window.draw(spriteCloud3);
window.display();//Update screen with new background
while (window.isOpen())//Stay looping until ESC
{ if (Keyboard::isKeyPressed(Keyboard::Escape))
{ window.close(); }//Hit ESC key to exit
}
window.clear();
window.display();
return 0;
}
you can see I see the coordinates of the sprite of tree at (810,0) in line 18. and sprite of bee is (400, 510) in line 24. Why the sprites display so off on the screen? Got to have a very simple explanation why I am off that I missed.
Thanks