btaeagle.blogg.se

How to make something bounce when touching a color in scratch
How to make something bounce when touching a color in scratch





A variable is a way of storing data used in a the project. Let's go through it and explain how it works.įirst, we're using two variables - here named "OldX" and "OldY".

how to make something bounce when touching a color in scratch

This is the entirety of the script that takes care of it:

  • Find the ||sprites:mySprite image|| block in the Sprites menu – this is the image that is flippedĬontroller.A.onEvent(ControllerButtonEvent.The way that I do this is through the use of what I call the "old X and old Y" method.Įssentially, you constantly record the current location of the sprite, and then go back to that when touching the lines.
  • Note use of the function called “flipHorizontal”.
  • Create a new project and name it “flipImage”.
  • This can be useful in creating a simple 2 frame walking animation. Example #4: Image Flip with button press eventįlipping an image creates a mirror image when we use ||images:flip horizontal|| block. Concept: Flip Imageīy making a mirror flip of a sprite we can simulate walking by making each leg appear differently. The ||sprites:stay in screen|| block is in the Sprites menu.
  • Challenge: add button events that stop the sprite’s motion, and reset the sprite to the center of the screen.
  • Make the sprite stay in the screen boundary.
  • Change the key pad motion to use the discovered block by placing it in ||game:on start||.
  • how to make something bounce when touching a color in scratch

    Explore the Controller menu for ||controller:move mySprite with buttons|| and select the plus sign in the block to see ||controller:vx 100 and vy 100||.Start with motion (short method) example above or similar code.Create the sample code and run the codeĬ(ControllerButtonEvent.Pressed, function () ) Student Task #3: Create Velocity Motion.Create a new project and name it “motionLR”.Short methods and functions with motionĮxample #1: Increment position left and right.Setting ||sprites:vx|| and ||sprites:vy|| velocity.Incrementing ||sprites:x|| and ||sprites:y|| coordinates.

    how to make something bounce when touching a color in scratch how to make something bounce when touching a color in scratch

    In these activities, the student will use: When the velocities of a sprite are not zero, then the sprite will be in motion. Velocity is the rate of change of our position - in real life, this is often measured as kilometers per hour or miles per hour. We will also see how to give a sprite a speed of motion, or velocity. We can use those events to change sprite location, and to make the sprite move. The game pad has ||controller:controller events|| for the ||controller:up||, ||controller:down||, ||controller:left|| and ||controller:right|| buttons. To get sprites moving, we will change their position using a game pad event.







    How to make something bounce when touching a color in scratch