SFML community forums
General => General discussions => Topic started by: kolofsson on April 14, 2010, 02:44:32 pm
-
Hello. I am a hobbyist programmer. I do not have academic programming knowledge, only the things I learned on my own.
I would like to write a 2D racing game of my own, and I really like SFML. However, there are many obstacles when I try to write it in C++. I lack the flexibility of PHP, I can't really grasp the whole low-level programming stuff, like memory management, pointers. Converting numbers to strings is a real pain in the ass.
I have heard about Python, although I do not know how to program in this language.
So I would like to have some advice from more advanced programmers. For a hobbyist programmer, who does not like to fiddle much with the source code to get things done, which programming language should I use? Are the SFML bindings fully functional? Or should I stick with C++?
-
Firstly, I'm not formally educated in programming or anything similar.
I would really recommend C++ above the rest, I found parts of it ridiculous while I was learning the basics but now I am glad C++ is what I focused on.
I'm not a real fan of programming in Python, it can be a useful tool for scripting and automation, but I do view it as a tool rather than a "proper" programming language, I've never looked into the Python SFML binding.
I'm pretty sure the .NET binding is very close if not the same as the C++ one, if you are interested in a .NET language.
If you already are learning C++, I say stick with it.
Hopefully this is of some help and not just confusing :)
Converting numbers to strings pisses me off too lol :P
-
All version of the .Net bindings are up-to-date (even in SFML 2) ;)
-
Just use C++ and keep it simple. You don't have to use pointers or anything complex. If you are just making a simple game you can hardcode most things (and that can even make it faster).
The real answer is that you need to make your game simple until you become a better programmer.
IE, make a shmup--there are a bunch of people here making those too.
-
so, by .NET you mean C#? I know that C# has some nice functions included, which make eg. type conversion easier. But is this whole "binding" a simple thing to do for a noob? Are there no compatibility issues, do the binding work 100% and are they efficient to use? How about portability, if I write in C#, will I be able to compile it under Linux?
-
so, by .NET you mean C#?
I mean all .Net languages. Once an assembly is compiled, it can be used by all the .Net languages. There's a VB.Net sample in SFML.Net to demonstrate that.
But is this whole "binding" a simple thing to do for a noob?
The .Net API is almost the same as the C++ one, there are just a few things that have been modified to better suit the language.
Are there no compatibility issues
Compatibility with what? :)
do the binding work 100%
As far as I know.
and are they efficient to use?
Absolutely, the overhead of accessing the actual functions through several DLLs is in fact pretty low.
How about portability, if I write in C#, will I be able to compile it under Linux?
I've written the binding with Linux compatibility in mind. I've never tried to compile it on Linux with Mono, but it should be ok.
-
I lack the flexibility of PHP, I can't really grasp the whole low-level programming stuff, like memory management, pointers. Converting numbers to strings is a real pain in the ass.
If you know and are used to php I definitely suggest not to use C++. I suggest you to try Phyton (http://python.org/) or Ruby (http://www.ruby-lang.org), they are more like php style.
I have heard about Python, although I do not know how to program in this language.
There's plenty of information out there, just have a look at Phyton site (http://python.org/), it's documentation (http://docs.python.org/) and wiki beginners guide (http://wiki.python.org/moin/BeginnersGuide).
I think C++ is too much powerful and complex for what you want, give Phyton a try and see what you think about it ;)
I actually never used Phyton or Ruby, but I have an idea about it...
-
Asking what language to program SFML in is kinda like moving to Japan and asking what language you should speak.
Yeah, you can speak whatever you want, but depending on who you want to understand and help you is important. It depends on your background and what you want to do.
-
I mean all .Net languages. Once an assembly is compiled, it can be used by all the .Net languages. There's a VB.Net sample in SFML.Net to demonstrate that.
OK, I read a bit about the .NET. I did not know that there are more languages than C# working with the .NET framework.
So, I have found out that there is such thing as iron Python, which is Python for .NET. So the question is, which would be better: PySMFL or SFML.NET with iron Python?
-
If you are going to be coding in Python, PySFML is most certainly the better choice.
-
Converting numbers to strings is a real pain in the ass.
Why do you want to do that ? Don't you think you could do better by using strings for string stuff and numbers for number stuff ?
-
Converting numbers to strings is a real pain in the ass.
Why do you want to do that ? Don't you think you could do better by using strings for string stuff and numbers for number stuff ?
Anyway, it's not really hard at all.
int number = 5;
std::stringstream num_stream;
num_stream << number;
std::string num_string = num_stream.str();
And besides that, Boost (and C++0x, I believe) offer a lexical_cast to do pretty much the same thing in one line.
-
Why do you want to do that ? Don't you think you could do better by using strings for string stuff and numbers for number stuff ?
Wow, I almost don't know how to respond to that. I need to print some values to check how some variables behave. Anyway, I'm using the good old sprintf. For me, the c++ way of working with strings is terrible.
-
Wow, I almost don't know how to respond to that. I need to print some values to check how some variables behave. Anyway, I'm using the good old sprintf. For me, the c++ way of working with strings is terrible.
Why don't you simply use std::cout ?
int main()
{
int a = 3;
float b = 3.4;
std::string foo = "bar";
std::cout<<"int : "<<a<<std::endl;
std::cout<<"float : "<<a<<std::endl;
std::cout<<"string : "<<a<<std::endl;
}
Be careful, I'm just asking questions, not judging you. It's always interesting to see what others do.
-
std::cout is fine until you want to use something like sf::String and have numbers to print to it. I imagine this is what kolofsson is trying to do.
As pdusen said it's not that hard anyway, although it is a little bit more difficult than string += someInt; :lol:
-
For an sf::string, of course, a stringstream will help :wink:
-
then, use phyton :lol:
myAge = 23
myString = "I am " + str(myAge) + " years old"
-
Be careful, I'm just asking questions, not judging you. It's always interesting to see what others do.
Hey I didn't mean to offend you, I was only puzzled by your question.
Here is how my code looks like:
int txt = sprintf_s(string, "KPH %6.0f WHEELS %6.2f AIR %6.3f DISTANCE %6.0f POWER %6.0f", s, wheels, air, dist, pwr);
label.SetString(string);
Label is an sf::Text object. So, as you can see, displaying these numbers with all the formatting, using c++ streams would be much more complex.
Anyway, I seem to have some problem with my code. I declare the "float wheels = 0.f;" and when I run the program, SOMETIMES it is not equal to zero. it's very strange to me. the value randomly is equal to zero or something else, each time I run the program.
-
Very strange, what is the value in wheels if it's not 0 ?
Hey I didn't mean to offend you, I was only puzzled by your question.
Ok, I was afraid I offended you. I'm french and am not always completely sure of my english comprehension ;)
-
then, use phyton :lol:
myAge = 23
myString = "I am " + str(myAge) + " years old"
Use C++ 8)
template <typename T>
std::string str(const T& t)
{
std::ostringstream oss;
oss << t;
return oss.str();
}
int myAge = 23;
std::string myString = "I am " + str(myAge) + " years old";
-
I know Laurent :P For us C++ coders, it's all ok 8) But for a hobbyist programmer phyton is much simpler to learn and use.
But it's all up to you kolofsson, learning C++ is great but will probably make things harder to you. If you have the time and interest on learning and use C++ with SFML for your game, go ahead :). But if you just want to make a game without many worries, I'd say phyton. Phyton specially if you're used to php and/or javascript, because they all uses dynamic type checking, when C++ uses static typing instead.
I found this comparison article (http://www.dmh2000.com/cjpr/), actually I didn't read it all, but you may find it interesting.
-
D (http://www.digitalmars.com/d/) is also to be chosen over C++.
But if you are into php you better go with Python or some other high-level language.
-
I'm working with SFML and c# and apart from a few minor wrinkles largely to do with my misunderstanding the SFML API, its been extremely straightforward to use.