第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 cachedActions Libgdx 繼續(xù)序列/并行操作

如何從 cachedActions Libgdx 繼續(xù)序列/并行操作

函數(shù)式編程 2022-12-28 11:08:01
我有一個 clicklistener 擴(kuò)展類,旨在緩存 actor 在 touchDown 期間的任何當(dāng)前動作,并在觸發(fā) touchUp 時將其分配回去。但是,它不適用于序列或并行操作。public class MyClickListener extends ClickListener {    public Actor actor;    private final Array<Action> cachedActions = new Array<Action>();    @Override    public void touchUp(InputEvent event, float x, float y, int pointer, int button) {        super.touchUp(event, x, y, pointer, button);        actor = event.getListenerActor();        actor.addAction(btnScaleBackActions());        for(Action action:cachedActions)        {            //action.reset(); // i wants the actor to continue at where it stop            action.setTarget(actor);            action.setActor(actor);            actor.addAction(action);        }        cachedActions.clear();    }    @Override    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {        if(pointer==0)        {            actor = event.getListenerActor();            actor.setScale(0.9f);            cachedActions.addAll(actor.getActions());            actor.clearActions();            return super.touchDown(event, x, y, pointer, button);        }        else        {            return false;        }    }我的按鈕測試:// button touchUp continue its previous action at where it stopbtn1.addAction(Actions.scaleBy(1,1,3));// button touchUp not continue it previous actions and complete stopbtn2.addAction(sequence(Actions.scaleBy(1,1,3))); // button touchUp give nullException errorbtn3.addAction(forever(Actions.scaleBy(1,1,3)));//error :Exception in thread "LWJGL Application" java.lang.NullPointerException        at com.badlogic.gdx.scenes.scene2d.actions.RepeatAction.delegate(RepeatAction.java:29)        at com.badlogic.gdx.scenes.scene2d.actions.DelegateAction.act(DelegateAction.java:43)是否可以在 myClickListener 類停止的地方繼續(xù)序列/并行操作?
查看完整描述

2 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗 獲得超11個贊

這是另一個想法。您可以將您的操作包裝在一種新型的可暫停操作中,而不是處理刪除和恢復(fù)操作以及隨后處理池問題。


public class PausableAction extends DelegateAction {


    public static PausableAction pausable(Action wrappedAction){

        PausableAction action = Actions.action(PausableAction.class);

        action.setAction(wrappedAction);

        return action;

    }


    boolean paused = false;


    public void pause (){

        paused = true;

    }


    public void unpause (){

        paused = false;

    }


    protected boolean delegate (float delta){

        if (paused)

            return false;

        return action.act(delta);

    }


    public void restart () {

        super.restart();

        paused = false;

    }

}

現(xiàn)在,在獲取您的操作時,將它們包裝在一個可暫停的對象中,例如:


btn1.addAction(PausableAction.pausable(Actions.scaleBy(1,1,3)));

并在需要時暫停/取消暫停操作,例如:


//...

actor = event.getListenerActor();

actor.setScale(0.9f);

for (Action action : actor.getActions())

    if (action instanceof PausableAction)

        ((PausableAction)action).pause();

return super.touchDown(event, x, y, pointer, button);


查看完整回答
反對 回復(fù) 2022-12-28
?
三國紛爭

TA貢獻(xiàn)1804條經(jīng)驗 獲得超7個贊

來自池(比如來自 Actions 類)的動作的默認(rèn)行為是當(dāng)它們從 actor 中移除時重新啟動它們自己。重用這些實例實際上并不安全,因為它們也已返回到池中并且可能意外地附加到其他一些參與者。


因此,在將它們從 actor 中移除之前,您需要將它們的池設(shè)置為 null。


private static void clearPools (Array<Action> actions){

    for (Action action : actions){

        action.setPool(null);

        if (action instanceof ParallelAction) //SequenceActions are also ParallelActions

            clearPools(((ParallelAction)action).getActions()); 

        else if (action instanceof DelegateAction)

            ((DelegateAction)action).getAction().setPool(null);

    }

}


//And right before actor.clearActions();

clearPools(actor.getActions());

然后,當(dāng)您將它們添加回 actor 時,您需要將它們的池添加回來,以便它們可以返回到 Actions 池并在以后重用以避免 GC 攪動。


private static void assignPools (Array<Action> actions){

    for (Action action : actions){

        action.setPool(Pools.get(action.getClass()));

        if (action instanceof ParallelAction)

            assignPools(((ParallelAction)action).getActions()); 

        else if (action instanceof DelegateAction){

            Action innerAction = ((DelegateAction)action).getAction();

            innerAction.setPool(Pools.get(innerAction.getClass()));

        }

    }

}


//And call it on your actor right after adding the actions back:

assignPools(actor.getActions);


查看完整回答
反對 回復(fù) 2022-12-28
  • 2 回答
  • 0 關(guān)注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號