Discuss Scratch

ikuzduy
Scratcher
100+ posts

How do I make a floating button in the easiest way possible?

How do I make a floating button in the easiest way possible? (and smoothest)
Thanks
Mechanical_coding
Scratcher
44 posts

How do I make a floating button in the easiest way possible?

you said easiest way so…

make a sprite that has a button on it
then code this:
when @greenFlag clicked
forever
go to (front v) layer

when this sprite clicked
broadcast (clicked v)
legendary34678
Scratcher
1000+ posts

How do I make a floating button in the easiest way possible?

By “floating” I assume you mean moving up and down smoothly. You can use the sine function for this. Not sure if you've learned about it in math yet, but simply, sine is a function that oscillates smoothly between -1 and 1 which you can use to create a bobbing effect.
RadiusGames46
Scratcher
100+ posts

How do I make a floating button in the easiest way possible?

Alright.

when gf clicked
set size to (0)% // Some code below will make this pop in.
show
forever
go to x: (desired x :: grey) y: ((([sin v] of ((timer) * (100))) * (5)) + (desired y :: grey)) // Bobbing effect.
set size to (((size) + (100)) * (.5))% // Smoothly move the size to 100.
if <touching (mouse-pointer v)?> then
change size by (15) // Increase size on hover.
if <mouse down?> then
broadcast [pressed v] // Button was clicked, so begin any other code.
hide
stop [this script v] // Stop the code. If you want it to continue, remove this block and the hide block.
Hope this helps!
alisonw778
Scratcher
9 posts

How do I make a floating button in the easiest way possible?

Thanks! This really helped! Follow from me.
samululas
Scratcher
2 posts

How do I make a floating button in the easiest way possible?

when green flag clicked
go to x: (0) y: (0)
forever
point in direction ([sin v] of ((timer) * (400))+(specific direction)
end

Last edited by samululas (Nov. 17, 2023 15:15:02)

LaMahr_Jr101112
Scratcher
3 posts

How do I make a floating button in the easiest way possible?

RadiusGames46 wrote:

Alright.

when gf clicked
set size to (0)% // Some code below will make this pop in.
show
forever
go to x: (desired x :: grey) y: ((([sin v] of ((timer) * (100))) * (5)) + (desired y :: grey)) // Bobbing effect.
set size to (((size) + (100)) * (.5))% // Smoothly move the size to 100.
if <touching (mouse-pointer v)?> then
change size by (15) // Increase size on hover.
if <mouse down?> then
broadcast [pressed v] // Button was clicked, so begin any other code.
hide
stop [this script v] // Stop the code. If you want it to continue, remove this block and the hide block.
Hope this helps!


Where did you get “((timer)” from???????????????????????

Last edited by LaMahr_Jr101112 (June 4, 2025 18:21:53)

N8_D_GR8_1
Scratcher
1000+ posts

How do I make a floating button in the easiest way possible?

LaMahr_Jr101112 wrote:

Where did you get “((timer)” from???????????????????????
It is in the sensing (light blue) category of blocks. In the future, please create a new topic for any questions you have. Thanks!

Powered by DjangoBB