Code help with edges


#1

For lesson 19, yesterday I had two students try to draw a thin line (empty border as a sprite and place it at the edges then use

if character is touching edge

    character bounce off edge

This just made the sprite disappear completely.
They have it set up just like the character and the obstacle, and the character does bounces off obstacle.

Is it because the border really isn’t “empty” even though it’s “see-through”? I tried the same code with just a vertical line on the left edge and it still made the sprite disappear. Does it need to be cropped so it’s really a long thin line?

We found another way to create “edges” to keep the character from flying out, but we’re curious as to what is wrong with this set-up.


#3

@lkeil

Hi, can you post a “Share” link to the code so we can take a look?

Thanks,
Elizabeth


#4

I figured it out! The kids created a sprite that “covered” the entire area (400x400) even though we couldn’t “see” it.
So I broke the border into 4 sprites. For the left edge I made a sprite that is a Iine 5px wide x 400 px long then resized/cropped the sprite’s dimensions to be 5x400. The code “If character is touching edge then character bounce off edge” now works.
They’ll have to create top, bottom, and right edges to finish the border.


#5

What a creative solution!