0

I have a little game based on SpriteKit.

In this game I use lots of Nodes with letters (or combinations of letters) on it that user can move around to build words.

Those nodes are basically SKSpriteNodes with SKLabelNodes on them.

When I have a considerably large amount of nodes, Draw count increases and FPS drop dramatically.

Obviously, when I remove SKLabelNodes, Draw count stays low. But I still need those letters.

The question is, what is the best way to add those letters without dropping FPS?

  • 2
    Draw the letters into textures? – matt Nov 07 '15 at 16:08
  • @ElleryAree You should check BMGlyph and Glyph Designer. – Whirlwind Nov 07 '15 at 16:15
  • @matt, that could help, I should try this anyway... Although, if possible I want to keep a possibility to define any variant of letter/combination of letters, that I can put into the node... – Ellery Aree Nov 07 '15 at 16:17
  • @Whirlwind, I should indeed. Thanks. – Ellery Aree Nov 07 '15 at 16:21
  • "I want to keep a possibility to define any variant of letter/combination of letters, that I can put into the node" Perhaps you don't understand what I mean by "draw". I mean draw _in code_. – matt Nov 07 '15 at 16:33
  • @matt, truly, I've misunderstood you. Well, I don't really want to draw letters myself in code, but if nothing else helps... – Ellery Aree Nov 07 '15 at 17:00
  • "Well, I don't really want to draw letters myself in code" Why on earth not???? That's just silly. Drawing in code is one of the most elementary and important things to know how to do in iOS programming. I have _no_ apps in which I don't draw images in code. You're just closing your eyes to a major feature of the wonderful world of iOS. – matt Nov 07 '15 at 17:01
  • @matt, hm, should read about it more... But the idea was, I have a nice fort, I don't want to copy it myself, instead I'd like it to be drawn for me... – Ellery Aree Nov 07 '15 at 17:45
  • You can draw text in any font. Whatever a label can do, you can do. – matt Nov 07 '15 at 18:06
  • 1
    Matt is not using the word "draw" in the way you think he is. Matt, Ellery doesn't realise you're not talking about literal drawing. – Confused Nov 08 '15 at 04:40
  • I can't strongly enough recommend BMGlyph. It's even got custom image placement, so you can make your text in Photoshop and drop it into BMGlyph and it sorts it all out for you. This is awesome. You'll be able to make your text look much better than you can with SKLabelNode. – Confused Nov 08 '15 at 04:54
  • @Confused, well, I've got the idea that it's not about literal drawing, on the other hand, I'm not sure, what does it mean exactly. But I'll find out and try. Idea with BNGlyph is working, however. – Ellery Aree Nov 08 '15 at 19:47

1 Answers1

1

There are three ways to do this, each is a different blend of compromises.

The first, would be the easiest, is to use shouldRasterize on the existing labels. This doesn't seem to exist for labels in Sprite Kit. DOH!

Use bitmapped textures as letters on objects, actually as sprites, the thing that Sprite Kit handles best. This will involve using a bitmap font generator, such as the excellent BMGlyph as pointed out by Whirlwind in the comments.

This will give not be easy because the coding part will be a little more labour intensive, but you should get the absolute best performance this way.

You can swap letters, too, still, but you will need to think of them as subsections of the texture rather than as letters. An array or dictionary with each letter's position in the texture assigned to something easy to remember will be both performant and easy to use. But labour intensive to setup. Much more so than SKLabelNode

Or, you could go wild, and create textures with code, by using an SKLabelNode on a virtual object and then "rendering" or "drawing" that to a texture, and then using that texture(s) for each letter onto the objects/sprites. Similar to how BMGlyph works, but MUCH more time consuming and much less flexible.

BMGlyph is the best combination of speed and ease of use, and it has some pretty fancy effects for creating nice looking text, too.

Confused
  • 6,048
  • 6
  • 34
  • 75