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
How to Work with Udp Sockets in iOS, Swift
Didoutputsamplebuffer Delegate Not Called
Swift Bridging Header File Won't Work with Use_Frameworks
Dynamic Uitablecellview Height
Facebook Sdk Login Throws Error in Swift 2 iOS 9
Custom Uibutton Class for Button Touch Event
Save Uiimage Array in Nsuserdefaults
How to Change Uitextfield Color in Searchcontroller
Unrecognized Selector Sent to Instance Swift 3
Issues Reading Data from Firebase Database
Ios: How to Create Expandable Tableview in Swift Without Using Third Party Libraries or Pods
How to Create an Image of Specific Size from Uiview
How to Create an Alert in a Swift File Model That Works for Various View Controller
How to Get the Index (String.Index) Value from the Cursor Position of a Uitextview Element in Swift