Stroking not working on CCLabelTTF in cocos2d-x ios in c++ - 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);

Related

Cocos2d, How Set Device Orientation to portrait IOS

I had followed this http://www.cocos2d-x.org/wiki/Device_Orientation
but my RootViewController.mm not exactly look like that.
After i replace
'UIInterfaceOrientationMaskAllButUpsideDown'
to 'UIInterfaceOrientationMaskPortrait' there is some error on main.m
my cocos2d version = cocos2d-x-3.13.1 , on iPhone 7 simulator
You also need to go to xcode project setting and choose device orientation.
Here is a screenshot.

cocos2dX Orientation Support

I am having this problem when doing a simple orientation test.
Suppose I am using a design resolution of 480*320 for landscape and 320*480 for portrait mode.
Now I have a long sprite of width 480 which doesn't show all of itself in portrait mode.
Then upon orientation change, I reposition it so that it should show properly.
After doing so, I successfully place the sprite correctly, anchoring at the bottom left corner, but the sprite still doesn't fully show itself.
http://tinypic.com/r/34e45c2/8 <- portrait mode
http://tinypic.com/r/2s84vgh/8 <- landscape after repositioning
Steps to reproduce:
1) create a default project with the create_project tool
2) Edit RootViewController.mm as follow
add these 3 lines to didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
auto dum = Director::getInstance()->getRunningScene()->getChildByTag(13579)
->getChildByTag(24680);
dum->setPosition(cocos2d::Point::ZERO);
dum->setAnchorPoint(cocos2d::Point::ZERO);
}
3) add the tags used above,
under createScene change to
scene->addChild(layer, 0, 13579);
under HelloWorld::init
this->addChild(sprite, 0, 24680);
4) under project setting "General" tab, tick all 4 modes under "Device Orientation"
5) run in simulator and then click Hardware->rotateLeft
How may I fix this problem?
[I have tried changing the HelloWorld layer's content size to getFrameSize() as well with no luck.]
Thanks.
PS I am using cocos2dx-3.0alpha1
You can try adding the following code in your AppDelegate.cpp in your AppDelegate::applicationDidFinishLaunching() methode :
glview->setDesignResolutionSize(320,480,ResolutionPolicy::SHOW_ALL);
Worked for me. I hope it helps.

How to get app to be in landscape orientation in cocos2d 2.0

(Sorry I can't include the images. I don't have a high enough rep so i just provided links to the images)
As the title says, I am having problems with my app in landscape mode. I want the whole app to be in landscape mode so I selected only Landscape Left and Landscape Right in the Target Summary. I also put this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
in my AppDelegate.m. I also went to my info.plist and put "Initial interface orientation to Landscape (left home button). However my orientation in the simulator and on the actual device are wrong. Here is a picture of what I have in my storyboard (what I want it to look like)
http://imageshack.us/photo/my-images/836/iphoneimage2.png/
But this is what it looks like in my simulator and on my device
http://imageshack.us/photo/my-images/440/iphoneimage.png/
Does anyone know how to fix this? Thanks
EDIT: If you are running Cocos2d 2.0 rc1 or rc0a, then the shouldAutorotateToInterfaceOrientation: method should be placed in the RootViewController.m file. If you are running Cocos2d 2.0, the the shouldAutorotateToInterfaceOrientation: should be placed in the AppDelegate.m file.
The method will already be in RootViewController.m if you used one of the templates in Cocos2d 2.0 rc1 or rc0a to create your app.
The method will already be in AppDelegate.m if you used Coco2d 2.0.
You just need to edit the method to only return the desired orientation you need.
Edit the method in your RootViewController.m or AppDelegate.m class, depending on which version of Cocos2d 2.0 you are using, to look like this to accommodate both landscape orientations:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

AI88 textures bug on Cocos2D 1.1beta2 with TMX tile maps

Recently I migrate my project to Kobold2D 1.1 with Cocos2D 1.1beta2 inside for iPad Retina Display. But when I run my project and try to put a TMX tile map, the program hung up. The problem is CCTexture2D is call in InitWithImage and there's no Case for texture format AI88. Because of that, program goes to default and hang up.
I add to the code:
case kCCTexture2DPixelFormat_AI88:
data = malloc(POTHigh * POTWide);
info = kCGImageAlphaOnly;
context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, NULL, info);
break;
Is the same config as kCCTexture2DPixelFormat_A8 and now code works. I used a TMX made with Tile Editor 0.8 and uses a simple PNG not in any texture packer. The name inside TMX is fondomaze.png but in the project I must rename to fondomaze-ipad.png.
Hope you find useful. Now I can breathe relax with my project still working!
Discover a workaround for Retina Display iPad... Must to increase malloc by 4.
data = malloc(POTHigh * POTWide * 4);
Hope helps people who want to work with RD iPad.

iOS 4.3 causes black screen (4.0-4.2 was fine) - MPMoviePlayerController at fault?

I've made a game that uses cocos2d to display graphics, and uses a lot of MPMoviePlayerController to display cutscenes.
The problem is - the game stopped working on iOS 4.3. It was fine up until iOS 4.2, but on iOS 4.3 the movies play OK, the gameplay also happens, but the screen is all black when not playing the movies.
I have a hard time tracking the problem. Suggestions?
Edit: I narrowed the thing down to MPMoviePlayerController - if I disable it, everything is fine. I guess something changed in 4.3?
MPMoviePlayerController's view is clear in 4.0-4.2, and black in 4.3 by default, what helped was:
MPMoviePlayerController* moviePlayer = ...
moviePlayer.view.backgroundColor = [UIColor clearColor];
MPMoviePlayerController* moviePlayer = ...
[moviePlayer.backgroundView setBackgroundColor:[UIColor whiteColor]];
// or set need color
read more in "MPMoviePlayerController Class Reference"