1
General / Lethn's Programming Questions Thread
« on: June 20, 2013, 08:32:40 pm »
I thought instead of spamming the forum with new topics guys I'd just spam the one topic then that way everyone else can keep posting as normal. I didn't think I'd get this deep into programming but as I go through tutorials I've got more and more things to investigate, some stuff I just get on my own but other stuff like what I'm working on currently I need help with.
I'm looking at how to combine C++ and SFML so I can get a basic game running, so the obvious stuff like health or gold go up or down depending on what happens to the game. I understand the C++ code and I understand the SFML code for both of these functions but I'm of course running into problems combining the two because I'm not sure where to put it. I'm also getting these situations where the C++ code isn't liking my SFML objects very much and I suspect that's going to be because the two will be in conflict with each other somewhere so I need to experiment and find out what works.
#include <Iostream>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
int main ()
{
sf::RenderWindow window(sf::VideoMode( 800, 600 ), "C++ Programming Test");
sf::Font arial;
if ( !arial.loadFromFile ( "arial.ttf" ) )
{ }
sf::Text lineone;
lineone.setFont( arial );
lineone.setCharacterSize ( 12 );
lineone.setPosition ( 340, 280 );
while (window.isOpen())
{
{
using namespace std;
int numberinput;
lineone.draw ( "Type in a number: " )
cin>> numberinput;
cin.ignore();
if ( numberinput < 10 ){
lineone.draw ( "Death, you entered too low a number" );
}
cin.get();
}
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw ( lineone );
window.display();
}
return 0;
}
I'm starting off with the basic C++ functions and combining them with the SFML text, I'm aware you could use SFML TextEntered but I want to be able to use all of my C++ functions rather than just a couple and getting stumped when I try to do something different.
I'm looking at how to combine C++ and SFML so I can get a basic game running, so the obvious stuff like health or gold go up or down depending on what happens to the game. I understand the C++ code and I understand the SFML code for both of these functions but I'm of course running into problems combining the two because I'm not sure where to put it. I'm also getting these situations where the C++ code isn't liking my SFML objects very much and I suspect that's going to be because the two will be in conflict with each other somewhere so I need to experiment and find out what works.
#include <Iostream>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
int main ()
{
sf::RenderWindow window(sf::VideoMode( 800, 600 ), "C++ Programming Test");
sf::Font arial;
if ( !arial.loadFromFile ( "arial.ttf" ) )
{ }
sf::Text lineone;
lineone.setFont( arial );
lineone.setCharacterSize ( 12 );
lineone.setPosition ( 340, 280 );
while (window.isOpen())
{
{
using namespace std;
int numberinput;
lineone.draw ( "Type in a number: " )
cin>> numberinput;
cin.ignore();
if ( numberinput < 10 ){
lineone.draw ( "Death, you entered too low a number" );
}
cin.get();
}
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw ( lineone );
window.display();
}
return 0;
}
I'm starting off with the basic C++ functions and combining them with the SFML text, I'm aware you could use SFML TextEntered but I want to be able to use all of my C++ functions rather than just a couple and getting stumped when I try to do something different.