Sketch3 and PaintCode: making a drawing move
I wanted a train to appear when someone pulled to refresh my app. Wormy the bookworm would ride on top, bouncing as the wheels turned. Timothy the train would keep moving while the app waited. No connection to the popular train series.
I already drew in Sketch. Learning PaintCode gave me a way to connect those drawings to variables and control their movement in code. This is the process I used, from the first background to the finished animation.
This walkthrough records a 2014 workflow with Sketch3, PaintCode, Storyboard, and the Swift/Objective-C APIs of that period. The original screenshots and animation are preserved; it is not a tested recipe for current tool versions.
Draw the parts that need to move
I began with hills, clouds, dirt, and a track. The background is 600 pixels wide. The visible scene is 400 pixels wide, leaving 200 pixels of extra artwork to scroll through as Timothy moves.
Then I drew the train. The bar connecting the three wheels is a group of shapes, separate from the wheels themselves. That separation matters later: the wheels rotate, while the bar’s position follows their rotation.
I took Wormy from an earlier drawing. He needs his own layer so that I can move him up and down independently of the train.
The target scene is 400 by 100 pixels, a 4:1 aspect ratio, sized with the iPhone 6 and 6 Plus in mind. In the app, I pin the view’s leading and trailing edges with constraints and preserve that ratio as the width changes.
The pull-to-refresh interaction came from this tutorial. Here I’m concentrating on producing the animation that it would display.
Move the artwork into PaintCode
I exported each asset from Sketch3 as SVG using the 4× export setting in this project. SVG keeps the vector shapes available for the next stage.
Import those SVG files into PaintCode. In this workflow, the groups and layers from Sketch3 carry across, so the parts can be connected to separate variables.
I went back to Sketch several times to adjust the spacing of the track, hills, and clouds. A scene that looks right when still can reveal awkward gaps once it moves. Work out which parts need to move before wiring up the animation. A simple loop may not need a background at all, and a complicated scene produces more generated Swift or Objective-C code to manage.
Drive the scene from one distance value
These are the variables in my PaintCode project:
The main value represents the distance traveled. Move the background through its extra 200 pixels, then reset the distance to zero and repeat. The artwork at the end of that travel must line up with the starting view for the reset to look continuous.
Each wheel consists of a blue back, sixteen spokes, and a cap. I grouped these as a Sketch3 Symbol so edits could be applied consistently. Their rotation is derived from the same travel value as the background.
The original setup maps the wheelAngle value through 360*wheelAngle/400. A value of 400 therefore corresponds to 360 degrees, one full turn. The intended timing is one complete rotation during the 200-pixel background cycle. Keep the travel distance and the rotation parameter distinct when connecting them; they use different ranges.
The wheel bar’s horizontal position follows the cosine of the wheel’s rotational value, and its vertical position follows the sine. Together, those two coordinates make the bar follow the wheel’s circular motion.
I also connect Wormy’s vertical position to the animation so he bounces as the train runs.
This is where the drawing starts to feel like one scene. The background, wheels, bar, and passenger each move differently, but they share a timing source. I can change the relationships without redrawing every frame.
Export the drawing function
Once the movement works in PaintCode, export the project as Swift or Objective-C. The generated file contains the drawing functions for the scene. Input variables defined in PaintCode become parameters to those functions.
For this demonstration, I render a sequence of images and display them as an animated image. In Storyboard, create a UIImageView, expose an @IBOutlet named imv of type UIImageView, and connect it to the view.
Use a loop to render successive frames. In the original implementation, an NSMutableArray holds the output of StyleKitName.imageOfTimothyTrain(). Each iteration supplies the drawing values for that point in the animation. Then create the animated UIImage from the frames and assign it to imv.image.
The screenshot below preserves the original implementation. Its syntax belongs to the Swift version used for this project.
Build, run, and watch the loop
This is the result of the original build:
When checking a loop like this, watch the reset as closely as the movement. The background should join up, the wheels and bar should stay together, and the passenger should return to the starting position. Those constraints give the animation its continuity. Within them, there is plenty to play with: the pace of the train, the bounce of the passenger, or how much scenery the little journey needs.











