Is There Really No Way to Style Sklabelnode

Is there really no way to style SKLabelNode?

There is no method or property of SKLabelNode that will enable you to achieve the gradient style. As noted in the link in the comments, SpriteKit does have a SKBitmapFont private class, but that's not going to help you.

You can either roll your own solution or try glyph designer : https://71squared.com/glyphdesigner

How to cache or preload SKLabelNode font in spritekit

You can set the font once by initializing an UIFont:

let yourFont = UIFont(name: "yourfontName", size: 17)

var firstLabel = SKLabelNode(fontNamed: yourFont?.fontName)
var secondLabel = SKLabelNode(fontNamed: yourFont?.fontName)

That way, you only set the font once and the SKLabelNodes don't have to load it by themself.

Change the text of a SKLabelNode added from the scene editor

From code that you provide var myScoreLabel: SKLabelNode! is not created.

Try to create SKLabelNode firstly. And then set value.

Example:

myScoreLabel = SKLabelNode(fontNamed: "Chalkduster")
myScoreLabel.text = "Test"
myScoreLabel.horizontalAlignmentMode = .right
myScoreLabel.position = CGPoint(x: 0, y:10)
addChild(scoreLabel)

Or you can connect it from .sks scene.

override func sceneDidLoad() {
if let label = self.childNode(withName: "myScoreLabel") as? SKLabelNode {
label.text = "Test" //Must add '.text' otherwise will not compile
}
}

What would be the best approach for outlining or dropshadowing a font?

This is most likely what you are doing, but it works and is simple.

- (SKLabelNode *) makeDropShadowString:(NSString *) myString
{
int offSetX = 3;
int offSetY = 3;

SKLabelNode *completedString = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
completedString.fontSize = 30.0f;
completedString.fontColor = [SKColor yellowColor];
completedString.text = myString;

SKLabelNode *dropShadow = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
dropShadow.fontSize = 30.0f;
dropShadow.fontColor = [SKColor blackColor];
dropShadow.text = myString;
dropShadow.zPosition = completedString.zPosition - 1;
dropShadow.position = CGPointMake(dropShadow.position.x - offSetX, dropShadow.position.y - offSetY);

[completedString addChild:dropShadow];

return completedString;
}

Will try and make outline one as well... but I have a feeling it'll be more tricky... there must be a way to use bitmap fonts .. ??? bmGlyph ...



Related Topics



Leave a reply



Submit