Cocos2D: In the .7.2 version how do I write simple text? - cocos2d-iphone

Due to certain circumstances (not having admin's administatrion on a computer that isn't mine) I can't use the latest version of cocos2D.
How am I able to write simple text on that version?
Thanks.

I would really try and get the latest version as you could imagine 7.2 is long non supported I would think.
However it should be as simple as:
//Make your text.
CCLabelTTF *label = [CCLabelTTF labelWithString:#"Your text!" fontName:#"Helvetica" fontSize:24];
//Choose a position on the screen.
label.position = ccp(240, 160);
//Add it to the scene.
[self addChild:label];

Related

Enable Multi-touch in Cocos2d 3.0

There are many buttons in my game but some functions require pressing 2 buttons at once. Now when I try to press 2 buttons at once it only detects one. What could I do to detect both?
To enable multi-touch in the new Cocos2d 3.0
In your - (id)init. This now Enables multi-touch to the whole scene.
first add
self.multipleTouchEnabled = YES;
Right under the
self.userInteractionEnabled = YES;
To finish it off add
jButton.exclusiveTouch = NO;
jButton.claimsUserInteraction = NO;
to your buttons. Im sorry i cannot explain how this works (i hope somebody can explain) but it works!

Stroking not working on CCLabelTTF in cocos2d-x ios in c++

I am tryng to make an outline of green color in my label but its not working..
my code is
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "HoboStd", 50);
pLabel->setPosition(ccp(200,200));
pLabel->enableStroke(ccGREEN, 5.0,true);
this->addChild(pLabel);
Its not providing the outline around the label text Hello World.Any one here who can help me
I got the fix in ios7.0 on how to enable stroking on labels
The normal stroking code of a label doesn’t work in IOS 7.0 but it works successfuly below IOS 7.0
The basic code for enabling stroking is provided below. We need to add a CCLabelTTF and then call the enableStroke function
CCLabelTTF *label=CCLabelTTF::create("Hello", "Arial.fnt", 50);
label->setPosition(ccp(300,300));
label->enableStroke(ccGREEN, 1.0,true);
this->addChild(label);
This works fine with IOS below 7.0. But in IOS 7.0 there is no stroking effect on the label. In order to fix the issue just follow some steps
Step1
Find the CCImage.mm file in your project and find the following code written there
//actually draw the text in the context
//XXX: ios7 casting
[str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) withFont:font
lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)align];
Step2
Now add the following code just below this line
//New Code Start
if(pInfo->hasStroke)
{
CGContextSetTextDrawingMode(context, kCGTextStroke);
CGContextSetRGBFillColor(context, pInfo->strokeColorR, pInfo->strokeColorG, pInfo->strokeColorB,
1);
CGContextSetLineWidth(context, pInfo->strokeSize);
[str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) withFont:font
lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)align];
}
//New Code End
Save the CCImage.mm file and then again re-run your project. It will redraw stroke with correct color.Tested on 7.0 simulator
I tested your code and I get the outline. Try to reduce the stroke width to 1.0.
pLabel->enableStroke(ccGREEN, 1.0,true);

Side scrolling game background

I am working in Cocos2d and xcode to create a side scrolling game.
I have an issue with my coding for adding a background to the levelscene.
I tried to implement a parallax background to no avail so have opted to just have a background the player will scroll across.
But at the moment the background follows the player across the screen, which frankly looks rubbish.
The code I have is
(void)setupParallax {
NSString *backgroundName = [self.tilemap propertyNamed:#"BackgroundImage"];
CCSprite *background = [CCSprite spriteWithFile:[AssetHelper getDeviceSpecificFileNameFor:[NSString stringWithFormat:#"background-noon.png]]];
background.anchorPoint = ccp(0,0);
background.position = CGPointMake(0, 0);
[self addChild:background z:0];
}
I know it must be something with either the position or anchorPoint but these values only change with reference to the screen they are loaded on.
Have you looked at this tutorial on doing parallax scrolling in cocos2d-x?
You an do parallax scrolling by hand...but it will probably easier, at least if you are just starting out, to do it using the CCParallaxNode and let the framework do the heavy lifting for you.

CCLabelTTF Color - Gradient Possible?

I create label in my game using code:
CCLabelTTF *label = [[CCLabelTTF alloc] initWithString:#"COMBO x1" dimensions:CGSizeMake(200,100)
alignment:UITextAlignmentCenter fontName:#"Helvetica" fontSize:HD_TEXT(25.0f)];
label.color = ccc3(255,0,0);
[self addChild:label z:0 tag:44];
This gives me a red label. But I'd like to have a gradient colored label.
is it possible using CCLabelTTF?
Thanks
No. Use a bitmap font instead. Glyph Designer enables you to create gradients and shadows for the characters.
Hiero can also do this but I can't recommend this tool, it's full of bugs and has a terrible user interface.

Cocos2D: Best way to display text from font atlas?

Based on the use CCDirector makes of CCLabelAtlas, I tried the following:
scoreLabel = [[CCLabelAtlas alloc] initWithString:#"0123456789" charMapFile:#"fps_images.png" itemWidth:8 itemHeight:12 startCharMap:'.'];
[scoreLabel setPosition:ccp(200, 200)];
[self addChild:scoreLabel];
I must be missing something as nothing displays. I'm using the basic .png that's supplied with Cocos2D.
What am I missing? Thanks!