Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Window
»
How to move a rectangle with two clicks in SFML?
Print
Pages: [
1
]
Author
Topic: How to move a rectangle with two clicks in SFML? (Read 11183 times)
0 Members and 1 Guest are viewing this topic.
zed118
Guest
How to move a rectangle with two clicks in SFML?
«
on:
August 30, 2021, 04:52:15 pm »
I want to move a rectangle in such a way that the first click selects it and the second click will change its position to wherever the current mouse position is. I've written the code for actually changing the position of the rectangle. The only problem is actually triggering these events because when I try to, it detects more than one click. What would be your approach?
Logged
Hapax
Hero Member
Posts: 3417
My number of posts is shown in hexadecimal.
Re: How to move a rectangle with two clicks in SFML?
«
Reply #1 on:
August 30, 2021, 05:19:05 pm »
Flags.
Use a flag (boolean value) to represent when something has been selected.
When you click:
if the isSelected boolean is not set, set it, if it's on the shape.
if the isSelected boolean is already set, unset it and move the shape.
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
G.
Hero Member
Posts: 1599
Re: How to move a rectangle with two clicks in SFML?
«
Reply #2 on:
August 30, 2021, 05:45:03 pm »
If you set mouse_pressed in your first if, and the condition of your second if is "mouse_pressed == true" then of course the condition will be verified immediately, use an "else if"
Logged
Hapax
Hero Member
Posts: 3417
My number of posts is shown in hexadecimal.
Re: How to move a rectangle with two clicks in SFML?
«
Reply #3 on:
August 30, 2021, 05:45:56 pm »
EDIT: what G. said.
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
Print
Pages: [
1
]
SFML community forums
»
Help
»
Window
»
How to move a rectangle with two clicks in SFML?
anything