Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. 知识库
  3. 三维积木
  4. 鼠标悬停事件

鼠标悬停事件

Scheduled Pinned Locked Moved 三维积木
1 Posts 1 Posters 718 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CreatiCode TA 2
    wrote on last edited by admin
    #1

     

    预备知识

    • 添加盒子
    • 名称和角色物体

     

    介绍

    为了允许用户与场景中的物体互动,我们可以允许用户在不点击物体的情况下把鼠标悬停在任何物体上方。

     

    “开启悬停”编程积木

     
    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1b0304c2-e2b5-41e3-b609-0e567e763322.png" width="700" style="">

     

    角色列表

    为了指定哪些场景中的物体可触发鼠标悬停事件,你可以指定一系列的角色名称并用逗号来分隔他们,比如角色1,角色2。需要注意的是,你需要使用逗号作为分隔器。通过这样的方式,每一个在角色中创建的物体将会回应鼠标悬停。如果角色列表为空,那么系统将会默认使用现有角色名称。

    因为你可以指定多个角色,所以你只需要运行这个编程积木一次,通常会是程序起始步骤之一。

     

    诠释悬停事件的编程积木

    下列4个编程积木可以允许你得到更多关于悬停事件的资讯,包括被悬停物体的名称,以及被悬停物体的确切定位。

     
    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1a276fb3-528f-4688-aa78-cf8db20aa1a7.png" width="900" style="">
    需要注意的是如果鼠标没有悬停在指定角色的物体上,那么“被悬停物体名字”将会显示空白。

     

    “关闭悬停事件”编程积木

     
    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/950d8f7e-5569-4d78-bcf6-c483aaead372.png" width="500" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">

    这个编程积木允许你在角色列表中移除某些角色,以便被移除角色中创建的物体不再回应鼠标悬停事件。角色名字列表需要被逗号分隔,比如角色1,角色2。
     

    关闭/开启物体悬停事件

    有时候,指定角色名称可能不够准确。举个例子,假设一个角色创建了五个物体,而你只需要其中三个物体回应鼠标悬停。这样的情况下,你可以利用以下两个编程积木,通过指定物体名称来关闭或开启鼠标悬停。

     

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/cbae56d6-4dd8-475d-b2b7-3aacc2150299.png" width="400" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/49c05dfc-bd0b-4ebd-82ed-5b6fc03f928b.png" width="400" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">

    物体名称列表需要被逗号分隔,比如盒子A,盒子B。

     

    演示

    在这个演示中,我们让一个盒子在鼠标悬停在盒子上方时变大,当鼠标被移走时,盒子将会恢复它原本的大小。

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/a244ea23-d26f-4a9f-b6eb-171fdf977c8d.gif" width="480" style="border-radius: 5px; border: 1px solid #29622d;">

    场景中有两个角色。
    在角色1,我们允许用户把鼠标悬停在“盒子”角色创建的任何物体上,然后我们将会发送消息以添加一些盒子。

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/28c741ee-fb96-43ca-a45a-47075d0cc775.png" width="450" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">
     
    在**“盒子”**角色中,当我们受到广播信息是,我们先添加一个名为“平地”的平面,但是关闭平面物体的鼠标悬停。接着,我们在随机位置添加五个盒子。这样的话,就只有这五个盒子能够激活鼠标悬停事件。

    接下来,我们进入一个重复执行循环来反复检查被悬停物体名字。

    当“被悬停物体名字”不是“无”,这意味着鼠标悬停在某个物体上。我们使用“悬停物体名字”变量来储存被悬停物体的名字。如果那个变量跟“悬停物体名字”不一样,那就代表有其他物体被悬停,那么我们就需要把上一个被悬停物体的比例恢复到100%。接着,我们选定最新的悬停物体并把它的比例调整到150%。我们也需要把最新的悬停物体名称储存到“悬停物体名字“变量中。
    当“悬停物体名字”是”无“的时候,我们只需要把上一个悬停物体的比例恢复至100%即可。

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f8bd5c1f-672b-4267-9fa7-c794c77cfdab.png" width="700" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">

     
    动手时刻:

    https://play.creaticode.com/projects/cda97d7a292852ecb076f69d

    1 Reply Last reply
    0
    • CreatiCodeI CreatiCode pinned this topic on

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode