How do you make buttons only pressed while the mouse cursor is on it?

So how would you recommend doing this for an indefinite amount of buttons and clones of buttons that need to be spread out through every stage?

of course, you make it as a scene and with its own script for the scene
the script of this ā€œbuttonā€ scene will send signal to tell what it can do when in and out the button area
the ā€œwhat it can doā€ will be determined when it’s spawned/instantiated from main script
the receiver or the main script/player script will then connect the signal from each button (so when instantiated the button, you will also need to connect the signal, this if you dont do EventBus Autoload signalling) and execute movement either by function or boolean that’s always running (put in a _physics_process)

1 Like

Just to be clear, I can make clones of the buttons using this method and place them separately and differently through each level?

make it as a scene or PackedScene, then reference the scene, then .instantiate() it and add_child it, then set the ā€œwhat it can doā€ variable, so it has different purpose

1 Like

Would this be easier to do with regular buttons? And how would regular buttons work in this, and do touchscreens react to regular buttons?

yes, but it doesnt do what touchscreenbutton do, when you pressing the button it wont count as a press, so you will need to handle it like touchscreenbutton by button down and button up signals with boolean

2 Likes

Is there really no way that doesn’t use scripts? Since I have to copy and paste these buttons a lot for my levels, it would be a pain if I had to mess with the scripts as well, but if there’s no other way then I guess I’ll use the control and script way.

this will need for a level generator, basically a random way to spam the button by code in a loop, rather than manually putting it one by one

when you want it to be automated , very difficult to do it without custom script. it’s just the way it’s

1 Like

So, with the level generator, how do I place the buttons? And where do I place the level generator? I’m assuming it’s it’s own node, but I could be wrong.

i dont know how is your leveling, so cant tell how, if it’s just randomly generated for any level, then you just need to make a button spawner code

1 Like

I manually place each object and it’s coordinates in each level. Although randomly generated levels do sound interesting, but also hard to program.

ok, so make and place PackedScene of the button instead of new button and new script every time it’s new

image
click that and select the scene of button with script

1 Like

So packed scene carries over everything, including script?

yes, when you created a new button and attached a script to it, and it’s the button you want to duplicate, you can save it as a scene first, then next time you want to duplicate it, it will carry over as a scene

to make a scene from current node
right click the node, and select save branch as scene
image

1 Like

Oh, ok now I understand, so I add a control node to button, add a script to the button, then I can copy and paste as a packed scene.

1 Like

Ok, so now that I understand what to do a little more, after adding the control node to one button, what do I do next? Do I add a script now?

the button is basic Control’s button? if that so why need to add control as a child of this button?

1 Like

No I’m still using touchscreen if that will work.

ok, so add a script to it
make it as a scene afterwards

then any changes will be done on that touchscreenbutton scene

1 Like

I already had it saved as a separate scene, and in a buttons scene, but I’ve added the control node to both scenes, and a script to the one in the buttons scene. Should I make a new button scene now that I have the script and control node?