ICSOC-8.11.5.1 Collision Sensing: Bounding Geometry, Pixel Precision, and Interaction Detection
Collision detection in Scratch provides the real-time spatial awareness required for interactive physics, boundary enforcement, and object interactions. The primary conditional reporter is the hexagonal boolean block “touching [mouse-pointer / edge / sprite]?”, located in the Sensing category. Unlike basic rectangular bounding-box collision algorithms used in early game engines, Scratch’s virtual machine utilizes exact non-transparent pixel-mask intersection testing. When checking collision against another sprite or the edge of the stage, the engine samples whether any non-transparent pixel (alpha > 0) of the calling sprite physically overlaps a non-transparent pixel of the target entity during the current rendering frame.
The dropdown selector permits dynamic targeting of the current mouse-pointer coordinates, the four rigid stage boundaries (“edge”), or any discrete sprite currently loaded in the project hierarchy (including clones of that sprite). Because collision evaluation occurs synchronously within the Scratch execution loop (running at 30 frames per second), high-speed projectile sprites can occasionally pass through thin target boundaries without triggering collision—a computational phenomenon known as “tunneling.” To prevent tunneling in fast-paced games, developers combine collision sensing with fractional step loops or raymarching algorithms, ensuring pixel-perfect contact registration before the frame completes.
ICSOC-8.11.5.2 Color-Based Collision: Hexadecimal Sampling, Multi-Layer Masks, and Hitboxes
Scratch offers sophisticated chromatic interaction detection through two distinct hexagonal boolean blocks: “touching color [ ]?” and “color [ ] is touching [ ]?”. The single-color block “touching color [ ]?” evaluates whether any non-transparent pixel of the calling sprite makes direct contact with a specific target color present on the stage backdrop, video feed, or any other visible sprite. Scratch represents colors internally using standard 24-bit RGB / HSV values. When a sprite traverses a complex terrain map or maze, this block acts as a versatile sensor for pathfinding, obstacle navigation, and boundary containment.
The more advanced dual-color block, “color [C1] is touching [C2]?”, introduces targeted sub-sprite hitbox sensing. It triggers only when a specific color cluster (C1) belonging to the calling sprite physically touches another designated color (C2) on another sprite or background. This allows programmers to engineer discrete segmented hitboxes—such as a red foot sensor detecting green ground tiles for platformer gravity, or a blue head sensor registering yellow ceiling hazards—without creating separate child sprites. However, color sensing operations are computationally expensive for the rendering engine because each frame requires pixel-by-pixel color buffer scanning, which can induce noticeable frame-rate drops when overused in tightly nested loops.
ICSOC-8.11.5.3 Euclidean Distance Calculations: Pythagorean Proximity and Dynamic Vector Tracking
Proximity detection and radial tracking in Scratch are governed by the rounded reporter block “distance to [mouse-pointer / sprite]”. Rather than relying on simple bounding boxes, this block computes the continuous, scalar Euclidean distance between the calling sprite’s rotation center (defined by its costume canvas origin) and the target entity’s center point. Under the hood, the Scratch virtual machine evaluates the classical Pythagorean distance formula: sqrt((x2 – x1)^2 + (y2 – y1)^2), where (x1, y1) and (x2, y2) represent the Cartesian coordinates of the respective sprites on the 480×360 stage coordinate grid.
Because the output is a continuous floating-point numeric reporter, it serves as a foundational building block for game mechanics such as artificial intelligence proximity aggro radii, dynamic audio volume modulation, radar sweeping, and gravity simulation. When combined with mathematical comparison operators (such as “< distance to [sprite] < 50"), it enables circular trigger zones that are significantly more realistic than axis-aligned bounding boxes. Note that the distance block measures strictly between costume origin centers; an incorrectly centered costume canvas will distort distance calculations, causing radial triggers to fire offset from visual boundaries.
ICSOC-8.11.5.4 Interactive Text Input: Synchronous Prompt Execution and Global Answer Registers
Two-way textual communication between the user and a Scratch application is handled by the synchronous stack block “ask [text] and wait” paired with the system reporter block “answer”. When the “ask and wait” block executes, it immediately renders an interactive input dialog bar at the bottom of the stage and speech-bubbles the prompt string from the calling sprite (or a standalone prompt bar if executed by the Stage). Critically, this block enforces thread synchronization: it suspends the execution of the calling script stack until the user submits text by pressing the Enter key or clicking the blue checkmark icon.
Upon submission, the user’s raw input string is stored into the built-in system variable reporter “answer”. This “answer” reporter functions as a single global register shared across the entire project; it is not local to the sprite that issued the prompt. Consequently, if multiple sprites issue “ask and wait” prompts concurrently, or if a new prompt executes before the prior answer is processed, the contents of “answer” are overwritten immediately. To safeguard input data in multi-step quizzes or complex data entry systems, developers must immediately transfer the value of “answer” into designated user-defined local or global variables before triggering subsequent prompts.
ICSOC-8.11.5.5 Hardware State Polling: Asynchronous Event Listeners vs. Continuous Frame Sampling
Scratch provides robust hardware input interrogation through two contrasting architectural paradigms: event-driven interrupt handling and continuous state polling. In the Sensing category, the boolean blocks “key [space v] pressed?” and “mouse down?”, alongside coordinate reporters “mouse x” and “mouse y”, represent continuous hardware polling functions. Unlike the event hat block “when [key v] pressed”, which relies on operating system key-repeat intervals and suffers from an inherent delay before rapid-fire repeats, polling “key [pressed]?” inside a high-frequency [forever] loop queries the keyboard buffer every virtual machine frame tick (~33 ms). This enables fluid, zero-latency multi-directional movement in arcade and platformer games.
Continuous input polling also facilitates simultaneous multi-key combinations—such as pressing both the Up Arrow and Right Arrow keys to achieve diagonal velocity—which event hat blocks cannot reliably orchestrate. Similarly, the “mouse down?” boolean reports whether the primary mouse button (or touchscreen contact) is currently depressed, while “mouse x” and “mouse y” stream continuous real-time pointer coordinates mapped precisely to the -240 to +240 horizontal and -180 to +180 vertical Cartesian grid. This enables developers to create dynamic custom crosshairs, drag-and-drop physics, and mouse-follow orientation vectors.
ICSOC-8.11.5.6 Internal Precision Clocks: Microsecond Accumulators and Deterministic Game Loops
Temporal regulation in Scratch is anchored by the built-in precision clock system accessible via the rounded reporter “timer” and the stack block “reset timer”. The timer functions as an autonomous, high-precision stop-watch managed by the Scratch virtual machine, measuring elapsed real time in decimal seconds with millisecond precision (three decimal places). The timer begins counting upward from zero the exact instant the Scratch project is initialized or loaded, and continues accumulating time independently of script execution, sprite switching, or frame-rate slowdowns.
Executing the “reset timer” stack block sets the internal timer accumulator back to 0.000 seconds instantly across the entire project. Because the timer is an immutable global system resource, resetting it affects any other sprite or script referencing the “timer” reporter. For this reason, professional developers avoid resetting the master timer repeatedly during complex games; instead, they capture baseline timestamps into local variables (e.g., [set [start_time] to (timer)]) and calculate delta intervals (timer – start_time) to manage individual cooldowns, animations, and speedrun records without introducing cross-script temporal interference.