How to make a button that will still work after being moved

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Nightmare
Prole
Posts: 5
Joined: Fri May 06, 2022 9:25 pm

How to make a button that will still work after being moved

Post 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!
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to make a button that will still work after being moved

Post 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.
User avatar
Nightmare
Prole
Posts: 5
Joined: Fri May 06, 2022 9:25 pm

Re: How to make a button that will still work after being moved

Post by Nightmare »

I'm new to love and if I could have a code sample it would help, thanks!
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to make a button that will still work after being moved

Post 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
Attachments
example-button-on-map.love
(467.48 KiB) Downloaded 82 times
User avatar
Nightmare
Prole
Posts: 5
Joined: Fri May 06, 2022 9:25 pm

Re: How to make a button that will still work after being moved

Post by Nightmare »

Thanks!
User avatar
Nightmare
Prole
Posts: 5
Joined: Fri May 06, 2022 9:25 pm

Re: How to make a button that will still work after being moved

Post 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.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to make a button that will still work after being moved

Post 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.
User avatar
Nightmare
Prole
Posts: 5
Joined: Fri May 06, 2022 9:25 pm

Re: How to make a button that will still work after being moved

Post by Nightmare »

Could I have an example how to make this without a library for the buttons?
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to make a button that will still work after being moved

Post 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.
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: How to make a button that will still work after being moved

Post 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!
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests