0
我試圖編寫一個基本的因果遊戲。到目前爲止,我已經設法在屏幕上顯示火箭的圖像(隨機在x軸上顯示),以及何時觸摸啓動。該程序工作正常,但我希望火箭重新出現(循環10次),任何人都可以給我一些指導我如何才能做到這一點。如何在遊戲中添加循環
我重視從下面我scene.m代碼...
#import "MyScene.h"
@implementation MyScene
@import AVFoundation;
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
self.backgroundColor = [SKColor whiteColor];
SKSpriteNode *rocket1 = [SKSpriteNode spriteNodeWithImageNamed:@"rocket.png"];
CGRect rocket1frame = CGRectMake(100, 100, 100, 100);
[rocket1 setSize:rocket1frame.size];
rocket1.position = CGPointMake(CGRectGetMidX(self.frame), 100);
[self addChild:rocket1];
_ship = rocket1;
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint currentLocation = [[touches anyObject] locationInNode:self];
CGPoint previousLocation = [[touches anyObject] previousLocationInNode:self];
CGRect shipRect = _ship.frame;
if (CGRectContainsPoint(shipRect, previousLocation))
{
CGPoint lvPosition = CGPointMake(_ship.position.x - (previousLocation.x - currentLocation.x), _ship.position.y);
_ship.position = lvPosition;
SKAction *sound = [SKAction playSoundFileNamed:@"slideup.mp3" waitForCompletion:NO];
SKAction *moveNode = [SKAction moveByX:lvPosition.x y:3000.0 duration:3.0];
[_ship runAction: sound];
[_ship runAction: moveNode];
}
}
@end;
你想它老火箭重新出現後出現,移動然後消失? – hasan83
我的代碼中沒有看到隨機數 – hasan83
是的,我希望在舊火箭發射並從屏幕消失後出現新的火箭。 –