一次绘制一个地图图块

时间:2015-12-11 20:11:06

标签: sprite-kit tvos

我正在为tvOS开发基于SpriteKit的游戏。我希望能够看到一次一个地显示地图的地板砖。我无法让它发挥作用。下面是一个展示我的问题的示例类文件。无论我在NSTimer上放了什么延迟,瓷砖都会立刻出现。

我错过了一些直截了当的事情吗?

由于

#import "GameScene.h"

@implementation GameScene
-(void)drawFloorNode:(NSTimer *)timer{
  NSDictionary *thisDict=[timer userInfo];
  int x =[[thisDict objectForKey:@"xval"] intValue];
  int y =[[thisDict objectForKey:@"yval"] intValue];
  SKSpriteNode *myFloor=[[SKSpriteNode alloc]   initWithImageNamed:@"Floor1.png"];
  myFloor.anchorPoint=CGPointMake(0, 0.5);
  myFloor.size=CGSizeMake(64, 64);
  myFloor.position=CGPointMake(x,self.frame.size.height - (y*64) - 128);
  myFloor.zPosition=-1;
  [self addChild:myFloor];
  [timer invalidate];
  timer=nil;
}


-(void)didMoveToView:(SKView *)view {

  SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];

  myLabel.text = @"Hello, World!";
  myLabel.fontSize = 65;
  myLabel.position = CGPointMake(CGRectGetMidX(self.frame),
                               CGRectGetMidY(self.frame));

  [self addChild:myLabel];

  for(int y=0;y<9;y++){
    for(int x=0;x<64*15+1;x+=64){
        NSMutableDictionary *myDict =[[NSMutableDictionary alloc ]init];
        [myDict setObject:[NSNumber numberWithInt:x] forKey:@"xval"];
        [myDict setObject:[NSNumber numberWithInt:y] forKey:@"yval"];
        [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(drawFloorNode:) userInfo:myDict repeats:NO];

    }
}

}

@end

0 个答案:

没有答案