Armelline's Super-Easy Custom Number Fonts 2.0 - now includes CENTRED fonts!
One thing that I've not seen anyone release (though I know has been done before) is centred fonts. I had to solve this problem a few years ago for a game I made for one of the Amazon promotions, however the solution I used was effective but inelegant.
When I reworked how to do custom fonts a few weeks ago, I did so with left aligned and centre aligned fonts particularly in mind. My method isn't quite as simple as the traditional method, and uses a touch more resources in a lot of situations, but applying it to your own game is insanely easy, and it makes doing left and centre aligned fonts equally easy. I only released left and right aligned fonts before, but now I thought I'd add in centre alignment.
Tracking the position of each digit as the number changes obviously requires your game to do more work, so you want to avoid putting too many of these on screen at once. In my tests, 20 centre aligned fonts being repeatedly changed at short intervals would drops the frame rate a few FPS, but if you have 20 centre aligned fonts on screen at once being changed constantly, then you probably aren't going to notice a drop of a few FPS anyway as you're looking at a mostly text based scene.
Please note that if you want multiple instances of a centre aligned font in your game, it will require a different actor for each one - each digit needs to know where the centre point of the number is, so a different game attribute is needed for each different number being displayed. It's still super-easy to add one to your game, but additional ones will require a few more seconds of effort (though it still is seconds, literally).
Download for FREE from here:
https://app.box.com/s/1z0bjs5fm08qe33lf0syl9ty79uye03d
No signup needed!
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Comments
Very nice!
You just keep on giving! Great stuff!
Mental Donkey Games
Website - Facebook - Twitter
Sweet ! Thanks
Complete Guide to iOS Publishing {} Complete Guide to Mac Publishing
@Armelline good job man! (awesomed)
@Armelline good lord that might come in handy:)! Thanks
@Armelline Awesome work.
I have a question though, are custom fonts less processor intensive than the display text behavior? @socks Shed some insight in one of the threads on the display text behavior, so I tried it out by removing all instances of it in regular gameplay, the game was able to run smoothly now{before there would be up to 10 instances of display text running at the same time.}
This means I even removed the score display when the game is running, would a custom font reduce lag considerably, or the behaviors involve be equivalent to running display text.
But anyway, very awesome work here.
It really depends on what you're trying to do. You can put a lot of fonts (with either method) or a lot of display texts on the screen at once and not have a problem. There are tons of factors that play into how a game performs.
I've not run any tests comparing the custom font methods to Display Text behaviours, but unless you're doing changes to the displayed numbers on a very regular basis, it really shouldn't make any noticeable difference either way.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
This is awesome! Very clean. I had my own method of centered scores but I'll have to try this out.
I have a few suggestions though, wouldn't the following changes make things quite a bit less processor intensive?
Add a self attribute of type index to the font actor and call it "div".
Below "set unit number" add a change attribute: self.div to 10^self.digit * 10
turn off the "constrain number image" behavior and use instead the following rule:
when self.image is not ( game.Score % self.div )/( self.div /10)
change attribute: self.image to ( game.Score % self.div )/( self.div /10)
Also, it seems that the behavior constraining the x position can just be a change attribute.
I could be wrong (haven't tested thoroughly--if someone wants to do that, that'd be great) but this certainly works and eliminates the constrains for each actor, in addition to using simpler equations that I imagine are easier for the engine to evaluate. There might even be more savings to be made, I just took a cursory look at it.
@Armelline I see, I just need numbers to display a score that changes every few seconds as the game progresses. I also had a speedometer to show how fast the character was going {ranging from 15kph to 320kph} which was constantly changing. I also had HP displays for the enemies. Removal of all that except for 2 display texts has reduced load time noticeably.
I heard that display text rendering causes lag to the fps, Socks had tested it and I think it might be true. Perhaps custom fonts is a solution. Although I will probably just show the score at the end of the game loop, but either way, I should look into custom fonts perhaps.
I have specifically avoided mod() and div attributes. My intention was to try a different method to the standard one, and use text functions instead. My priority wasn't to make things more processor efficient, it was to make implementing custom fonts easier.
If you wanted you could remove the text functions and substitute the old method, but in my testing it was no faster. So I'm really not sure why it would be worth shoehorning mod() into here. Additionally, using change attributes instead of constrains actually came up considerably slower in my testing. Constrain attributes really aren't as bad as people seem to think. If you put 100 of these custom fonts on a scene all tracking the same number, it won't be the constrain attributes that will lose you FPS, it'll be the spawning backlog that will slow things down (it will be trying to spawn 100 actors at once when a new digit is needed). Obviously in such cases you have no choice but to place every required digit on scene beforehand, but what you'd be doing changing 100 identical numbers at once is another question!
Unfortunately, if you make it a change attribute then the repositioning won't keep up. If you use the same rule as I'm using, there will be instances when the correct change attribute won't trigger. If you add logic to ensure it does, you lose any benefit gained by the change attribute. Again, though, having one extra constrain per actor really isn't going to have a noticeable impact unless you're displaying a lot of digits.
I tested pretty thoroughly, and the only way I found to increase performance was to sacrifice the drag and drop, single actor placed on scene simplicity I was aiming for.
If your game is so active that the tiny gains in FPS from optimising more are needed, you're best of using pre-placed actors and hiding them when not needed. That way is unquestionably faster, but it's not so much faster that it's worth the extra time and effort in 95% of cases.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
If you're just using one of two or five or ten display texts, you really aren't going to notice a big drop in performance. If your FPS is low, the problem is likely elsewhere.
Displaying just two numbers isn't going to affect your FPS at all. Whether you do it with Display Texts, or if you do it with custom fonts. The reason to go with custom fonts is that you want them to look fancier than a display text allows.
There's this obsession on the forums currently about over-optimising. You really don't need to optimise anywhere near as much as people seem to think in the majority of games. If your game isn't extremely active, heavily reliant on physics, or filled with actors, you should realistically be running at close to 60fps regardless. Adding in a handful of display texts or constrain attributes isn't going to change that.
GameSalad can handle a lot more than people give it credit for if your logic isn't a mess.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
@Armelline I'm trying to reply to your post but I've not really used the quote feature before and can't seem to make it do what I want. Is there some secret I'm not aware of? I assumed that highlighting the text I want and then hitting the quote button might do it, but no success. Nor does just hitting the button copy the whole post. For some reason that just gives me this:
Sometimes quoting can be iffy. Just copy the text by hand and stick a > before it.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Just updated my custom fonts template on GS helper with this one that includes centred text!
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
omg. that was a simple drag and drop and one variable change and bam.
Good work @Armelline
You saved me a lot of time!
My Apps
https://itunes.apple.com/de/artist/david-zobrist/id733552276
https://play.google.com/store/apps/developer?id=David+Zobrist&hl=de
Glad it helped!
Don't forget the next release of GameSalad will have custom fonts in it, though. Only bother with this if you're releasing your game imminently.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support