Flip layer

18 views
Skip to first unread message

Pongpipat Supalak

unread,
Apr 14, 2015, 1:53:03 PM4/14/15
to pl...@googlegroups.com
How to flip layer.
Give me for example code please.

Michael Bayne

unread,
Apr 14, 2015, 4:43:58 PM4/14/15
to pl...@googlegroups.com
On Tue, Apr 14, 2015 at 8:35 AM, Pongpipat Supalak <k.blu...@gmail.com> wrote:
How to flip layer.
Give me for example code please.

If by that you mean animate a layer flipping over using a 3D rotation, then you need code that looks something like this:


Specifically the flip transition:

    public static class Flip extends Trans {
        public Flip (int duration) { super(duration); }

        @Override protected void init () {
            // TODO: compute the location of the center of the box in screen coordinates, place
            // the eye there in [0, 1] coords
            Graphics gfx = _ocontents.root().iface.plat.graphics();
            Point eye = LayerUtil.layerToScreen(
                _ocontents.layer, _ocontents.size().width()/2, _ocontents.size().height()/2);
            eye.x /= gfx.viewSize.width();
            eye.y /= gfx.viewSize.height();
            _obatch = new RotateYBatch(gfx.gl, eye.x, eye.y, 1);
            _nbatch = new RotateYBatch(gfx.gl, eye.x, eye.y, 1);
            _ocontents.layer.setBatch(_obatch);
            _ncontents.layer.setBatch(_nbatch);
        }
        @Override protected void update (float pct) {
            _obatch.angle = FloatMath.PI * pct;
            _nbatch.angle = -FloatMath.PI * (1-pct);
            _ocontents.layer.setVisible(pct < 0.5f);
            _ncontents.layer.setVisible(pct >= 0.5f);
        }
        @Override protected void cleanup () {
            _ocontents.layer.setBatch(null);
            _ncontents.layer.setBatch(null);
        }

        protected RotateYBatch _obatch, _nbatch;
    }

This is operating on TPUI elements, but those are just a Layer with a bunch of extra bookkeeping. So all of this operates on the underlying layers and should be pretty easy to convert to whatever you're doing.


Reply all
Reply to author
Forward
0 new messages