Hey Mark.
In my sample code above, the speed of the rotation is controlled by the variable angle. To speed things up, you could simply increment it in bigger steps than just by one each frame. If the rotation looks jerky, try a release instead of a debug build.
Well, I was a little bored so here’s a more sophisticated example - including different images for both sides of the card.
package;
import openfl.display.Sprite;
import openfl.display.BitmapData;
import openfl.display.Bitmap;
import openfl.display.Graphics;
import openfl.display.TriangleCulling;
import openfl.geom.*;
import openfl.Vector;
import openfl.events.Event;
import openfl.Assets;
import openfl.display.FPS;
import motion.*;
import motion.easing.*;
class Main extends Sprite
{
private var mat:Matrix3D = new Matrix3D();
private var vertices:Vector<Float>=Vector.ofArray([-20, -20, 0, 20, -20, 0, 20, 20, 0, -20, 20, 0.0]);
private var uvt:Vector<Float>=Vector.ofArray([0.0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0]);
private var indices:Vector<Int>=Vector.ofArray([0, 1, 3, 1, 2, 3]);
private var projectedPoints:Vector<Float>;
private var plane:Sprite = new Sprite();
private var pProjection:PerspectiveProjection = new PerspectiveProjection();
private var proj:Matrix3D;
private var textureA:BitmapData;
private var textureB:BitmapData;
private var angle:Int = 0;
public function new()
{
super();
projectedPoints = new Vector<Float>(Math.ceil(vertices.length / 3 * 2));
addChild(plane);
plane.x = stage.stageWidth / 2;
plane.y = stage.stageHeight / 2;
pProjection.fieldOfView = 45;
proj = pProjection.toMatrix3D();
textureA = Assets.getBitmapData("img/imgA.jpg");
textureB = Assets.getBitmapData("img/imgB.jpg");
var fps:FPS = new FPS(10,10,0xff0000);
addChild(fps );
flip(3);
}
private function flip(state:Int):Void
{
switch(state)
{
case 0:
Actuate.update (spin, 1, [90, textureB], [180, textureB]).ease(Quad.easeOut).onComplete(flip, [1]);
case 1:
Actuate.update (spin, 1, [180, textureB], [270, textureB]).ease(Quad.easeIn).onComplete(flip, [2]);
case 2:
Actuate.update (spin, 1, [270, textureA], [360, textureA]).ease(Quad.easeOut).onComplete(flip, [3]);
case 3:
Actuate.update (spin, 1, [0, textureA], [90, textureA]).ease(Quad.easeIn).onComplete(flip,[0]);
}
}
private function spin(degrees:Int,texture:BitmapData):Void
{
mat.identity();
mat.appendRotation(degrees, Vector3D.Y_AXIS);
mat.appendTranslation(0, 0, 100);
mat.append(proj);
projectedPoints = new Vector<Float>();
Utils3D.projectVectors(mat, vertices, projectedPoints, uvt);
plane.graphics.clear();
plane.graphics.beginBitmapFill(texture, null, false, false);
plane.graphics.drawTriangles(projectedPoints, indices, uvt, TriangleCulling.NONE);
plane.graphics.endFill();
}
}