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

Author Topic: Need help with button class [Solved]  (Read 1247 times)

0 Members and 1 Guest are viewing this topic.

Calm530

  • Newbie
  • *
  • Posts: 2
    • View Profile
Need help with button class [Solved]
« on: November 21, 2016, 05:28:09 pm »
So, I have a problem with my button class. I know how to make a button in main but I want to make a button "Prefab", so I can easily make several buttons with different sprites.

the first part of code (the code I have in main) works fine, the class doesn't, it doesn't register me even hovering over.

code:  http://pastebin.com/sswTTn7k

Gif of problem: https://gyazo.com/51087ff491395fc2aa0d1412063da9db
« Last Edit: November 22, 2016, 05:56:52 pm by Calm530 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Need help with button class
« Reply #1 on: November 21, 2016, 06:16:52 pm »
You retrieve the button bounding rect, before the button (sprite) has a texture, thus the button bounding rect is still (0, 0, 0, 0).

I recommend you study again how member variables are initialized and what the difference is between initialization list and in-class initialization. And think about what can already be initalized before the constructor gets "called". :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Calm530

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Need help with button class
« Reply #2 on: November 22, 2016, 05:54:32 pm »
I fixed it a few hours later, but thanks for the reply, I didn't have time to take post down..

 

anything