对于SKAction.WaitForDuration,Xamarin / C ++中的完成处理程序是什么样的?

时间:2015-03-23 23:01:20

标签: c++ xamarin sprite-kit

我正在尝试在我的Xamarin SpriteKit游戏中实现Wait函数。我想让玩家在等待之前做一个胜利动画,然后加载下一级游戏。到目前为止,Wait的实现没有任何影响。

起初我只是调用了播放器动画,然后是等待动作,然后构建了新级别,但是Wait没有工作:

SKAction Waiting = SKAction.WaitforDuration (2);
SKAction Victory;
var textures = Enumerable.Range (1,20).Select (
(i) => SKTexture.FromImageNamed (String.Format (player_victory_{0}", i))).ToArray ();
Victory = SKAction.RepeatAction (SKAction.AnimateWithTextures (textures, 0.04),1);
SelectedNode.RunAction (Victory);
SelectedNode.RunAction (Waiting);
BuildStage (Stage); //load new level

然后我尝试将等待堆叠成一个序列(再次,它不会等待):

SKAction Waiting = SKAction.WaitforDuration (2);
SKAction Victory;
int Stage;

var textures = Enumerable.Range (1,20).Select (
(i) => SKTexture.FromImageNamed (String.Format (player_victory_{0}", i))).ToArray ();

Victory = SKAction.RepeatAction (SKAction.AnimateWithTextures (textures, 0.04),1);

Sequence = SKAction.Sequence (new SKAction [] {Victory,Waiting});

public void CheckGoal (SKSpriteNote SelectedNode)
{
//extra code that confirms Goal
SelectedNode.RunAction (Sequence);
Stage = Stage + 1;
RemoveAllChildren();
BuildStage (Stage);

我读到这只是因为代码是顺序的,它并不意味着它会等到上一次调用完成,我需要一个完成处理程序。

我发现了这个similar question/answer on SO for Swift,但是我不够精通将其转换为Xamarin / C ++解决方案。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

我对原来的问题没有答案,但我现在有一项工作,现在正在做这项工作。我仍然热衷于学习SKAction完成代码,但现在必须这样做。

using System.Threading.Tasks

public void CheckGoal (SKSpriteNote SelectedNode)
{
//extra code that confirms Goal
SelectedNode.RunAction (Victory); //animation plays for .8 seconds
await Task.Delay (1500); //waits here for 1.5 seconds, allowing animation to play plus some buffer time
Stage = Stage + 1;
RemoveAllChildren();
BuildStage (Stage);
}

答案 1 :(得分:0)

不熟悉您正在使用的Xamarin或C ++语法,但这应该让您接近。你对序列非常接近,但是你需要在序列结束时构建你想要它做的事情。 runBlock应该为你做的伎俩。

SKAction customBlock = SKAction.runBlock({
            Stage = Stage + 1
            RemoveAllChildren()
            BuildStage (Stage)
        })

Sequence = SKAction.Sequence (new SKAction [] {Victory,Waiting, customBlock});

public void CheckGoal (SKSpriteNote SelectedNode)
{
    //extra code that confirms Goal
    SelectedNode.RunAction (Sequence);

}

希望这有意义且有用。