Using custom font in SpriteKit for OSX in swift - macos

So I'm trying to use a custom font "Impact". It works fine if the font is installed on the computer, but if it's not I can't seem to get it to work. I bring in the .ttf file to the project, add it to the info.plist like this:
Impact.ttf
And I've tried multiple methods for using that font on a SKLabel but nothing works. Here's what I've tried:
let restartLabel: SKLabelNode = SKLabelNode(fontNamed: "Impact-Regular")
let restartLabel: SKLabelNode = SKLabelNode(fontNamed: "Impact")
let restartLabel: SKLabelNode = SKLabelNode(fontNamed: "Impact.ttf")
Any ideas? I would really appreciate the help, thanks!

You need to use the exact same name of your font. So if you want to use the Impact Regular font, you need to call it like that:
SKLabelNode(fontNamed: "Impact Regular")
Without the -.

The correct answer is here Custom font in a Cocoa application
It turns out that the app didn't know where to look for the font, but setting the Application fonts resource path in info.plist made it work. I actually left the value blank since the font in just in MyApp.app/Contents/Resources/

Related

Xcode SwiftUI modify extension variable

I have an extension of Color that stores a colour variable. I am currently using this to set the main colour for the whole app, which currently works.
extension Color{ static var colour: Color = Color.red }
If I set it to red everything turns red. But at the moment I have to hard code what colour it will be. I want to be able to modify this colour during runtime.
I have tried to modify the extension at runtime but I can’t seem to get it working and I’m not sure if it allows you to do this. I’m not sure the best way to approach this.
If anyone has anyway of changing the variable in an extension that would be ideal but if there’s another way, any help would be greatly appreciated. If you have any questions or I haven’t explained something clearly ask away.
Thanks so much

how to add font in scss preprocessor?

I am adding a custom font in my project when I am adding this font using normal CSS that time it's working but when I am using this font in SCSS processor CSS that time it's not working.
I am sharing the screen shot of file and console error.
I do not find where I am doing wrong. Please resolve my problem.
The message is pretty much self-explanatory. The issue is you are using = instead of a : to assign the value to the variable. It should be
$roboto-Regular: 'robotoregular';
Don't be so specific with the variable names, variables are meant to hold dynamic data. If tomorrow, you change the font to some other font, using roboto-Regular as the variable name would make no sense. You should use something like
$base-font: 'robotoregular';
$fallback-font: 'Arial';
font-family: $base-font, $fallback-font;

XCode XCAssets and autocompletion

I was wondering if anyone knew if the XCAsset symbols provided in autocompletion can be used in any way, I imagine something but it didn't worked.
Xcode propose all the images, it looks really interesting but if it's just to "show" I would be sad :(
What you're seeing there is an image literal. It's not the name for the image, it is the image — so using one is equivalent to the entire UIImage(named: "icon-stack") call, not just the "icon-stack" string within that call.
If you assign one of these directly to a var or let, you'll see that its inferred type is UIImage (or NSImage if targeting macOS):

BitmapFont in Skin doesn't draw labels correctly

I made a bitmap font using Hiero, called default.fnt and default.png. I can use these as a BitmapFont in LibGDX, and draw text with the font without problems, using font.draw(). But I can't use this font as the default font in a Skin. I've used the uiskin.json file from here(along with the rest of the skin, but I deleted the Droid Sans files before making my own font), because I have no idea how to make one of my own. From what I've read on the Internet, the .json file is correctly set up: it has the line com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } }, which should make the default.fnt the default font for widgets that use the skin. Still, when I run the program, I see this:
There should be a label above the buttons, and the buttons should have text.
If I do this: startGameButton.getStyle().font = font;, where startGameButton is one of the buttons, and font is the BitmapFont created like this: font = new BitmapFont(Gdx.files.internal("uiskin/default.fnt"), Gdx.files.internal("uiskin/default.png"), false);, the buttons shows the text properly. I don't want to do this since it feels too much like a hack.
I'm following this tutorial, but I've had to look some things up in later revisions of his code, because LibGDX has changed since it was written.
MenuScreen.java(the screen where there are problems)
AbstractScreen.java
Also please tell me if there's a better way to make the menu UI, or if you need other files. The uiskin.json is linked above.
Thank you.
I fixed it. The Droid Sans bitmap image existed in two places, it was part of uiskin.png too. I don't know how, but it probably read the font's letters from that file instead of default.png. So in the end I just renamed the font's .fnt and .png(and the file parameter in the .fnt) and did a search-replace inside the skin's .json, and it all works fine now. I don't know exactly what caused it, but maybe default-font is a reserved word or something.
Anyway, it works now. Thanks to Jyro117 for making me think maybe I shouldn't replace the default but add my own font.

Xcode: Cant find rgb color picker for controls

Using Xcode 4.3.2 I am unable to add color values by rgb. The standard picker looks like this
Which does not offer any input for rgb or have any sliders allowing me to set anything else.
The custom picker at this location http://www.panic.com/~wade/picker/ instructs me to install at
/home/Library/ColorPickers.
However home is not editable. So I placed it into
/Users/username/Library/ColorPickers
which does nothing. (Is this correct?) Can anyone explain how to properly install this? Thanks
I use this tool and it works fine, /home is referring to /Users/Username so you did place it in the right folder.
If the tool still isn't working then you will need to restart Xcode and possibly even the computer.
After that you simply open the standard picker in Xcode, it isn't replaced, a new tab is added to it.
Additionally, you can always manually specify RGB values in code, for example:
[myLabel setTextColor:[UIColor colorWithRed:235.2/255 green:150.7/255 blue:35.1/255 alpha:1.0]];
The values are x/255 because UIColor expects a float value between 0 and 1 and this is an easy way to convert the standard RGB 255 values down to 0-1.
I had the same problem, and it's simply that your Toolbar is not showing. Go to View->ShowTool bar and you should now see a tab bar of color picker options. For more information on installing custom color pickers, visit https://developer.apple.com/library/mac/documentation/cocoa/conceptual/DrawColor/Tasks/AddingColorPickers.html

Resources