ScratchData LogoScratchData
Back to kriblo_test's profile

Example: Wrapping Asteroid

KRkriblo_test•Created March 19, 2023
Example: Wrapping Asteroid
8
6
67 views
View on Scratch

Instructions

This is a simple example. Not optimized in terms of resources or computing. But it seems to work, and I like "the Scratch Way" ;) Click the green flag to re-randomize direction, or use the Left/Right arrow keys to steer. Hold D while clicking the green flag to activate enhanced demo mode (half-size virtual screen mode, to illustrate how it works). All code by me (@kriblo). The example illustrates how a sprite might me made to wrap the screen, i.e. turn up on the opposite side of the screen it exits. This works by creating eight clones ("shadow clones") of the main sprite, if it touches the edge. Shadow clones are offset one screen width/height in each of the eight directions. This happens in the same frame (or screen update): 1. The main sprite is moved. If the main sprite is completely off screen, it's moved one screen width / height back on screen. 2. Old shadow clones are deleted 3. New shadow clones are created, if the main sprite touches the edge. Clearly, this could be optimized by only creating clones which will be visible. But it will do for this example. I made this after reading this comment in the D&M studio: https://scratch.mit.edu/studios/25643089/comments/#comments-217333812

Project Details

Project ID821968435
CreatedMarch 19, 2023
Last ModifiedMarch 20, 2023
SharedMarch 19, 2023
Visibilityvisible
CommentsAllowed