Cocoa touch 如何在cocos2d中将滚动添加到图层?

Cocoa touch 如何在cocos2d中将滚动添加到图层?,cocoa-touch,iphone-sdk-3.0,cocos2d-iphone,Cocoa Touch,Iphone Sdk 3.0,Cocos2d Iphone,我的游戏中有一个用cocos2d编写的文本。文本在我们触摸的同时上下移动。文本正在移动。但当接触结束时,它并没有回到原来的位置。所以,我为文本编写了cade,以获得原始位置。但问题是我现在无法阅读全文。我需要的是滚动效果。如何在cocos2d中制作 -(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint touchLocation = [touch locationInView: [touch

我的游戏中有一个用cocos2d编写的文本。文本在我们触摸的同时上下移动。文本正在移动。但当接触结束时,它并没有回到原来的位置。所以,我为文本编写了cade,以获得原始位置。但问题是我现在无法阅读全文。我需要的是滚动效果。如何在cocos2d中制作

-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchLocation = [touch locationInView: [touch view]];   
    CGPoint prevLocation = [touch previousLocationInView: [touch view]];    

    touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
    prevLocation = [[CCDirector sharedDirector] convertToGL: prevLocation];

    CGPoint diff = ccpSub(touchLocation,prevLocation);

    CCNode *node = [self getChildByTag:kTagNode];
    CGPoint currentPos = [node position];
    [node setPosition: ccpAdd(currentPos, diff)];   
}

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGSize windowSize = [[CCDirector sharedDirector] winSize];
    CCNode *node = [self getChildByTag:kTagNode];
    [node setPosition: ccp(text1.contentSize.width/2,text1.contentSize.height/2 - windowSize.height)];
}


-(id) init
{
    if((self = [super init]))
    {
        CGSize windowSize = [[CCDirector sharedDirector] winSize];
        self.isTouchEnabled = YES;
        NSString *dataPath = @"/Users/sridhar/Srikanth/DrawGameSrikanth/ResourcestextData.txt";
        NSString *dataString = [[NSString alloc] initWithContentsOfFile:dataPath];
       CCLabel *text1 = [CCLabel labelWithString: dataString dimensions: CGSizeMake(300, 600)   alignment: UITextAlignmentLeft fontName:@"American Typewriter"  fontSize:24];
        text1.position = ccp(text1.contentSize.width/2 ,text1.contentSize.height/2 - windowSize.height); 
        text1.color = ccc3(0, 0, 0);
        CCNode *node = text1;
        CCParallaxNode *voidNode = [CCParallaxNode node];
        [voidNode addChild:node z:2 parallaxRatio:ccp(0.0f,1.0f) positionOffset:ccp(text1.contentSize.width/2,text1.contentSize.height/2 - windowSize.height)];         
        [self addChild: voidNode z:2 tag:kTagNode];
    }
    return self;
}

这将在cocos2d层上创建一个文本视图,数据将只上下滚动。但这有一个问题

我无法使用文本视图中文本的自定义字体,如“铜版哥特式粗体”。我只能使用系统字体。但是上面的代码我们可以使用任何字体

-(id)init
{
if( (self = [super init]) )
{
    self.isTouchEnabled  = YES;
    CGSize windowSize = [[CCDirector sharedDirector] winSize];

    description = [[UITextView alloc] initWithFrame:CGRectMake(50,150,200 ,200)];
    description.backgroundColor = [UIColor clearColor];
    description.text = enemyDescription;  //enemyDescription is a string from plist in my code
    [description setEditable:NO]; 
    description.font = [UIFont fontWithName:@"Arial Unicode MS" size:14.0f];

    description.showsHorizontalScrollIndicator = NO;

    description.alwaysBounceVertical = YES;

    description.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS( 90.0f ));

    [[[CCDirector sharedDirector]openGLView]addSubview:description]; 
    [description release];
}  
要再次删除它,我们必须使用以下代码

NSArray *subviews = [[[CCDirector sharedDirector]openGLView] subviews];
for (id sv in subviews)
{
    [((UIView *)sv) removeFromSuperview];
    [sv release];
}  
我希望这对你有帮助。任何建议请张贴