Шаблон:About
Making a dropdown menu can be useful for making an animated selection for a project. These can be any shape, size, or color but the coding is the same. This tutorial will teach how to make a dropdown menu .
Setup
To start, create a sprite. Draw a costume however the dropdown is wanted. Here is an example:
Name this costume "closed".
Now, duplicate the costume and flip the arrow. Now it should be looking like this:
Now, make more costumes, each one being an option to choose. Create variables called
Make two custom blocks:
Coding
Make this code:
Шаблон:Tip
when clicked set chosen to 0 set position to closed go to x: . . . y: . . . set size to . . . % switch costume to closed forever if touching mouse pointer ? and mouse down? then if position = open then close wait until not mouse down end if position = closed then open wait until not mouse down end end define close if position = open then switch costume to closed broadcast close end define open if position = closed then switch costume to open set clone # to 0 repeat 3 change clone # by 1 create clone of myself end change clone # by 1 end when I start as a clone if clone # = 1 then switch costume to option 1 glide 0.2 secs to x: . . . y: . . . else if clone # = 2 then switch costume to option 2 glide 0.2 secs to x: . . . y: . . . else if clone # = 3 then switch costume to option 3 glide 0.2 secs to x: . . . y: . . . else delete this clone end end end set position to open when I receive close if clone # = 1 then glide 0.2 secs to x: . . . y: . . . delete this clone else if clone # = 2 then glide 0.2 secs to x: . . . y: . . . delete this clone else if clone # = 3 then glide 0.2 secs to x: . . . y: . . . delete this clone else delete this clone end end end set position to closed set clone # to 0 when I start as a clone wait 0.2 seconds if touching mouse pointer ? then set ghost effect to 20 if mouse down? then if clone # = 1 then set chosen to 1 broadcast close else if clone # = 2 then set chosen to 2 broadcast close else if clone # = 3 then set chosen to 3 broadcast close else delete this clone end end end end else set ghost effect to 0 end when clicked if touching mouse pointer ? then set ghost effect to 20 else set ghost effect to 0 end
Example Project
The following is an example project.