I basically want to add custom font numbers (with images) in Singles and add them for my score in my game with SpriteKit.
This is the font image style
They are numbers from 0 to 9
I have been trying to figure this out for a while.
I'm not sure if you can add it to SKLabelNode or if you would have to make it in a class.
SKLabelNode
would not allow for bitmap fonts. If your custom font was TTF, you would be able to use the custom font withSKLabelNode
. An explanation how is here: SKlabelNode custom fontIn your case, since you want to use bitmap fonts, you will need to create a class to do it do this. You can either subclass an
SKNode
or not. But you would want to have oneSKNode
act as the "root" and then have each digit for your number be anSKSpriteNode
(these would be children nodes of the root node representing the number).One thing you will want to determine is how you want to handle alignment for the number (both horizontally and vertically).
I have used my own custom class to draw numbers before and typically have it configurable to be adjustable horizontally (left justified, right justified, and centered). But out of laziness, I usually always center vertically.
This may sound complicated, but is easy to do. You would just need to have
SKSpriteNode
and add each new digit. Each new digit being offset by the proper amount based on alignment.Your custom class should, upon the number value being set, build the correct
SKSpriteNode
s to represent the number.Some updated info for the last question regarding to how one would use an array with the
SKTexture
. This code is not tested for compilation and is meant to just give you a better idea.