CCLabelTTF Color - Gradient Possible? - cocos2d-iphone

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.

Related

How to do overlapping custom items in qt?

Like in the title. I have few objects, and i wanted to set graphics to them and overlap each other. I'm setting 18 squares (terrains). I'm adding to this terrains graphics:
setPixmap(QPixmap(":Graphics/Terrain")); like so.
Then i want to add frame to it. I have 4 files of format .png, every one is 200x200px. First one is terrain.png - it's a green square, second and third are frames, about 20px wide with a transparent center (with alpha channel) and the last .png file is City.png, in left corner of City.png, there is a small graphics, rest is transparent (alpha channel). When i'm trying to set the frame by the same way as terrain.png:
setPixmap(QPixmap(":Graphics/Frame"));
it covers all of the terrain.png graphics, despite the fact that the center of frame1.png is transparent.
Furthermore i want to add some others object like for example City.png. How to do it? Mayby exists some diffrent way except using this setPixmap function ?
The setPixmap approach seems to work quite nicely, when used like this:
QGraphicsScene* scene = new QGraphicsScene();
QGraphicsPixmapItem* itemA = new QGraphicsPixmapItem();
itemA->setPixmap(QPixmap(":/NonTransparentImage.png"));
scene->addItem(itemA);
QGraphicsPixmapItem* itemB = new QGraphicsPixmapItem();
itemB->setPixmap(QPixmap(":/TransparentImage.png"));
scene->addItem(itemB);
QGraphicsView* view = new QGraphicsView(scene);
view->show();
As you expect, the transparent itemB overlaps itemA.

Cocos2d. CCMenuItem with custom touchable region?

For example, in my case every button look likes a hex.
Hex pictures on these buttons can't intersect but their rects can.
You can use the new activeArea property of CCMenuItem to define your custom touchable region: see this article
You can use CGMutablePathRef to make non-rectangular sprite collision detection. use this in CCMenuItem. It works...See my answer in this post:Custom touch detection

Cocos2D font rendering issue

Observed one serious Cocos2D Font related problem
Please see this image:
In above image, fonts are not rendered proper. I used CCLabelBMFont. How can I resolve this problem?
Code:
CCLabelBMFont *userName = [CCLabelBMFont labelWithString:PlayerNameStr fntFile:#"MyFont.fnt"];
You need to leave more space between the glyphs. You can change this setting in the bitmap font editor, Glyph Designer and Hiero both have it. In Glyph Designer the setting is called Spacing and set to 2. I'm guessing you're using Hiero which has this spacing set to 0 by default.

Qt GUI Development - Displaying a 2D grid using QGraphicsView

I'm new to Qt development so I've being trying to research a solution to a user interface I need to design. My project is to simulate players in an online game moving around a global map. To represent the map I need to display a 2D grid, with each space in the grid representing a region of a map. I then need to display the location of each player in the game. The back-end is all fully working, with the map implemented as a 2D array. I'm just stuck on how to display the grid.
The research I have done has led me to believe a QGraphicsView is the best way to do this, but I can't seem to find a tutorial relevant to what I need. If anyone has any tips on how to implement this it would be much appreciated.
Thanks, Dan
A 2D Grid is nothing more than a set of horizontal and vertical lines. Suppose you have a 500x500 map and you want to draw a grid where the distance between the lines in both directions is 50. The sample code that follows shows you how you can achieve it.
// create a scene and add it your view
QGraphicsScene* scene = new QGraphicsScene;
ui->view->setScene(scene);
// Add the vertical lines first, paint them red
for (int x=0; x<=500; x+=50)
scene->addLine(x,0,x,500, QPen(Qt::red));
// Now add the horizontal lines, paint them green
for (int y=0; y<=500; y+=50)
scene->addLine(0,y,500,y, QPen(Qt::green));
// Fit the view in the scene's bounding rect
ui->view->fitInView(scene->itemsVBoundingRect());
You should check the QGraphicsView and the QGraphicsScene documentation as well as the corresponding examples. Also you can watch the graphics view training videos or some graphics view related videos from the Qt developer days.
Well if you have a constant grid size or even a limited number of grid sizes what i like to do is to draw a grid block in gimp or any other program and then set that as the background brush (draw only bottom and right side of the block) qt will repeat the image and will give you a full grid. I think this is good for performance too.
This is the grid image i used in one of my programs it's 10x10 pixels.
Then call QGraphicsScene setBackgroundBrush as the follwing:
scene->setBackgroundBrush(QBrush(QPixmap(":/grid/grid10.png")));
The more native way is this:
scene = self.getScene() # Your scene.
brush = QBrush()
brush.setColor(QColor('#999'))
brush.setStyle(Qt.CrossPattern) # Grid pattern.
scene.setBackgroundBrush(brush)
borderColor = Qt.black
fillColor = QColor('#DDD')
rect = QRectF(0.0, 0.0, 1280, 720) # Screen res or whatever.
scene.addRect(rect,borderColor,fillColor) # Rectangle for color.
scene.addRect(rect,borderColor,brush) # Rectangle for grid.
Sorry by PyQt...
Suppose a scene is set to the graphicsview then simply below one line will show the grid.
ui->graphicsView->scene()->setBackgroundBrush(Qt::CrossPattern);
There several other values can be passed for ex: Qt::Dense7Pattern
These are members of enum BrushStyle, just click on any used value in Qt creator and it will take you to the enum declaration where you can see all other possible values.
PS:
A scene can be set like this:
ui->graphicsView->setScene(new QGraphicsScene());

Cocos2d show only a part of a CCSprite

Is there any possibility to show only a part of an CCSprite?
It seams that contentSize property doesn't have a good result.
I think you might have to create a new sprite for this. The general pseudo code is this.
CCTexture2D *origTexture = originalSprite->getTexture();
CGRect rect = {0, 0, 20, 20};
CCSprite *destSprite = CCSprite::spriteWithTexture(origTexture, CGRect);
Both doc_180's and James' answers work by creating new CCSprite using a portion of the texture, but if you are using clipping method, you will get CCSprite that uses the full texture but have the ability to only draw a portion of it on screen. One advantage of this method is you are able to modify how big or small the portion that you want shown or hidden on the fly rather than having to re-create the CCSprite again and again (or replacing the texture again and again).
So, to use the clipping method, simply download the ClippingNode class from here, and add the CCSprite you want clipped to that ClippingNode. Then you call one of its methods to specify which region to limit the drawing to. I'm currently using it to create a progress bar so I know for sure it works great.
Get the [sprite displayedFrame], change the frame of that, and create a new sprite with that spriteframe: CCSprite *sprite2 = [CCSprite spriteWithSpriteFrame:frame]