ios - 为什么我的 SpriteNode 没有被添加到场景中?
<p><p>我正在制作一个 SpriteNode 并尝试将其添加到场景中。即使我使用 <code></code>,它也不会出现。我只是看不出我哪里出错了。这是我的 View Controller.m:</p>
<pre><code>- (void)viewDidLoad
{
;
// Pause the view (and thus the game) when the app is interrupted or backgrounded
[ addObserver:self selector:@selector(handleApplicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
[ addObserver:self selector:@selector(handleApplicationDidBecomeActive:)name:UIApplicationDidBecomeActiveNotificationobject:nil];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = ;
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
;
}
</code></pre>
<p>这是我的 Scene.m</p>
<pre><code>- (void)viewWillAppear:(BOOL)animated
{
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
SKTexture *YellowLabelTexture = ;
SKTexture *BlueLabelTexture = ;
SKTexture *GreenLabelTexture = ;
SKTexture *RedLabelTexture = ;
SKTexture *WhiteLabelTexture = ;
NSArray *anim = ;
SKSpriteNode *labelNode = ;
labelNode.position = CGPointMake(160, 400);
SKAction *actionAnimate = ;
SKAction *actionRepeat = ;
;
;
}
</code></pre>
<p>谁能弄清楚是什么导致 Sprite 没有被添加到场景中。另外,如何将其添加到场景中?谢谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>正如@akashg 所说,你不能使用 <code>viewWillAppear</code> 方法,而且你应该使用 runAction 作为 labelNode:</p>
<p><code>;</code> 到 <code>;</code></p>
<p>你的代码应该是这样的:</p>
<pre><code>-(id)initWithSize:(CGSize)size {
if (self = ) {
/* Setup your scene here */
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
SKTexture *YellowLabelTexture = ;
SKTexture *BlueLabelTexture = ;
SKTexture *GreenLabelTexture = ;
SKTexture *RedLabelTexture = ;
SKTexture *WhiteLabelTexture = ;
NSArray *anim = ;
SKSpriteNode *labelNode = ;
labelNode.position = CGPointMake(160, 400);
SKAction *actionAnimate = ;
SKAction *actionRepeat = ;
;
;
}
return self;
}
@end
</code></pre></p>
<p style="font-size: 20px;">关于ios - 为什么我的 SpriteNode 没有被添加到场景中?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24924233/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24924233/
</a>
</p>
页:
[1]