第 16 步:我们快完成了!球入网后,让我们把球藏起来。

  • ,将Hide Sprite拖动到您的碰撞事件和 if 语句中。
  • 它应该缩进 8 个空格,如下所示: ········ sprite .hide ()
  • 将 .hide .hide()前面的名称从sprite更改为hit_sprite
  • 点击奔跑并尝试在网上投篮。如果您制作篮子,您应该会看到它消失!

To navigate the page using the TAB key, first press ESC to exit the code editor.

stage.set_background("halfcourt") sprite = codesters.Sprite("player1") sprite.go_to(-175, -150) net = codesters.Sprite("basketballnet") net.go_to(215, 175) stage.set_gravity(10) sprite.set_gravity_off() def click(sprite): ball = codesters.Sprite("basketball") ball.go_to(-175, -125) ball.set_x_speed(10) ball.set_y_speed(10) # add other actions... sprite.event_click(click) stage.disable_right_wall() def collision(net, hit_sprite): my_var = hit_sprite.get_image_name() if my_var == "basketball": sprite.say("Score!") # add any other actions... net.event_collision(collision)
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)