Page 1 of 1
How to make a button that will still work after being moved
Posted: Fri May 06, 2022 9:34 pm
by Nightmare
Hello! I am trying to make a core game and need a button that works with the camera plugin in:
https://github.com/vrld/hump I want to know a way to make a button that can move and still works, Thanks!
Re: How to make a button that will still work after being moved
Posted: Sat May 07, 2022 12:32 am
by pgimeno
Assuming you want a button located in a place in the world:
Use the camera library to translate world coordinates to screen coordinates. Then tell your GUI library to place it in the returned coordinates.
Re: How to make a button that will still work after being moved
Posted: Sat May 07, 2022 6:11 pm
by Nightmare
I'm new to love and if I could have a code sample it would help, thanks!
Re: How to make a button that will still work after being moved
Posted: Sat May 07, 2022 10:48 pm
by pgimeno
Here's an example using cam11 for camera and Gspot for GUI. It places two buttons on the map, one in Wermin and one in Garrt. I found the positions with Gimp because they have to be defined in image pixels. For maps, you use map coordinates.
Map credits:
https://opengameart.org/content/rpg-map
Re: How to make a button that will still work after being moved
Posted: Sun May 08, 2022 1:48 am
by Nightmare
Thanks!
Re: How to make a button that will still work after being moved
Posted: Mon May 16, 2022 8:32 pm
by Nightmare
I'm also still a bit confused about this could you explain this a little simpler, I also dont wanna make buttons with libraries with the camera plugin I was using.
Re: How to make a button that will still work after being moved
Posted: Tue May 17, 2022 1:14 am
by pgimeno
Take a look at the docs for cam11:
https://notabug.org/pgimeno/cam11, specifically the section titled "Definitions".
Pay special attention to the distinction between screen coordinates and world coordinates. Try to understand both concepts.
Don't keep reading until you have read and understood it.
----------------------------
If you want your buttons in a fixed position in your map, you need to convert the map coordinates to screen coordinates. I don't know hump.camera, so I can't help you with it.
Once you have the screen coordinates, you can draw your button and use the same coordinates to recognize the click position.
If you want better help, you will need to provide more details about what you want to do.
Re: How to make a button that will still work after being moved
Posted: Tue May 17, 2022 7:27 pm
by Nightmare
Could I have an example how to make this without a library for the buttons?
Re: How to make a button that will still work after being moved
Posted: Tue May 17, 2022 8:57 pm
by pgimeno
No. If you don't want to use a GUI library, I have to assume you know how to draw buttons and make them clickable. I told you how to find out where to place them, and I gave you an example of how to set the button's x and y coordinates. Now it's up to you to do the groundwork.
Re: How to make a button that will still work after being moved
Posted: Wed May 18, 2022 1:46 pm
by milon
There are already many sample & complete .love projects posted in the
Games & Creations subforum. I recommend browsing through there for something related/interesting. Download it, rename the .love to .zip, extract, and look at the code. It's a great way to learn new things!