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

Author Topic: Anyone know about this code example?  (Read 2057 times)

0 Members and 1 Guest are viewing this topic.

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Anyone know about this code example?
« on: August 02, 2012, 10:05:54 pm »
While googling for SFML code samples a few weeks ago, I found a sample that had examples of what I wanted to learn.  I thought I bookmarked that webpage but evidently did not.  Now I can't find that webpage anymore.

The code used C++ and SFML, and I believe it was for a game.  It was just a few pages of tutorial and code, not very long. The code included:

A way to store the coordinates of areas on the screen (like buttons for instance) in a list.  Then use a for or while loop to scan each area using an iterator see if a mouse click coordinates is within any of the areas.  If yes, take the appropriate action.

I've been googling for hours and can't find that webpage again.  Anyone happen to know of a webpage that has sample code like that?

Thanks,
Raptor

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Anyone know about this code example?
« Reply #1 on: August 03, 2012, 06:39:08 pm »
Could it be this(it's other loop but still list and hard to find tutorial)?
40 MainMenu::MenuResult MainMenu::HandleClick(int x, int y)
41 {
42   std::list<MenuItem>::iterator it;
43
44   for ( it = _menuItems.begin(); it != _menuItems.end(); it++)
45   {
46     sf::Rect<int> menuItemRect = (*it).rect;
47     if( menuItemRect.Bottom > y
48       && menuItemRect.Top < y
49       && menuItemRect.Left < x
50       && menuItemRect.Right > x)
51       {
52         return (*it).action;
53       }
54   }
55
56   return Nothing;
57 }
That's from game from scratch c++ edition part 3 : http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-Part-3.aspx
« Last Edit: August 03, 2012, 06:40:44 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Anyone know about this code example?
« Reply #2 on: August 04, 2012, 10:26:39 am »
Could it be this(it's other loop but still list and hard to find tutorial)?
.... snip ...
That's from game from scratch c++ edition part 3 : http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-Part-3.aspx

FRex,

Thank you, thank you!!  That is the code, along with the "struct MenuItem" in mainmenu.h.

I had mentally eliminated gamefromscratch so everytime it showed up during my searching, I just skipped it.  I spent quite a few more hours since my post, continuing to search for the code and never would have found it if not for you.

Thank you so much again!
Raptor

 

anything