Salomonsson.se
Oct 01 2014

pixel perfect tiles in unity

I was wrestling a bit with how to get my tiles 1:1-scale. Turns out this is the way to go:

  • Set camera to orthographic (2d), and set the size to screen height/2. Since I optimize for PS Vita screen (960×544) that’s 272.

  • Now the tiles are super tiny. That’s because I created the vertexes with 1 unit as spacing. My tiles are 64×64 so I can either re-write all my vertexes (multiply them with 64). OR we can keep the 1-unit vertexes and divide the camera size (272/64 = 4.25)

Bingo! Will probably cause some problem when I have to move my sprites by 1/64 per pixel… That’s future Tommy’s problem though =) Oh, and if you have a dynamic size of your screen you can use Screen.height;

Edit (2016-12-14): here is a good blog post from Unity about pixel perfect 2d in Unity: https://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/

Sep 30 2014

drawing a custom 2D tilemap

I have a really simple/stupid demo today. It is however a little bit more awesome behind the scenes as I render the tiles to a mesh programatiacally in Unity. I used most of the stuff from this really awesome tutorial http://studentgamedev.blogspot.se/2013/08/unity-voxel-tutorial-part-1-generating.html (but I left off in part 2 when he started with custom meshcolliders. That was after I found out that Unity has a 2d Edge Collider…. NICE!

For some docs on Unitys mesh: http://docs.unity3d.com/ScriptReference/Mesh.html

And a simple demo (arrow keys to scroll)

Sep 28 2014

2D Sprite Animations Part 3 (Completed)

I’m done witht the Tutorial now that I’ve spent the last week working on. << Click to play >> (req. Unity Web Player)

It was a very good tutorial, and I think it was good to make a complete project from start to end, including different screens, win/lose-conditions, sounds and publish settings. Highly recommend that tutorial for anyone who’s new to Unity!

I also found a cheat sheet to the keyboard shortcuts in Unity. Good one to note is Ctrl + P to test the current scene. http://blogs.unity3d.com/2011/08/24/unity-hotkeys-keyboard-shortcuts-in-unity/

Sep 25 2014

2D Sprite Animations Part 2

Tired tonight. Only got one new part of the tutorial done, but it’s one long part left. Will have to be tomorrow: http://www.raywenderlich.com/71029/unity-4-3-2d-tutorial-scrolling-scenes-and-sounds

The tutorial so far is actually really good! It goes a bit out of line in name of teaching, but I guess that’s ok. There is no way I’ll be able to enter in that miniLD, but I guess that’s ok too. Better to go through a few of these tutorials instead and get to know all the quirks of Unity instead of trying to learn by bashing my head against it. As soon as the tutorial is complete I’ll post a link to the final game.

Oh, and note to self: I really need to get more familiar with MonoDevelop. It works when I copy-paste code from a website, but some methods just seems like they won’t autocomplete at all, like the

void OnBecameInvisible() {}
void OnBecameInvisible() {}

I also need to figure out the keyboard shortcuts for starting the game instead of having to click on that tiny button. Peferablydirectly from MonoDevelop.

But this is a common frustration when starting with a new editor =)

Sep 24 2014

2D Sprite Animations Part 1

Ok, unity has a lot of new stuff to cover. Today I started from scratch with a simple 2d-tutorial. It turned out to be quite good, covering sprites, spritesheets, animation and animation controllers. Good stuff!

http://www.raywenderlich.com/61532/unity-2d-tutorial-getting-started http://www.raywenderlich.com/66523/unity-2d-tutorial-animation-controllers http://www.raywenderlich.com/66345/unity-2d-tutorial-animations

I’ve still to cover the very last part found here (http://www.raywenderlich.com/70344/unity-2d-tutorial-physics-and-screen-sizes), but now it’s time to get some sleep.