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

Author Topic: Flashing Text  (Read 4946 times)

0 Members and 1 Guest are viewing this topic.

lockandstrike

  • Newbie
  • *
  • Posts: 32
    • View Profile
Flashing Text
« on: August 06, 2013, 08:13:17 pm »
So hi. I'm starting my game and I'm doing the menu. I've decided the way I'm going images for the background and text for the actual button. So what i would like is when the user is going through the menu with the arrow keys the button witch is currently selecting is highlighted. The highlight would be the text flashing. By flashing I mean switching between 2 colors. I have no idea how to so any help is tremendously appreciated.  ;)

Aster

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: Flashing Text
« Reply #1 on: August 06, 2013, 08:23:50 pm »
Alrighty, where to start?
You're probably looking for sf::RectangleShape, since you can give those borders, and textures. A simple button class like the one you want is very simple to implement if you have basic knowledge in C++.
sf::RectangleShape has the sf::RectangleShape::getGlobalBounds()::contains() function, to which you could pass the mouse position to check whether the mouse is over it.

However, judging by your previous questions, you aren't too proficient with C++ yet, so I would definitely recommend learning it without the help of SFML. Just grab a book, like C++ Primer, 5th Edition. Take a few months to learn basic C++ before giving your hand to game development. When you're done, you'll be able to do most of what you've asked for on your own, as what these questions are, are very, very basic concepts that any programmer should know.

lockandstrike

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Flashing Text
« Reply #2 on: August 06, 2013, 08:38:28 pm »
Still everything you said in the first paragraph didn't change a thing because what I want isn't simply changing the color once when it's selected, I want it to continuously change the color of the text, not the outline, until it's been deselected.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Flashing Text
« Reply #3 on: August 06, 2013, 08:44:00 pm »
Use sf::Clock and switch the color after enough time has passed.
Back to C++ gamedev with SFML in May 2023

lockandstrike

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Flashing Text
« Reply #4 on: August 06, 2013, 08:47:18 pm »
Ok thank you very much. It's such a simple solution. Should have thought of that. :facepalm:

Aster

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: Flashing Text
« Reply #5 on: August 06, 2013, 08:56:25 pm »
Still everything you said in the first paragraph didn't change a thing because what I want isn't simply changing the color once when it's selected, I want it to continuously change the color of the text, not the outline, until it's been deselected.

I didn't mention flashing. Problem solving is part of programming, if you can't solve simple problems, you aren't a good programmer, and need to learn. The function I gave was just to show that SFML offers a pretty easy way to do things like this. I wasn't trying to give you the code required to solve your problem because I don't think doing things that way helps you learn anything.

If you want, you could do a
if(sin(time) > 0)
    set_color_to_something();
else
    set_color_to_something_else();
 
You could also use the sin function for smoother flashing, if you have basic understanding of trigonometry and how colors work in graphics programming.

You should seriously consider getting a book.
« Last Edit: August 06, 2013, 09:00:58 pm by Aster »