Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - codelyoko373

Pages: [1]
1
General / Re: Ping Tutorial Question
« on: August 26, 2017, 04:22:48 pm »
For the state stack it's understandable to use heap allocation as it stores the states as pointer to base class - although modern C++ would prefer a smart pointer (aka RAII) which can be stored in a vector using std::move() and takes care of the new/delete problem. Members such as font and text have no need for heap allocation, and can be initialised via the constructor's initialiser list rather than using double initialisation (which is still true even if you do decide to use smart pointers). It seems unusual to write 'this' everywhere (to me at least), although it appears to be a preference thing - many people instead prefix members with m_ or _. If you can, check out the first SFML game development book, it has a great example of a state stack, and is probably the best of the bunch.

Apparently the guy used "this" a lot to just show the viewers what variables he was referencing. And that state pointer is a raw pointer so surely it's bad that It's not being deleted anywhere

2
General / Ping Tutorial Question
« on: August 26, 2017, 02:57:45 am »
I'm quite new to SFML and the first tutorial I watched for SFML was how to basically make pong, this tutorial:

It this tutorial he taught me how to create this basic menu system. All menu's such as the Main Menu and the actual game would inherit this "BaseState" subclass: https://image.prntscr.com/image/Jx0fTP5SRGySmurrJ-_img.png
And then the actual class had code to manage these menus:
https://image.prntscr.com/image/radyTH_xRkuqrbcmEIHMuw.png
https://image.prntscr.com/image/7Mgd1AxhTpmxMJ6RVkixAg.png

The way you would change state is using the SetState function like this:
CoreState.SetState(new MainMenu());
but I've noticed that the new keyword is used but the created MainMenu object shown is this example isn't actually deleted anywhere, the only things that are deleted are the pointers used within these menus. It would have to be deleted wouldn't it or am I missing something?
I've tried deleting the menu with "delete this" in the destroy function that is called when the menu changes but it doesn't seem to work.

Sorry for the long post

3
General / Re: When should I be using pointers?
« on: August 22, 2017, 10:18:56 pm »
Firstly, a bit of theory:
https://stackoverflow.com/a/79936

Now, If the stack model is convenient for you (small size, short lifespan, etc..), use it, there's no reason not to (however,make sure you're not creating global variables just so you can use stack model. Always avoid globals). Only use heap if stack memory management is insufficient.

On top of that, when you finally use pointers, use smart pointers instead of the raw ones, as smarts are safer.

So I'm guessing I shouldn't be making all those pointers then? (Shown in the screenshot)

4
General / When should I be using pointers?
« on: August 22, 2017, 04:35:35 am »
(Sorry if this is in the wrong place)

I firstly want to point out I know what pointers are and how to use them though they're still quite a confusing topic to me. I can see how they're useful when you're for example wanting to pass a variable around through functions without making copies of it but that's about it.

Should I be making all variables pointers or not for example?

The reason I mainly ask this is because the tutorial series I watched for making pong in sfml, the guy basically always created pointers, all his variables were pointers so I've done exactly the same thing but it doesn't feel right.

5
General / Re: Strange Sprite Offset
« on: August 21, 2017, 02:51:08 am »
Is there a way to fix this?

6
General / Re: Strange Sprite Offset
« on: August 21, 2017, 01:37:14 am »
That didn't work, The sprite is still in the same place.

Did I do it wrong?
invader2 = new MenuInvader();
   invader2->setScale(1.0f, 1.0f);
   invader2->setOrigin(invader2->getGlobalBounds().width / 2, invader2->getGlobalBounds().height / 2);
   invader2->setPosition(window->mapPixelToCoords(sf::Vector2i(window->getSize().x / 2, window->getSize().y / 2)));

7
General / Strange Sprite Offset
« on: August 20, 2017, 11:16:11 pm »
I'm attempting to recreate Space Invaders using SFML and I'm currently working on the menu.

I wanted to add two sprites to the menu but I'm having lots of problems trying to get the sprites into position.
This is the code I'm using to create one of the sprites as well as set it's position and origin (I commented out the other sprite for testing reasons):
invader2 = new MenuInvader();
   invader2->setScale(5.0f, 5.0f);
   invader2->setOrigin(invader2->getGlobalBounds().width / 2, invader2->getGlobalBounds().height / 2);
   invader2->setPosition(window->getSize().x / 2, window->getSize().y / 2);

This is what it looks like in Game:

For some reason the sprite is far off the screen and the only way I can fix this is by scaling the sprite back down to it's original size but even if I do that, there is still this strange offset from the centre of the screen which is where I want the sprite to be:


Does anyone know what's going on?

8
Graphics / Selecting different sized Sprites from Sprite Sheet
« on: August 20, 2017, 02:07:53 am »
I'm quite new to SFML and I have looked at some videos of getting different sprites from sprite sheets but the reason those videos haven't really helped me is they use sprite sheets that hold same sized sprites throughout while the sprite sheet I'm using which is for Space Invaders:

Has different sized sprites.

I was wondering how exactly I would get these different sized sprites out of the sprite sheet?

Pages: [1]