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

Author Topic: How to make it press a button?  (Read 2474 times)

0 Members and 1 Guest are viewing this topic.

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
How to make it press a button?
« on: June 04, 2014, 02:51:56 am »
I was wondering, if i could make a rectangle has a button, then have the user click on the specific button to start a game since SFML doesnt, include buttons (at least i think they dont)?

I was wondering that if the Event for MouseButtonPress will work but how do i check that the left mouse button click anywhere inside the rectangle?
I dont have any code to show since i dont know were to start ? ANy help would be appreciated!

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: How to make it press a button?
« Reply #1 on: June 04, 2014, 03:09:06 am »
Does SFML provide a direct way to do this? No.
Can it be done very easily? Yes.
Is this specific to SFML? No, so you should probably look at google since there are unlimited ways of making buttons.

Quote
I was wondering that if the Event for MouseButtonPress will work but how do i check that the left mouse button click anywhere inside the rectangle?

Reading the documentation would surely help.

Or doing a simple search would return this or many other resources on this huge subject....  ;)
http://alexanderx.net/create-simple-button/
« Last Edit: June 04, 2014, 03:12:03 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: How to make it press a button?
« Reply #2 on: June 04, 2014, 03:30:35 am »
i realize that creating a specific button will be more complicated than needed. However due to the style of game (Retro), im not really looking for a more modern and effective way as of yet (Later i will). I only know so much in C++ so i'm trying to use the bit of knowledge i know! I was thinking and reading from other users in google, what if i create a Text string that when the mouse is within the Text string X and Y position, and clicks it using its left button, it will start the game! I've coded the game already (Simple PONG), but i'm trying to implement a better OOP style and implement newer features, both as an educational aspect and for my Portfolio!

This is just a spoken opinion since i havent tested anything, but creating a box with a text on top work as well? I just want the user to click anywere within the box, nothing fancy! I might find my answer once i finish this and go back into coding, but in my opinion and from reading others ideas, most have used a text string rather than creating a more effective method which is a class button !

Anyways thanks for the link! Once i get a better understanding of Inheritance and Classes, i'll surely try out that method! since it looks more neat and professional!

Syntactic Fructose

  • Jr. Member
  • **
  • Posts: 80
  • Overflowing stacks and eating snacks
    • View Profile
Re: How to make it press a button?
« Reply #3 on: June 04, 2014, 04:18:34 am »
i realize that creating a specific button will be more complicated than needed. However due to the style of game (Retro), im not really looking for a more modern and effective way as of yet (Later i will). I only know so much in C++ so i'm trying to use the bit of knowledge i know! I was thinking and reading from other users in google, what if i create a Text string that when the mouse is within the Text string X and Y position, and clicks it using its left button, it will start the game! I've coded the game already (Simple PONG), but i'm trying to implement a better OOP style and implement newer features, both as an educational aspect and for my Portfolio!

This is just a spoken opinion since i havent tested anything, but creating a box with a text on top work as well? I just want the user to click anywere within the box, nothing fancy! I might find my answer once i finish this and go back into coding, but in my opinion and from reading others ideas, most have used a text string rather than creating a more effective method which is a class button !

Anyways thanks for the link! Once i get a better understanding of Inheritance and Classes, i'll surely try out that method! since it looks more neat and professional!

don't use a text string, there are many obvious reasons you should avoid this. What is wrong with the link? it implements a button. If it is too complex I would recommend going back to the basics and refreshing your c++ or you will run into some issues.

The link will at least show you how to accomplish a button class, you can take when you learned and write your own bare bones class if you like with minimal functionality.

I very much understand where you're coming from, you really want to jump into SFML but your c++ might not yet be the strongest, I was in this exact same boat two years ago but some advice: Know your c++ before attempting to use libraries like SFML or other graphics libraries. If you can't understand my issue in this post http://en.sfml-dev.org/forums/index.php?topic=7579.msg50148#msg50148 you probably should follow what laurent said to me aswell :p
« Last Edit: June 04, 2014, 04:24:27 am by Syntactic Fructose »