Rectangle and Elipse
- Create a new script
- Add the game libarary
In addition to pictures, can add rectangles and ellipses
var square board→create rectangle(100, 100) var circle board→create ellipse(100, 100)
- Inputs are the width and height of the rectangle and ellipse
Rectangles and ellipses are sprites just like pictures, but can also change their color
square→set color(colors→random)
Touch Input
Can get the location of the user’s finger
var point := board→touch current
- The variable
point
is a new type we haven’t seen yet, aVector3
- It represents a point in 3 dimensions
Vectors have x and y values just like sprites
square→set x(point→x) square→set y(point→y)
- But notice that the square moves into the upper left corner of the sreen when the app first starts
- Recall that the upper left is 0, 0, that is the value of
touch→current
before the user actually touches the screen To fix this, we need to check if the user is actually touching the screen
if board→touched then var point := board→touch current square→set pos(point→x, point→y) else do nothing end if
Overlap
It wouldn’t be much of a game if we couldn’t test if sprites were interacting with each other
if square→overlaps with(circle) then rectangle→set color(colors→random) else do nothing end if
Quiz
- socrative.com
- Room name ‘INQ241’