SpriteKit - Scene Scale Mode with No Filter? - swift

I am making a game in SpriteKit for macOS using Swift, and due to my pixel art style, my SpriteKit scene has a size of 384 x 216, and I have relied on my scale mode to fix everything in fullscreen.
I realize that my pixel art becomes blurry with this, so I manually set all of my sprites to have nearest neighbor filtering, and that has worked so far.
The problem is, this gets very tedious, and I now have a SKLabelNode that uses a pixel font, and shows up blurry when in fullscreen. SKLabelNodes don't have an option for nearest filtering as far as I am concerned, and I am wondering if it would be possible to instead of changing textures to nearest neighbor, set it so the scene scales with no filtering at all?

Related

How do I efficiently render a pixelated line?

I am working in Unity2D and have a character who can shoot in all directions. The game has mobile controls and the player will choose his shooting direction with a joystick on the right side.After testing I found it rather difficult to correctly determin where the shot is going to land at. To convey this to the player I wanted to add a sort of "shooting line of sight" to the player. It is moving around the player according to the joysticks position. (As seen in the picture)
Because I want the line to be pixelated (to match the design theme of the game) I cant use the standard LineRenderer component as it doesn't support such pixelated lines. So I started looking for solutions to this problem and stumbled upon Bresenham's line algorithm. After implementing it into the game I knew which x, y coordinates I had to fill with a pixel. Currently every single white pixel in this line is a GameObject with its own SpriteRenderer and a single white pixel as a sprite. In my test scenario up to 400 pixels where rendered at once. I am already using an object pooling system to minimize the performance drag. Moving this line around drops me from around 1100 Fps down to like 200 Fps in the editor. I know it will be slightly better in the build game but I am sure it will take a toll on older mobile devices when enemys, animations etc. are present in the level.
So my question is: Is there a better or more efficient way to render the sprites? Or (preferably) do you have a better idea on how to render this line at all without creating ~300+ GameObjects. (e.g. Shaders (Zero experience), drawing on a texture)
I am grateful for any ideas that lead me into the right direction.

What is the proper way to light a scene for the Hololens?

We have built an app for the Hololens that has 1 or 2 3D characters in the scene at any given time. What is the best practice for adding lighting to an AR scene for headsets like the Hololens? Should the scene be lighted at all?
So here's the thing with the Hololens:
Black is Transparent
This means that any shadows on objects will make the object fade out into transparency when viewed on the real device (the emulator does not show simulated environments). As such, environments should be brightly lit from a source that is a child of the main camera (you may still use a directional light pointing from above angle) and objects should not cast shadows (as it will appear that those shadows are punching holes in objects).
This also means that you will want textures that are brightly colored as well.
Brightly lit (real world) backgrounds will exacerbate the transparency effect (as the Hololens can't reduce incoming light).
You'll likely have to experiment to find something that works best for your project.

Creating layers with different Z-Axis positions in SpriteKit?

The scene
I was wondering about creating
different layers with different Z-Axis values to give more reality like the above picture as it has
1- The green background then
2- The play ground it self then
3- The blurred black trees representing the camera depth of field
So, I thought about Creating the green background then the the black ground with more value of zPosition then the blurred stuff scaled up with more zPosition values, but the problem is when camera moves there is no sense of reality of speed of movement for each layer as they all move together respecting the same positions .
Also I thought about using SceneKit instead as it contains full 3D tools , but the scene is 2D and does not seem to need scenekit.
Thanks in advance as the question seemed too complicated.
Okay, it is figured now.
The answer is gonna be that I put a method that makes the background moves against the camera movement direction with one half or third the camera speed.
As an example
If the camera moves 20 pixels to right , all scene layers seems to be moved 20 pixels to left . So I have to move the background about 8
pixels to right
So all layers seem to be moved 20 pixels to left except that background moved 12 to left, which is slower.

Purpose of mipmaps for 2D sprites?

In current Unity,
For use in Unity.UI as conventional UI ..
for any "Sprite (2D and UI)", in fact it always defaults to having "Generate Mip Maps" turned ON. Every time you drop an image in, you have to turn that "off" and apply.
As noted in the comments, these days you can actually use world space UI canvasses, and indeed advanced users may indeed have (say) "buttons that float over the head of Zelda and they are in the far distance". However if you're a everyday Unity user adding a button, just turn it off :)
In Unity, "sprites" can still be positioned in 3D space. For example, on a world space canvas. Furthermore, mipmaps are used when the sprite is scaled. This is because the mipmap sampling is determined by the texel size rather than the distance.
If a sprite is flat and perfectly scaled then there is no reason to use mipmaps. This would likely apply to your icon example.
I suspect that it is enabled by default for 2D games where sprites will often not be perfectly scaled. To clarify, a sprite does not need to be on a canvas. Sprites can exist as their own GameObject with a Sprite Renderer (not on a canvas.) When this is the case, scaling the camera view will change the sprite's size on the screen resulting in mipmapping due to the texel size changing. This results in making the sprite always perfectly scaled challenging without a canvas.

Unexpected sprite tearing?

I making a 2d game and I am having some very random problems... My sprites are not displaying as they should be. Below is a screen shot of what I see when I run my game. This bug is present in the game window and the scene window, both when the game is running and not running. And the glitch is not because of the tiles being offset (The background is made up of tiles), if you look closely the player sprite is also glitched up. I have tried restarting unity and my computer, one of which has worked. I have been having this problem ever since i started using tilesets (using one PNG image and cropping out smaller sprites by setting the sprite mode to multiple, instad of using just one PNG image where there is only one sprite and the sprite mode is singular). How do I fix this? (BTW I am using Oryx's lo-fi fantasy and sci-fi sprites at www.oryxdesignlab.com)
This happend when your atlas is not sliced correctly. When you making 2D game there are several important things about sprites.
Set Filter Mode to Point
Set Fromat to 16 bit or TrueColor (in special cases)
Make sure that your atlas is sliced properly.
Edit:
Adjust "Max Size" - make sure is value represents number equal or bigger than spritesheet size
The best way in sliceing atlas in Sprite Editor is NOT to use automatic. I got glithes like that in my project too and those steps can eliminate them.
Have a look at your Sprite in the Sprite Editor. I think you can get to it by double clicking.
Your sprites will have sort of boxes around them to identify each individual sprite (if you set your texture to multiple). One of these boxes will not have sliced correctly, and will have overlapped into another sprite, hence why you're seeing what looks like the arm of another sprite in your picture :)