码迷,mamicode.com
首页 > 其他好文 > 详细

Libgdx1.5.1关于Action改动后的使用方式

时间:2014-12-31 21:37:57      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

API Change: Added concept of target actor, separate from the actor the action is added to. This allows an action to be added to one actor but affect another. This is useful to create a sequence of actions that affect many different actors. Previously this would require adding actions to each actor and using delays to get them to play in the correct order.

官方修改注释:

    添加目标演员的概念,和action附属的演员区分开来。这允许一个动作被添加到一个演员而影响另一个。对于创建一个序列的动作许多不同的演员十分有益。之前实现一系列的动作,需要把动作加到各个演员身上,并且使用延迟来保证他们按照顺序执行。

旧机制:

    private void testOldActions() {

        // 图片6移动到400,400,闪动3下,接着图片7移动到600,200

        Image image6 = CHGame.getInstance().getImage(String.format("xinxin/x%d.png", 6));

        final Image image7 = CHGame.getInstance().getImage(String.format("xinxin/x%d.png", 7));

        final Action action71 = Actions.moveTo(600, 200, 2f);

        // 移动动画

        Action action61 = Actions.moveTo(400, 400, 2f);

        Action action62 = Actions.repeat(3, Actions.sequence(Actions.alpha(0.2f, 0.3f), Actions.alpha(1f, 0.3f)));

        SequenceAction sequenceAction = new SequenceAction(action61, action62, Actions.run(new Runnable() {

            

            @Override

            public void run() {

               image7.addAction(action71);

            }

        }));

        image6.addAction(sequenceAction);


        addActor(image6);

        addActor(image7);

    }




在新的机制下:

private void testNewActions() {

        // 图片6移动到400,400,闪动3下,接着图片7移动到600,200

        Image image6 = CHGame.getInstance().getImage(String.format("xinxin/x%d.png", 6));

        Image image7 = CHGame.getInstance().getImage(String.format("xinxin/x%d.png", 7));

        Action action71 = Actions.moveTo(600, 200, 2f);

        // 移动动画

        Action action61 = Actions.moveTo(400, 400, 2f);

        Action action62 = Actions.repeat(3, Actions.sequence(Actions.alpha(0.2f, 0.3f), Actions.alpha(1f, 0.3f)));

        SequenceAction sequenceAction = new SequenceAction(action61, action62, Actions.addAction(action71, image7));

        image6.addAction(sequenceAction);


        addActor(image6);

        addActor(image7);

    }


    对比发现,对于按照顺序对不同actor执行动作时,现在的机制更加方便了,省去了RunnableAction。

    例如:

初始启动的Actor->action...

Actor1->action1....              合并为 AddAction add1= Actions.addAction(action1, Actor1)  

Actor2->action2....              合并为 AddAction add2= Actions.addAction(action2Actor2)  

Actor3->action3....              合并为 AddAction add3= Actions.addAction(action3Actor3)  

.....

可实现为:

Actor->Actions.addAction(action,add1,add2,add3,.....)

效果就是,actor动作执行完,执行actor1的动作,然后是actor2的动作,以此类推........





Libgdx1.5.1关于Action改动后的使用方式

标签:

原文地址:http://my.oschina.net/oahcfly/blog/362807

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!