Introduction to Unity Sprite Shapes
Using Unity’s Sprite Shapes, making 2D environments has never been easier. Best of all, you can get get started with just a couple of sprites! By Ajay Venkat.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Introduction to Unity Sprite Shapes
30 mins
- Getting Started
- Creating the Sprite Shape Profile
- Setting up the Platform Sprite Shape
- Setting up an Angle Range
- Editing Sprite Borders
- Creating Decorations with Sprite Shape
- Creating a Ground Sprite Shape
- Creating Multiple Angle Ranges
- Adding a Fill and Corners
- Adding Sprite Shapes to the Scene
- Creating the Ground Shape Using the Tools
- Applying Collisions to Sprite Shape
- Finishing up the Scene
- Adding Platforms to the Scene
- Applying Decorations to the Level
- Tying up Game Elements
- Where to Go From Here?
Applying Decorations to the Level
Everything works fine, but to spice up the scene you need to add some background decorations. Add another Sprite Shape GameObject to the scene and call it Tree Decorations. Ensure that the Sprite Shape is Open Ended and it is using the Tree Decorations profile.
This Sprite Shape can be tiled on top of the different grounds and platforms to add a pleasant backdrop. You attached three different sprites to the Tree Decorations profile. Two types of trees and an empty sprite, using the sprite index you can toggle between these sprites.
If that variation isn’t enough, you can also play with the height property of each node. First place the nodes roughly matching the outline of the Ground Object.
Add a few nodes in between and change the sprite index to create more variety.
Slightly change the height of some of the nodes to make it seem less repetitive. You may have to adjust the position of the node to set the sprite back on the ground.
Repeat the process of adding new decoration Sprite Shape GameObjects with the Tree Decorations profile for each ground and platform. Once you’re done, the scene should look something like this:
You should be proud — that is a beautiful looking scene created with just a couple of assets! :] Time to tie everything up with some awesome gameplay elements.
Tying up Game Elements
Before adding any enemies, clean up the Hierarchy by grouping the ground objects and platform objects. Make the decorations a child of the platform or ground they are on so that if you move the ground, the decorations will move with it.
You may have noticed the timer in the top-left; this is to see how quickly you can finish the level. The timer will stop when you reach the end. To add the finish, drag the Flag from RW/Prefabs onto the Floating End Platform.
The Flag represents the sweet taste of victory when you press the Play button and everything works fine, but you don’t live in a perfect world and there are always errors blocking the way.
Drag the Enemy from RW/Prefabs onto the Ground Object. You will notice a horizontal green line going through the Enemy; this is the path that the Enemy will patrol. You can modify this path using the Left Point and Right Point in the Enemy Controller.
Duplicate the Enemy and strategically place it around the scene to give yourself a challenge (group the enemies together under an empty GameObject to keep the Hierarchy organized). Modify the path of the enemy to suit the ground that it is on. Your scene should look something like this, with all the enemies:
To win, you have to reach the flag at the end; if you touch an enemy you will die but if you jump on top of the enemy you can destroy it.
Press Play and control your coffee-powered programmer to a successful build, crushing all errors in your path!
Can you do better than 15 seconds?
Where to Go From Here?
You can download the complete project using the Download Materials button at the top or bottom of this tutorial.
In this Sprite Shape tutorial for Unity, you learned how to:
- Install and configure Sprite Shapes.
- Create and modify Sprite Shape profiles.
- Work with Sprite Shape tools to create close- and open-ended shapes.
- Use the given tools to add variation using limited sprites.
This project is only the beginning; there is so much more you can add. I’m interested to see what you come up with!
Did you enjoy this tutorial? Want to learn more? Check out our book Unity Games by Tutorials, which has more info on making games with Unity.
If you want to learn more about Sprite Shapes, check out this tutorial by Unity or go to the Sprite Shape forum.
If you have any suggestions, questions or if you want to show off what you did to improve this project, join the discussion below.