Making a simple animation

In this demo, we will animate a vibrating membrane that follows a parabolic trajectory.

First we need to make a Game instance:

G = SpriteKit.Game.instance('Title','Flying Membrane');

Then we can initialize the Sprite. We will make use of the 24 previously saved PNG files in demo/img that have the filename format of membrane#.png.

s = SpriteKit.Sprite('membrane');
for k=1:24
    spritename = sprintf('membrane%d',k);
    pngFile = ['demo/img/' spritename '.png'];

Add a little physics for the parabolic path:

p0 = [10 10];
v0 = [2.75 7];
a = [0 -0.077];
t = (1:180)';
P = t.^2*a/2 + t*v0 + repmat(p0,size(t));

Now set some initial properties:

s.Location = p0;
s.State = 'membrane1';
s.Scale = 0.5;
iter = 1;

Setup a subfunction to be called on each tic/toc of gameplay

function action
     % increase the scaling
     s.Scale = s.Scale+0.01;
     % cycle next state
     % update position and angle
     s.Location = P(iter,:);  % use dot assignment...
     set(s,'Angle',iter)      % or "set"
     if iter==180 % stop processing
     iter = iter+1;

And that's it! Simply run the animation with the play function:;

Note that the above GIF may appear "choppy" compared to the actual MATLAB output.