You can find the DRAG ON and DRAG OFF commands in the ACTIONS Toolkit by scrolling down to SPRITE INTERACTIONS. When drag is turned on, you can click, hold, and drag the sprite anywhere on the stage. The default for a Sprite is DRAG OFF. Run the program to try DRAG. A second example uses DRAG with a Collision Event to feed a cow.

# EXAMPLE 1 - DRAG ON sprite = codesters.Sprite("person1") sprite.set_drag_on() sprite.say("Example 1") stage.wait(3) sprite.say("Click me, hold and drag") stage.wait(6) stage.remove_sprite(sprite) stage.wait(2) # EXAMPLE 2 - DRAG with Collision # Set up the Sprites cow = codesters.Sprite("cow") cow.set_drag_on() sprite = codesters.Sprite("hay",-100,-130) sprite.set_size(.5) cow.say("Example 2") stage.wait(1) cow.say("") text = codesters.Text("I'm hungry! Drag me to the hay",0,180) # When the cow collides with the hay, the hay is hidden # and the "Yum" message displayed # This part of the code defines the collision event def collision(sprite, cow): sprite.hide() text.set_text("Yum! Thank you!") # This calls or activates the collision event sprite.event_collision(collision) # The wait gives the player 6 seconds to "feed" the cow # and then the sprite and text are removed stage.wait(6) stage.remove_sprite(text) stage.remove_sprite(cow) #__________________________________________________ # # Menu of what you find in the program # #__________________________________________________ stage.wait(1) sprite.hide() stage.set_background_color("white") heading = codesters.Text("HOW TO USE DRAG",0,175) heading.set_color("red") heading.set_size(1.5) text1 = codesters.Text("Look at the Code:",0,120) text1.set_color("#14a4dd") text1.set_size(1.25) text2 = codesters.Text("Example 1 - Drag On",0,80) text3 = codesters.Text("Example 2 - Drag with Collision Event ",0,40) text4 = codesters.Text("ACTIONS Toolkit - Scroll down to SPRITE INTERACTIONS",0,-100) text4.set_size(.8)
Support