Changing Backgrounds 3 methods of achieving this
CHALLENGE 1 – You are going to practice your Background changing programming skills: You will automatically move from the first background to the second background after a pre-set time. On arriving at the second background a button will appear which, when clicked on, will send the user back to the first background. Alternatively, the user could press the space bar and this will send the user back to the first background. The user must be able to move between the backgrounds as many times as required. Program scratch to do this Do this as a new project!! 40 minutes
Add two backgrounds: stage section Add this code to the script area on the stage section When the flag is clicked ‘school image2’ (background 1) is shown. After a pre-set time the background changes to ‘classroom clip art’ (background 2). When this happens a message is broadcasted called “button” which will be received by the button sprite ( see next slide). Explanation
On the Button Sprite: Button sprite Add this code to the script area for the Button sprite When the flag is clicked the button sprite is hidden – it will not be seen on background 1. When the sprite receives the message “button”, which is broadcast by the code on the stage (see the previous slide), the button will appear on background 2 as the two backgrounds interchange. Explanation
On the button sprite Add this code to the script area for the Button sprite There are two options available to return to the first background. When the button sprite is clicked the code in the section ‘When this sprite is clicked’ is operated. This hides the button sprite and switches the background to background 1. The second option is to press the space bar. The code produces exactly the same effect – hides the button sprite and changes the background. Broadcast Screen 1 will be covered in the next slide Explanation
Background scripts We have now returned to the first background, see the previous slide as to how we did this. We want to advance automatically to background 2, as we did when the flag was first clicked. In this second instance there is no click event to do this as we had before and, therefore, no code operating. We need to create a new event. In both the button sprite click event code and the Press Space bar event code we broadcast a message called ‘screen 1’. This is received by the ‘When I receive Screen 1’ event (see image above) which runs the code, starting the process again stage section Add this code to the script area for the stage section Explanation
CHALLENGE 2 - Decompose what you have done Produce a word document start: When the game starts Show the first background Show the second background Can you think of the next bits to decompose? 10 minutes
Example of Decomposition: Making the cup of tea Boil the water Fill the kettle with water Close the lid Switch on Switch off Brew the tea get the teabag Place in pot Pour the hot water into the pot Stir the tea wait Fill the cup
1 Changing Backgrounds – student (2015) by Lucy Stone Sir Jonathon North Community College Shared under a CC-BY 4.0 licenceCC-BY 4.0