Skip to the game
ArrowsGame
EN

Guide

How our arrow puzzle stays smooth in a browser

On this page
  1. What smooth means, measured
  2. The flat board: SVG, one unit per cell
  3. The cube: plain WebGL, one image for everything
  4. Drawing only when something moves
  5. Arrows that slide along their own bodies
  6. A few kilobytes, all our own
  7. The same rules as the apps, checked on every board
  8. Big boards on small screens
  9. If it ever stutters
  10. Questions and answers

On the busiest board in our arrows game, level 701 with 203 arrows, one frame of animation costs our code about 0.2 milliseconds of work on an emulated phone, and 0.4 ms on the slowest frames. At 60 frames a second the browser has about 16.7 ms per frame for everything, so our share is a small fraction of it. The cube's busiest board takes 0.4 ms on average. Those numbers come from our automated browser test, which plays both games on an emulated phone and laptop. This guide explains the choices behind them: what the game draws with, when it draws, how little it downloads, and how we check that the browser version plays exactly like the apps it came from. Every number here was measured on the files this site serves.

The short version

The flat board is drawn as SVG, the cube with plain WebGL and no 3D library. Both redraw only while something moves, so an idle board costs nothing. The whole flat game is about 24.6 KB of compressed code, the cube 28.3 KB, built on no outside libraries, and the rules match the original apps on every board.

#What smooth means, measured

A game feels smooth when every frame arrives on time. Most screens refresh 60 times a second, some 90 or 120 (the refresh rate), and the browser asks the page for a new picture just before each refresh through requestAnimationFrame. If the page's work, plus the browser's own work to lay out and paint, does not fit in the time between two refreshes, a frame is skipped and motion stutters.

So the useful number is not the frame rate on a fast laptop but the cost of one frame on a modest phone. We measure it on the two boards that should be the hardest to draw:

  • Level 701, the flat level with the most arrows (203): 0.2 ms per frame on average, 0.4 ms on the slowest 5% of frames.
  • Cube level 901, one of the largest cube boards (119 arrows on a 10 × 10 × 10 cube): 0.4 ms on average, 1.3 ms on the slowest 5%.

Both ran at about 55 to 60 frames a second in the test, which runs headless Chrome emulating a phone screen of 390 × 844 with a screen density of three.

Level 701, 37 × 44 board, 203 arrows
Figure 1Level 701, the flat board with the most arrows (203): about 0.2 ms of our code per animation frame in our phone test. Play level 701
Try it: level 701203 arrows · 4 free at the start

#The flat board: SVG, one unit per cell

The flat board is SVG, the vector format browsers draw natively. One unit in the drawing is one cell of the board, so a 37 × 44 board is a 37 × 44 drawing, scaled to whatever space the screen has. Because vector graphics are redrawn from shapes rather than stretched from pixels, the arrows stay sharp at any zoom, on any screen density.

Each arrow is a small group of shapes: a body line and a triangle for the point, plus a badge for a special piece. When an arrow leaves, only that group changes. The browser's own drawing engine does the rest, and it is very good at redrawing a handful of shapes. The same drawing also serves taps: the game works out which cell you touched and which arrow owns it, and a forgiving rule passes a tap near a shared edge to a free neighbour.

#The cube: plain WebGL, one image for everything

The cube is drawn with WebGL, the 3D drawing layer every current browser supports, but without a 3D library on top. The whole cube view is one shader program and one texture atlas: a single image, drawn once at start with ordinary 2D canvas commands, that holds every dot, ring and badge the cube needs. Everything on screen is triangles cut from that one image.

The faces, grid dots, gates and resting arrows sit in a static buffer that is rebuilt only when the board changes. Arrows that are moving or pulsing go in a small second buffer that is rebuilt each frame. That split is why a 119-arrow cube costs well under a millisecond a frame: each frame only touches the few arrows in motion.

Skipping the library also keeps the download small. The cube's view code is 12.0 KB compressed, and it is only fetched when a page actually shows a cube; a page without a cube never loads it.

Cube level 901, 10 × 10 × 10 cube, 119 arrows
Figure 2Cube level 901: 119 arrows on a 10 × 10 × 10 cube, about 0.4 ms of our code per frame in the same test. Play level 901

#Drawing only when something moves

Many games redraw continuously, 60 times a second, whether anything changes or not. Ours does the opposite: both engines draw a frame only when there is something to show, such as an arrow sliding out, a bump, a turn of the cube or a zoom. When the animation ends, the frame loop stops.

Here is what happens on a tap:

  1. The game finds the arrow under your finger (on the cube, by casting a ray against the box, so a hidden face is never hit).
  2. The rules decide in an instant whether the arrow's line to the edge is clear.
  3. If it is, an animation starts: the arrow slides out along its own body, frame by frame.
  4. When the last arrow cell has left, the loop stops and the screen stays still until your next touch.

An idle board therefore costs no drawing work at all, which matters on a phone battery. When the tab is hidden, the game also pauses its timer, so time spent in another tab never counts against you.

#Arrows that slide along their own bodies

An arrow does not jump off the board; it slides out along the path of its own body, the way a train follows its track. Both engines share a small piece of code that does this: it treats the arrow as a sliding window moving along a line of points and draws only the part of the line inside the window. A 47-cell arrow, the longest in the game (level 857), slides out the same way as a 2-cell one, with no extra cost per cell beyond the shape itself.

The same idea gives the bump its feel: the arrow nudges forward towards whatever blocks it, turns red and settles back. On the cube the window follows the arrow over the edges between faces, so a body folded round a corner slides round it. Easing curves (slow start, quick finish) make the motion read as physical without making it slow.

#A few kilobytes, all our own

Smoothness starts before the first frame: a game that takes seconds to arrive never feels quick. Our engines use no framework and no outside libraries; the only files they fetch are their own. (The site also sends small anonymous usage events to our own analytics endpoint, listed on the privacy page.) The table shows the compressed sizes (gzip, measured from the files this site serves).

What the game downloads
WhatCompressed size
Flat game code24.6 KB
Cube game code28.3 KB (of which the 3D view: 12.0 KB, loaded only with a cube)
Styles2.9 KB
One pack of 50 flat levels11.1 KB to 13.4 KB
One pack of 50 cube levels4.7 KB to 20.8 KB

Levels come in packs of 50, so opening level 287 fetches one small file, and the next levels are fetched quietly in the background as you play on. A page that shows no board loads none of this code, and the cube's 3D view is only fetched when a cube is on the page.

#The same rules as the apps, checked on every board

The two engines are ports of our own apps, Right Away (the flat game) and Right Away Cube, rewritten from scratch in plain JavaScript so they run in a browser without the app's game engine. A port is only worth having if it plays exactly like the original, so the rules were translated line for line and then checked against the original code on every board.

The engine test re-solves every one of the 1,000 flat levels and 2,000 cube levels, plus every daily board, and compares each verdict and move count with the original game's rules; it also replays the original's own rule tests tap by tap, piece by piece. Nothing differs. That is why the numbers in our guides, such as the 16-layer one-move stretch on level 287 or the single opening arrow on level 450, hold in the browser exactly as they do in the apps.

It also means every special piece behaves the same here: rotators on level 16, bombs on level 28, keys on level 40 and the rest, all explained in our guide to the special pieces. The ways players lose lives are the same too, which the mistakes that cost lives covers, and the method in our guide to hard levels works unchanged. Our guide to move order explains why the solver can check thousands of boards so quickly: any free arrow is a safe move, so it never has to search.

#Big boards on small screens

Big boards on small screens are the other half of smooth. The flat game first shows the whole board, then, when cells would be too small to tap comfortably, it eases in so that cells are a finger's width. Pinch to zoom, drag to pan once zoomed, or use a trackpad. A plain mouse wheel scrolls the page unless the board is zoomed in, so the board never traps your scroll.

The cube keeps its picture sharp on high-density screens but caps the drawing resolution at twice the CSS size, which keeps the per-frame work bounded on phones with very dense screens. Turning the cube has a little inertia, and the pitch stops before the cube flips over, so it is hard to lose your bearings.

Both games are tested on a phone layout (390 × 844 with touch) and a laptop layout (1366 × 768 with a mouse): the test plays a level to the end by tapping where each arrow is, checks that a bump costs one life once, that hints and undo work, and that a board survives a reload.

#If it ever stutters

On a current phone or computer the game should run smoothly as it is. If it ever stutters, these steps fix most cases:

  1. Close other heavy tabs, especially video, which compete for the same graphics time.
  2. Update your browser; older versions can be slower at drawing SVG and WebGL.
  3. For the cube, check that hardware acceleration is on in your browser's settings; WebGL needs it to be fast.
  4. Turn off battery-saver modes while playing a big board; some cap the frame rate.
  5. Zoom in on very large flat boards so that fewer, larger cells are on screen.

None of these changes the puzzle: the level, your progress and the rules are the same however fast your device is. To get started, today's puzzle is on the home page, the flat game's endless list is in unlimited mode, and the cube is on the arrow cube page.

#Questions and answers

Why does the arrows game run so smoothly in a browser?

It draws the flat board as SVG and the cube with plain WebGL, redraws only while something moves, and downloads only about 24.6 KB of compressed code for the flat game. On the busiest board, a frame costs our code about 0.2 ms.

Does the arrow cube need a powerful computer?

No. It needs a browser with WebGL, which every current browser has. Its busiest boards cost under a millisecond of our code per frame on an emulated phone.

Does the game use battery when I am not playing?

Very little. Both games stop drawing as soon as nothing moves, and the timer pauses when the tab is hidden.

Play the game

A new daily board every day, over 1,000 levels and the 3D arrow cube, free in your browser.

#Sources

  1. Window: requestAnimationFrame() method (MDN Web Docs)
  2. Texture atlas (Wikipedia)
  3. WebGL (Wikipedia)
  4. Refresh rate (Wikipedia)