Monday, April 11, 2022

Nested sprites in Snap!

There is a Swimmer in Snap Examples which features 13 sprites attached to each other but I wanted a simpler example to teach to new Snap learners.

Read page 10 of the Snap! Manual for an overview of Sprite Nesting: Anchor and Parts:
Sometimes it’s desirable to make a sort of “super-sprite” composed of pieces that can move together but can also be separately articulated

I asked in the Snap Forum and cymplecy made a few suggestions: a car spinning its wheels, a Ferris wheel or a face blinking its eyes or moving its mouth.

CAR SPINNING ITS WHEELS

car_spin_wheels

Cymplecy observed that it's easier to do this in Snap! than Scratch.

Set the car pivot point half way between the 2 wheels and horizontal with the centres of the wheels. Otherwise, the wheels will spin out when you bounce off the wall.

I made the wheel by duplicating the car and rubbing out everything except one wheel. Set the pivot point of the wheels in the centre of the wheel, of course.

I reset the spin direction of the wheels to correlate with the car direction. It also works fine if you change the size of the car.

FERRIS WHEEL

ferris_wheel

If teaching this to beginners I'd give them the wheel and carriage to start with and teach the sprite nesting technique. The parts have a synchronous / dangling flag. The dangling option works well here, as the wheel rotates.

No comments: