I am trying to use custom font in Cocos2d-Android with CClabel, I have added my font file into the assets and trying to use it by name "Faraco_Hand.ttf" and "Faraco_Hand" but its not working, I have googled around but haven't found any solution. this is how my code looks a like:
currentVideoLabel = CCLabel.makeLabel(VideosLabels[currentSelected], "Faraco_Hand.ttf", winSize.width/41);
currentVideoLabel.setPosition(CGPoint.make(winSize.width/2, 20));
addChild(currentVideoLabel);
If someone know this please help me.
Hi i use this way to add font in my game here i am sharing you my code check it hope it's helpful for you here i am setting my font on label this is the only way to set fonts...all the best
Example:1
CCLabel labelcontinue = CCLabel.makeLabel("continue", "fonts/JimboStd-Black.otf", 14);
labelcontinue.setPosition(CGPoint.ccp(272, 95));
labelcontinue.setColor(ccColor3B.ccc3(165, 42, 42));
mainPaperNode.addChild(labelcontinue, 25);
Example2:
CCLabel labelWelcome = CCLabel.makeLabel("Welcome", "fonts/JimboStdBlack.otf",20);
labelWelcome.setColor(ccColor3B.ccc3(139, 69, 19));
labelWelcome.setPosition(CGPoint.ccp(innerArea.getContentSize().getWidth() / 2, (innerArea.getContentSize().getHeight() / 2) + 138));
innerArea.addChild(labelWelcome);
i know this is late reply, anyhow it may help someone who search this same thing...
CCLabel supports external fonts but some of the ttf will not recognized by android so it will through exception so better you try another font instead of this the code is same...
label = CCLabel.makeLabel("label value", "external_font_name.ttf", 30);
label.setPosition(CGPoint.make(winSize.width/2, 20));
addChild(label);
I don't think there's any problem with your method. I guess the problem is you are renaming the original font file. Rename the font file name with its original name (written in the font file itself, check attached image).
in this case, I kept my ttf file in Resources/fonts folder and wrote my code like:
CCLabelTTF* label = CCLabelTTF::create("Hello World", "fonts/A Damn Mess.ttf", 20);
Also check CCLabelTTF instead of CCLabel.
Hope this will help you.
Hai this will help. This code works for me fine. Put custom font int assets->fonts
CCLabel label1 = CCLabel.makeLabel("Points: 0", "fonts/pin.ttf", 28);
label1.setColor(ccColor3B.ccWHITE);
label1.setPosition(280f * scaleX, 550f * scaleY);
addChild(label1);
Related
I now how to set value(number) but can i read that label in some variable. if can't read, in which similar widgets can i put value and read it. Any help would be halpful or someone has an other idea. Maybe like LCD number, spin box
Like this?
QString text = someLabel->text();
Here is the documentation. QLabel.text()
EDIT:
QString text = theLabel.text();
//or with pointer
QString text = theLabel->text();
have you tried :
QString s = YourQLabel->text();
This should work, I guess.
// Thelepaty mode on
You need to use editor widgets, for example QLineEdit or QTextEdit. You may customize it via QSS to look like a QLabel.
P.S. try to improve your English. It is hard to understand, what you are asking.
// Thelepaty mode off
This code works:
auto label = LabelTTF::create(CokeStore::name, "Marker Felt", 170);
But none of these work:
auto label = LabelTTF::create(CokeStore::name, "Coca Cola ii", 170);
auto label = LabelTTF::create(CokeStore::name, "CocaColaii", 170);
auto label = LabelTTF::create(CokeStore::name, "cocacolaii", 170);
I imported all the fonts as resources into my project and added fonts' path into Fonts provided by application of Info.plist. I'm using Cocos2d-x v. 3, the latest version from Github.
Anybody can help me with this? Is there anything wrong with my code and how to fix them?
Thanks for your help!
I was facing alot of difficulty adding a custom font. I know the question has already been answered but I just want to share what solved the problem for me.
These are the points you need to ensure to use a custom font:
Font name must match the PostScript name of that font (you can easily find the postscript name using the Font Book, just select the font and press command+i) , so your font name should be: PostScriptName.ttf
In the Info.plist of your project, make sure to add the font name under "Fonts provided by application", just put in the font name and extension for item0 or whatever the length of your font stack is: PostScriptName.ttf,
Now, the next step that solved the issue for me was:
Ensure that the font file exists in the "Copy Bundle Resources" Section of the 'Build Phases' settings for your project. For me it somehow wasnt there and thats why the font wasnt loading, so I just manually added it.
Now you can use it even with LabelTTF::create("Text", "PostScriptName", 24)!
In Cocos2d-x V3, there is a new class Label.
I tried this and it worked:
Label *label = Label::createWithTTF("Your string here","cocacolaii.ttf", 170);
For more details, you can read this
To add custom fonts in cocos2d-x i followed the following steps.
Download a font.
paste it in resource file of my project without any subfolder.
Add my font in info.plist in Fonts provided by application as Roboto-thin.ttf
Add it in Copy bundle resources.
I used the following code to display the font:
CCLabelTTF* cycleLabel1 = CCLabelTTF::create(" ", "Roboto-Thin.ttf", 80);
I tried with removing the extension also in the code, but no use. Anyone please help me to solve this problem.
On IOS, inside your CCLabelTTF::create() you have to use the NAME of the font, not the file of the font. In your case it is probably "Roboto Thin". Something like this:
CCLabelTTF* cycleLabel1 = CCLabelTTF::create(" ", "Roboto Thin", 80);
You can see font names installing them and opening them in Font Book (assuming you use mac)
Note on Android you still call fonts using its file name.
It is very explained (not very well at all) in the documentation.
http://www.cocos2d-x.org/wiki/How_to_Use_Custom_TTF_Font_on_iOS
Try this:
AddFontResource(L"xxx/yyy/Roboto-Thin.ttf");
before CCLabelTTF::create(" ", "Roboto-Thin", 80);
and then RemoveFontResource(L"xxx/yyy/Roboto-Thin.ttf");
Make sure that the name of the font and the file name are the same
I try to ask not to localized, because I think many other wxWidgets users will stumble about this problem or a similar one.
I try to get a wxStaticBitmap (original a PNG-Image) in a GUI, I will try to model it:
text text text
text text text
IMAGE
text
text
How I can do this? When I try:
wxBitmap bild(_T("Bild.png"), wxBITMAP_TYPE_PNG);
wxStaticBitmap *image = new wxStaticBitmap(this, wxID_ANY,
wxBitmap("Bild.png", wxBITMAP_TYPE_PNG),
wxPoint(100,100),
wxSize(bild.GetWidth(), bild.GetHeight()));
The image will take over the hole window, even the wxNotebook, which contains the wxPanel, will disabled and I have only the image, but nothing else...
I want to get the image in the third row of the VerticalBox. Is there any way to make this happend?
-Casisto
(wxW: 2.9.4; C++-Compiler: g++)
There is nothing special about wxStaticBitmap and you absolutely don't need to put it inside a panel. You do need to create it with the correct parent, if this in your example refers to wxFrame, it's not going to work if you then put it inside a wxPanel sizer, for example.
P.S. Do get rid of _T in your code, it's completely unnecessary in 2.9+. You also probably don't want to load the bitmap twice...
Ok, i found the answer myself:
I've to use a "subpanel" which will be the parent of the StaticBitmap
so it's this structur:
panel << vbox << Text
vbox << panel_2 << Image
vbox << Text
I am trying to create a Windows application (but will eventually port it to linux also, so cross-compatibility is important if possible) that will take a picture from a webcam and can print without using a printDialog box, but I am having an issue selecting a paper size. I would like the paper size to be set to 4" x 6" which is the A6 format, but when I use setPaperSize(QtPrinter::A6) it seems to default to the letter format. It does not always default to letter with all printers though, it looks like each printer handles the command differently, but most default to letter. I believe this may be an issue with Qt and printer compatibility with the drivers.
My question is: Does anyone know a way to set the printer to 4" by 6" in Qt that should work with all printers?
My code is shown below.
void MainWindow::Print() {
QPainter painter;
QPrinter *printer = new QPrinter(QPrinter::HighResolution);
printer->setPaperSize(QPrinter::A6);
if (!painter.begin(printer)) {
qWarning("Failed to open file");
return;
}
painter.fillRect(QRectF(QPointF(108,118),QPointF(110+352, 120+352)), Qt::black);
painter.fillRect(QRectF(QPointF(109,119),QPointF(109+352, 119+352)), Qt::white);
ui->graphicsView->scene()->render(&painter, QRectF(110,120, 350, 350), QRectF(0,0, ui->graphicsView->scene()->width(), ui->graphicsView->scene()->height()), Qt::IgnoreAspectRatio);
painter.drawText(110, 110, "Test");
painter.end();
}
I have tried the following for resizing the paper
printer->setPaperSize(QPrinter::A6)
printer->setPageSize(QPrinter::A6)
printer->setPaperSize(QSizeF(4.0, 6.0), QPrinter::Inch)
none of those seemed to work. If anyone could help me with this issue I would be very greateful
setPaperSize relies on information received from the printer driver, so to be really printer independant, calculare pageRects yourself.
See the pageRect and the paperRect property together with the fullPage property of QPrinter.
See also my answer to Printing pagerect issues where there is a (wrong) starting example of printing arbitrary print rects and how to fix the code given with the question.