Activity: Hide Ball
I'M FINISHED WITH HOUR OF CODE!

STEP 16: We're almost done! Let's hide our ball once it hits the net.

  • In , drag Hide Sprite INSIDE your collision event and if statement.
  • It should be indented 8 spaces, like this: ········sprite.hide()
  • Change the name in front of .hide() from sprite to hit_sprite.
  • Click Run and try shooting the ball at the net. You should see it disappear, if you make a basket!

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)
Support