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

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.sequenceAction(action,add1,add2,add3,.....)

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





转载于:https://my.oschina.net/oahcfly/blog/362807

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值