Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 804755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:58:11+00:00 2026-05-14T23:58:11+00:00

I have a text in my game which is written in cocos2d. The text

  • 0

I have a text in my game which is written in cocos2d. The text moves up and down while we touch and move it up or down. The text is moving. But it is not getting to original position while touches ended. So, I wrote cade for touches ended for text to get original position. But problem is i could not read the entire text now. What I need is scrolling effect. How can I make it in 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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:58:11+00:00Added an answer on May 14, 2026 at 11:58 pm

    This creates a textView on cocos2d layer and data will be scrolled only top and down. But there is a problem with this.

    I am not able to use the custom fonts for the text in textView like “Copperplate Gothic Bold”. I am able to use only system fonts. But the code above we can use any font.

    -(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];
    }  
    

    To remove it again you we have to use the following code

    NSArray *subviews = [[[CCDirector sharedDirector]openGLView] subviews];
    for (id sv in subviews)
    {
        [((UIView *)sv) removeFromSuperview];
        [sv release];
    }  
    

    I hope this helps you. Any suggestions please post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a small text game I've written in Java that utilizes System.out.print();
I have a function which loads an image/text into my game.I'm using gluBuild2DMipmaps() to
The program above is, as said, a Sudoku game. I have written down ideas
I have written a networked game (basically a prototype) which implements different smoothing algorithms
I have a menu button called Restart which restarts a simple text game I
I am making a text based game in Java. I have a text field,
I am coding a text based Java game, I have ran into a few
I am creating a copy of the game Pig. I have got a text
I have a project which is essentially a game server where users connect and
I have written a mail-processing program, which basically slaps a template on incoming mail

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.