Iphone 如何在Cocos2D中滚动标签上的字符?

Iphone 如何在Cocos2D中滚动标签上的字符?,iphone,ios,scroll,cocos2d-iphone,Iphone,Ios,Scroll,Cocos2d Iphone,我有一个雪碧,上面有一个标签(CCLabelTTF)。在这个标签上,我有A,B,C,D,E等,当它们被点击时打印出来。我希望它们向左滚动。我在谷歌上搜索了一些tuorials,但我找不到解决方案,在这里停留了很长时间。这是我游戏的截图。您可以看到从A到J的字符。当我单击更多输入字符时,该部分应该滚动。我可以做些什么使角色滚动 以下是在sprite上添加的标签(lblSelectedAlpha)上显示字符的代码:- -(void)showSelectedAlphaBet{ fSelect

我有一个雪碧,上面有一个标签(CCLabelTTF)。在这个标签上,我有A,B,C,D,E等,当它们被点击时打印出来。我希望它们向左滚动。我在谷歌上搜索了一些tuorials,但我找不到解决方案,在这里停留了很长时间。这是我游戏的截图。您可以看到从A到J的字符。当我单击更多输入字符时,该部分应该滚动。我可以做些什么使角色滚动

以下是在sprite上添加的标签(lblSelectedAlpha)上显示字符的代码:-

-(void)showSelectedAlphaBet{

    fSelectedAlphaY =26;     
    if (tempBackground) {       
        [tempBackground removeFromParentAndCleanup:YES];
    }   
    tempBackground = [CCSprite spriteWithFile:@"stripe_2.png"];
    tempBackground.position = ccp(160,30);
    [self addChild:tempBackground z:30];        
    for (int i=0; i<[arryAddSelectedChar count]; i++) {     
       // NSLog(@"[arryAddSelectedChar count] %@",[arryAddSelectedChar objectAtIndex:i]);       
        lblSelectedAlpha = [CCLabelTTF labelWithString:
                        [arryAddSelectedChar objectAtIndex:i]dimensions:CGSizeMake(30,30)
                                         alignment:UITextAlignmentCenter  fontName:@"Marker Felt" fontSize:30];     
        lblSelectedAlpha.position = ccp(fSelectedAlphaY,25);
        lblSelectedAlpha.tag=i;
        lblSelectedAlpha.color = ccc3(125,125,125);
        [tempBackground addChild:lblSelectedAlpha z:5];     
        fSelectedAlphaY +=25;     
    }
}
-(无效)显示选定的对话框{
fSelectedAlphaY=26;
如果(临时背景){
[tempBackground removeFromParentAndCleanup:是];
}   
tempBackground=[CCSprite spriteWithFile:@“stripe_2.png”];
tempBackground.position=ccp(160,30);
[self-addChild:TempZ:30];

对于(int i=0;i而言,滚动只是位置随时间的不断变化。基本上如下所示:

-(void) update:(ccTime)delta
{
   label.position = CGPointMake(label.position.x - 1, label.position.y);
}

这就是我在cocos2d游戏中实现滚动的方式

//如何添加标签上的滚动。这是我用UITextView做的

//在init内部,我采取了

{

}

-(无效)显示选定的标签

{

//触摸时添加字母的区域

tempBackground = [CCSprite spriteWithFile:@"stripe_2.png"];
tempBackground.position = ccp(160,30);
[self addChild:tempBackground z:30];
bottomAlphabet = @" ";

for (int i=0; i<[arryAddSelectedChar count]; i++) {

    NSLog(@"[arryAddSelectedChar count] %@",[arryAddSelectedChar objectAtIndex:i]);

    bottomAlphabet = [bottomAlphabet stringByAppendingString:[arryAddSelectedChar objectAtIndex:i]];
}
}

//在Dealoc

[alphabetScroll release];

这可能会减少字符数。我需要的是滚动并查看由于添加更多字符而从视图中删除的字符。我不明白。要么您有一个带有字符串“ABCDEF..”等的标签,要么您有26个以上的标签,每个标签带有一个字符“a”、“B”、“C”等等。要滚动它们,你可以调整它们的位置。我有一个标签,上面有一个字符串“ABCDEF..”等等…我将要找到问题的解决方案。完成后将发布它。
tempBackground = [CCSprite spriteWithFile:@"stripe_2.png"];
tempBackground.position = ccp(160,30);
[self addChild:tempBackground z:30];
bottomAlphabet = @" ";

for (int i=0; i<[arryAddSelectedChar count]; i++) {

    NSLog(@"[arryAddSelectedChar count] %@",[arryAddSelectedChar objectAtIndex:i]);

    bottomAlphabet = [bottomAlphabet stringByAppendingString:[arryAddSelectedChar objectAtIndex:i]];
}
int newScrollViewWidth;
int newLabelWidth;
newScrollViewWidth =25*[arryAddSelectedChar count];
newLabelWidth =50*[arryAddSelectedChar count];

[scroll setContentSize:CGSizeMake(newScrollViewWidth, 45)];

alphabetScroll.frame =  CGRectMake(0, 0, newLabelWidth, 45);

alphabetScroll.text = bottomAlphabet;
if (newScrollViewWidth > 150) {
    CGPoint svos;
    CGPoint pt;
    svos = scroll.contentOffset;
    CGRect rc = [alphabetScroll bounds];
    rc = [alphabetScroll convertRect:rc toView:scroll];
    pt = rc.origin;
    pt.y = 0;
    pt.x += 20*([arryAddSelectedChar count]-5);

    [scroll setContentOffset:pt animated:YES];       
}
[alphabetScroll release];