SFML community forums

General => SFML projects => Topic started by: AlexxanderX on January 05, 2013, 01:50:21 pm

Title: AlexxanderX's Tutorials
Post by: AlexxanderX on January 05, 2013, 01:50:21 pm
Hello! I decided to make an blog and to post tutorials about SFML and informations about my projects. Here is my blog: http://alexanderx.net/ (http://alexanderx.net/)
I will try to upload at least 1 tutorial per week.

Here is a list of actual tutorials on my blog:
Title: Re: AlexxanderX Tutorials
Post by: Nexus on January 05, 2013, 01:58:56 pm
You should fix your link ;)

Also, you use interchangeably int and unsigned int for index access. You should use unsigned int, or directly std::size_t.

Then, top-level const qualifiers are useless:
void menu::setString(int item_number, const sf::String item_string)
You still perform a copy, and the caller isn't interested whether this copy is constant or not. What you probably want is a reference to a const sf::String:
void menu::setString(int item_number, const sf::String& item_string)

You should also make your code const-correct in other places, and get rid of unnecessary parameters.
void setFont(sf::Font &font);
// ->
void setFont(const sf::Font& font);
int menu::getCurrentItem()
// ->
std::size_t menu::getCurrentItem() const
void menu::update(sf::RenderWindow &window, sf::Event &event)
// ->
void menu::update(const sf::Event& event)

Apart from that, the code looks good, I like the fact that you use STL containers and no new/delete :)
Title: Re: AlexxanderX Tutorials
Post by: AlexxanderX on January 05, 2013, 02:41:18 pm
Thanks. I modified!  ;D
Title: Re: AlexxanderX Tutorials
Post by: masskiller on January 06, 2013, 04:31:30 am
You can just use unsigned without specifying the type as int is the default unsigned type, as a personal taste I find it better due to laziness and less typing.
Title: Re: AlexxanderX Tutorials
Post by: kaB00M on January 06, 2013, 07:10:04 pm
In my menus a use a single instance of sf::Text instead of a vector.
I move this text around and set the string (content) before drawing in my draw loop? Is my method slow?
Title: Re: AlexxanderX Tutorials
Post by: Nexus on January 06, 2013, 07:49:53 pm
I move this text around and set the string (content) before drawing in my draw loop? Is my method slow?
It should not be an issue. The worst thing that can happen is that sf::Font has to load new glyphs, but you probably won't notice the difference.

Depending on the graphical effects you want to have in your menu, a vector may be more flexible.
Title: Re: AlexxanderX Tutorials
Post by: AlexxanderX on January 09, 2013, 04:53:28 pm
About what to wrote in the next tutorial?
Title: Re: AlexxanderX Tutorials
Post by: Foaly on January 09, 2013, 06:09:31 pm
Please avoid posts like that. We are trying to be a helpful and friendly community here. Your post is not helpful in any way. Not everybody is a native English speaker or has the luck of having a good English teacher. Please respect that :)
By the way: The sentence might be unusual, but grammatically correct, except for one wrong verb form ("About what to write the next tutorial?")

topic: I really like the simplicity of your menu class! looks good!
Title: Re: AlexxanderX Tutorials
Post by: AlexxanderX on April 11, 2014, 10:05:17 pm
And I'm back( huh, after 1 year)! After I quit my free blog and lost the tutorial I made, the time has come to continue my blog. This time with a purchased domain and 2 tutorials, and my english improved. For more informations visit the first post.
Title: Re: AlexxanderX's Tutorials
Post by: zsbzsb on April 11, 2014, 10:26:25 pm
Well, welcome back!  :D
Title: Re: AlexxanderX's Tutorials
Post by: AlexxanderX on April 15, 2014, 04:02:11 pm
I released I new tutorial -> here (http://alexanderx.net/how-apply-collision/) :D
Title: Re: AlexxanderX's Tutorials
Post by: AlexxanderX on April 22, 2014, 11:45:49 am
Another tutorial was released: Jumping in 2D platform games (http://alexanderx.net/jumping-2d-platformer-games/)
Title: Re: AlexxanderX's Tutorials
Post by: lilz on April 22, 2014, 04:20:52 pm
Thats great. I did the collision-tutorial some days ago and tried to implement the jumping by myself - just for practice. It worked well but i could jump to the moon xD I will try the new tutorial.

I'm really new in programming and I think your tutorials are good for beginners.

I have one (maybe stupid question) about the code in the area part from the collision-tutorial.
for example:
Code: [Select]
if (area.contains({ area.left, player.getPosition().y }))I dont understand this brackets { }. I tried to compile it (Win7 VS 2012) and got some errors.
So I removed alle the brackets and it worked well... ?
Title: Re: AlexxanderX's Tutorials
Post by: ChronicRat on April 22, 2014, 04:25:09 pm
I dont understand this brackets { }. I tried to compile it (Win7 VS 2012) and got some errors.
So I removed alle the brackets and it worked well... ?
http://en.wikipedia.org/wiki/C++11#Initializer_lists
Title: Re: AlexxanderX's Tutorials
Post by: AlexxanderX on April 22, 2014, 09:05:38 pm
@lilz Thanks. Well, in order to use the brackets you will need a C++11 compiler.
Title: Re: AlexxanderX's Tutorials
Post by: Nexus on April 22, 2014, 09:31:54 pm
Visual Studio 2013 supports initializer lists (and many other C++11 features that have not been available in VS 2012), I recommend upgrading if possible.
Title: Re: AlexxanderX's Tutorials
Post by: lilz on April 22, 2014, 10:38:17 pm
Thanks a lot for the response. Good to know but I cant update at the moment.
Title: Re: AlexxanderX's Tutorials
Post by: AlexxanderX on April 30, 2014, 03:26:17 pm
Here is my new tutorial: How to flip sprites (http://alexanderx.net/flip-sprites/).
Title: Re: AlexxanderX's Tutorials
Post by: G. on April 30, 2014, 07:10:46 pm
Flipping a sprite with the textureRect trick is more than that if x or y is different from 0.
It's actually (x + width, y, -width, height) for horizontal flip, and (x, y + height, width, -height) for vertical flip.

You could also talk about some pros and cons of each method, for example with setScale, if the origin of the sprite isn't its center the sprite will "move".
Title: Re: AlexxanderX's Tutorials
Post by: AlexxanderX on April 30, 2014, 08:04:55 pm
Flipping a sprite with the textureRect trick is more than that if x or y is different from 0.
It's actually (x + width, y, -width, height) for horizontal flip, and (x, y + height, width, -height) for vertical flip.

You could also talk about some pros and cons of each method, for example with setScale, if the origin of the sprite isn't its center the sprite will "move".
Yes, i know if x and y are different from 0 need to add the distance and I will add and some pros and cons.
I thought to add if the x && y != 0, but I don't know why I didn't add it - bad school day I think, but thanks and will take into consideration.
Title: Re: AlexxanderX's Tutorials
Post by: AlexxanderX on May 21, 2014, 09:35:06 pm
Sorry for not posting for ~2 weeks, but had to learn for final semester exams. Here is my new tutorial: How to create a simple button (http://alexanderx.net/create-simple-button/).
Title: Re: AlexxanderX's Tutorials
Post by: AlexxanderX on June 11, 2014, 08:50:49 pm
Released a new tutorial - How to create a screenshot system (http://alexanderx.net/create-screenshot-system/) :D
Title: Re: AlexxanderX's Tutorials
Post by: G. on June 11, 2014, 09:09:18 pm
sf::Keyboard::F5 is probably clearer than 89 ;)
Title: Re: AlexxanderX's Tutorials
Post by: AlexxanderX on June 11, 2014, 09:17:51 pm
Oh, yes, thanks :D