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 - A_Pacifist

Pages: [1]
1
General / Re: How To Better Optimize This Code?
« on: May 13, 2016, 10:23:29 pm »
Thanks for all the help!
I wasn't to concerned about the actual time it took to run the code, I was just concerned that there were a bunch of if statements. I was once told by a CS teacher that if you are copying and pasting code repeatedly, you're probably doing something wrong.
Thanks all!

2
General / How To Better Optimize This Code?
« on: May 12, 2016, 12:43:10 am »
Hey Guys!
   I have been using SFML for quite some time now, but I want to really focus on optimizing and using better coding practices. My question is pretty straightforward. How could I optimize the code below to look better and not be so monotonous.

                //Movement code using if statements
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        playerSprite.move(-4, 0);
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        playerSprite.move(4, 0);
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                {
                        playerSprite.move(0, -4);
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        playerSprite.move(0, 4);
                }
I am guessing I could use a switch statement or an enumeration, but I don't know how to implement this.

Thanks for any help!
Calvin

Pages: [1]