0

我正在为滚动视图绘制 52 个标签、精灵和按钮。但是,当我滚动时,当我使用滚动视图时,它会非常滞后。我使用类似的设置,在 x 和轴上滚动,没有延迟。我正在 iphone 5 上进行测试,所以我认为它能够非常轻松地处理它。对象需要移动的距离被正确计算并且对象被正确绘制它只是真的滞后。绘制代码:

    int cnt = 40;      
  for (NSString *i in [Trucks GetSetTruckList].TruckList){
    NSMutableArray *Truck = [[NSMutableArray alloc] initWithArray:[TruckDict objectForKey:i]];
     CGSize s = [[CCDirector sharedDirector] winSize];


    CCMenuItemImage *BuyButton = [CCMenuItemImage itemWithNormalImage:@"Buy.jpg" selectedImage:@"Buy.jpg"block:^(id sender) {[self BuyTruck:Truck]; }];
    BuyButton.position = ccp((s.width/2) - 20 , (s.height/2) - cnt  + ShopPointX);
    BuyButton.scale = .5;

    CCLabelTTF *Name = [CCLabelTTF labelWithString:[Truck objectAtIndex:0] fontName:@"Marker Felt" fontSize:19];
    Name.position = ccp(100, (s.height) - cnt + ShopPointX);

    CCLabelTTF *NumPeople = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Ppl: %@" , [Truck objectAtIndex:2]] fontName:@"Marker Felt" fontSize:13];
    NumPeople.position = ccp(200, (s.height) - cnt + ShopPointX);

    CCLabelTTF *NumCrate = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Crgo: %@" , [Truck objectAtIndex:1]] fontName:@"Marker Felt" fontSize:13];
    NumCrate.position = ccp(270, (s.height) - cnt + ShopPointX);

    CCSprite *Pic = [CCSprite spriteWithFile:[Truck objectAtIndex:5]];
    Pic.position = ccp(340, (s.height) - cnt + ShopPointX);
    Pic.scale = .3;

    CCMenu *Menu = [CCMenu menuWithItems:BuyButton, nil];
    cnt = cnt + 40;

    [self addChild:Pic];
    [self addChild:Menu];
    [self addChild:Name];
    [self addChild:NumCrate];
    [self addChild:NumPeople];
    StartShop = 1;
}
4

1 回答 1

0

您可能会遇到延迟,因为 OpenGL 正在为每个精灵进行单独的绘制调用。您是否将精灵放入“CCSpriteBatchNode”?看起来所有孩子都被添加到“自我”中。如果你使用批处理节点,无论批处理节点中包含多少子节点,OpenGL 只能对每个 CCSpriteBatchNode 进行一次“绘制”调用。唯一的问题是作为 CCSpriteBatchNode 子节点的所有 CCSprite 必须共享相同的图像。

一种方法是按图像名称将 CCSpriteBatchNodes 放入 NSDictionary,并将每个 CCSpriteBatchNode 添加到“self”。

    // This line assumes usage of a CCSpriteFrameCache to init the sprite, but you can create it some other way.
    CCSprite *spr = [CCSprite spriteWithSpriteFrameName:spriteName];

    CCSpriteBatchNode *batchNode;
    if([self.batchNodeDictionary objectForKey: spriteName]) {
        // Acquire the batchnode by image name
        batchNode = (CCSpriteBatchNode *) [self.batchNodeDictionary objectForKey: spriteName];
    } else {
        // BatchNode for this image doesn't exist yet; therefore, populate a new batch node for the image name

        batchNode = [CCSpriteBatchNode batchNodeWithFile:spriteNamePNG];
        [self addChild:batchNode];
        [batchNodesDictionary setObject:batchNode forKey:spriteName];


    }
    [batchNode addChild:spr];
于 2013-03-23T21:35:27.467 回答