How To Make A 2d Game In Dev C%2b%2b
Games have been made in Unity at all levels of the Video Game industry. If you want to make games, this is a great engine to learn. Learning Unity will teach you the basics for any engine, and if you want to get a job at a big studio there is a chance that you will be working in this engine there as well. I have decided to take a quick detour from my primary game development, to illustrate how to create a more simplistic 2D game using C. I am going to cover it over a number of posts, each building on the last and if you follow along, hopefully at the end you will be well on the road to creating your own games. If you make a JRPG you're learning a timeless game format that modern players are still very receptive to. They make for a great framework to add your own twist and experiment - be that in the narrative, presentation or mechanics. It's a great thing if you can make a game that's still played and enjoyed decades after it's first release!
by Angela He
2 years ago I was just 17 year old high school student who knew nothing about coding. But I pushed forward anyway, and within a few months I published my first game on Steam.
Now, I’ve made over 10 games for desktop, web, and mobile, with over 1.9 million plays combined.
No matter your skill level, you can make a game too. 2 years ago, I thought it was impossible, but tried anyways. It was the hardestthing I’d ever done. But it was worth it. Now, I realize game development is like any skill — you only get better by doing, failing, then improving.
I taught myself everything I know. And now I’m going to teach you.
To make a game, you must go through the 6 stages of game development: Design. Art. Code. Audio. Polish. Market.
The rest of my post will structure each stage into the following:
- ?Advice I’ve curated from my and others’ experiences.
- ?Resources I’ve found most helpful.
1. Design ?
Advice?
You’ve got a great idea. *
But how do you capture it in writing?
Everyone’ll have their own way of doing that best. Some compose 60-page design documents. Others, like me, write a page of badly-written notes, unreadable to anyone else. I don’t know what’s best for you. But I can give suggestions on what to write about:
- Hook. What makes your game idea great? For me, this is the most important to write down. Once you capture this, you can write down the next three points much easier. Is your game about something thought-provoking? Scandalous? Is it putting a new twist to an old classic? Or, is it doing something that’s never been done before?
- Mechanics. What does your player do? And for what purpose? This is your gameplay. It can be as simple as pressing QWOP to move in the game QWOP, to tapping buttons to chat in Mystic Messenger, to the tons of key combos in Dwarf Fortress.
- Story. What story should players remember your game by? What emotions should they leave your game with? Every game has a story. If the story isn’t obvious, it is created by the player. A story can be created from the increasing numbers in 2048, the rising empires in Civilization, and the silent interactions in Monument Valley. Think about what story’ll be found in your game.
- Mood. What impression does your game make? What are the visuals? Sound? First impressions matter. First impressions will hook — then keep — the player playing. Perhaps, you’ll give your game a retro vibe with pixel graphics and chiptune music. Or, a modern, clean look with flat geometries and instrumentals.
* Having a hard time thinking of an idea? Creative block hits us all.
- Join a game hackathon/jam. You and other participants’ll be tasked to make a game in a short amount of time. Throughout, and after, you’ll be met with support from other jammers. And the excitement and creativity during a jam? Infectious. Don’t know where to get started? Try Ludum Dare, one of the largest game jams.
- Keep a list of ideas. I and other developers I know jot down our ideas. That way, we can refer back to our old ones when we run out of new.
When the muse hits, stop whatever you’re doing. Write that idea down. The next time creativity ghosts, you won’t be left grasping for straws.
Resources ?
All of the below are tried and true. (?) means I use it currently.
Note-taking:
- Notes for Mac (?)
- Google Docs (?)
- Trello
Collaboration (for teams):
- Google Drive
- GitHub (?). Requires git and Unity .gitignore.
- Unity Collab. Easiest out of the three. The free version has limitations.
Heads up — Unity is the game engine I use to make games, so I’ll be mentioning it throughout. Feel free to use a different engine.
Game design:
2. Art ?
Advice?
You’ve planned out your idea; congrats, that’s amazing! Now, you can work on the actual game.
(If you don’t know how to code, I suggest doing stage 3, Code, before Art. You don’t want to create art that you’ll trash later because you can’t code it in.)
Don’t know how to draw? Do not fret. Anyone can make something beautiful with the 3 basic visual principles: color, shape, space.
UI
Think about how you can make it unique — have a distinct color scheme, font(s), shape(s), and icon(s) — while functional. Is the important information readable and obvious? Do the colors/fonts/icons distract from that at all?
2D animations
You have two options:
- Frame-by-frame.Draw out each frame of the animation. For this, you should use sprite sheets with TexturePacker (or if you’re using Unity, Sprite Packer).
- Bone-based.Draw each animated limb, then animate the limb’s position, rotation, and whatnot in-game. Can be faster, easier, and save memory. If you’re doing 2D and using Unity, try editing the pivots of sprites or Anima2D.
Misc
Here are some general miscellaneous art tips that apply to not only art in games, but in other software as well.
- Tile patterned assets to create tiled images and save memory.
- 9-patch/9-slice assets with unscalable borders but a scalable center to create scalable images and save memory.
- Make the dimensions of each asset a multiple of 4or a power of 2 to save memory. Which one depends on how you’re compressing the assets.
- If you’re using Photoshop, use “File > Export > Layers to Files” to quickly export each layer as a file (e.g. PNG, JPEG).
Resources ?
Creating UI:
- Photoshop (?).
- Sketch.
UI principles:
- Google Material Design (?).
- Apple’s UI Do’s and Don’ts.
Creating 2D assets:
- Photoshop (?).
- Gimp.
- Paint Tool SAI. Good for smooth/anime styles.
Creating 3D assets:
- Blender (?). Powerful but steep learning curve.
- Maya. Good for animation.
- Max. Good for rendering.
Free assets:
- Behance (?). Fonts + icons + other designs.
- KennyNL. HQ, game-ready UI/2D/3D art.
- Open Game Dev Art. Large library of user-generated art.
Inspiration:
- Dribbble.Designs from invite-only designers.
- Behance (?). Designs from anyone with an account.
- itch.io (?). Beautiful indie games.
3. Code ?
Advice?
Your first step? Decide on a game engine and an IDE (Integrated Development Environment — basically, an app that lets you code). My recommended game engines+IDEs are in Resources below.
Your second step? Code.
Don’t know how to code? No worries. I got you. You can learn.
These CS fundamentals should be enough to start. (All code examples here are in C++, one of the main languages the Unity 3D game development framework uses.)
1) Data types and variables. At the root of all code is data. That data is stored in variables.You can declare a variable like this:
Let’s break that down.
int
is the data type. i
is the variable name. And that = 0
assigns zero as the variable value.
So what’s this?
string
is the data type. s
is the variable name. And yep — you guessed it — “pusheen is best cat”
is the variable value.
Some common data types: int
and long
are integers
. float
and double
are decimal numbers. And string is any sentence. (Even an empty one — “”
!)
Want to know more? Go through this and this.
2) If statements. If statements evaluate if a certain condition is true. If it is, run the code that’s inside the if
statement:
If the condition isn’t true, we can evaluate other conditions with else if
:
Or, just run some other code with else
:
3) For/while loops. While loops continue while a certain condition is still true, executing the same lines of code over and over again. When the condition is false, the while loop exits.
Think: how long does this while loop last?
For loops are basically while loops where:
That’s equivalent to:
4) Basic data structures. So, we have data, and we ways to evaluate and manipulate that data. We can also store that data into some structure — a data structure. Data structures you should know are arrays, lists, queues, stacks, and sets.
Here’s a quick example of an array:
To solidify your knowledge of 2–4, go through this.
5) Functions and exceptions. Functions are basically a small line of code describing a big bunch of code. For example, if you call:
And EatBread() looks like:
Then the call to EatBread()
is actually a call to the two statements within the EatBread()
function.
If you do something bad in your code, an exception might get thrown. They’re angry red errors there to tell you, hey, back up, what you did right there just ain’t ‘workin out logically. Go revise it.
To learn more about functions, go here; for exceptions, go here.
Then, there’re other things you should know:
6) Language. What language are you going to code in? C++? Javascript? C#? Every language is written somewhat differently and can let you do different things.
7) API (Application Programming Interface). Once you know the basics, you’ll have to learn the specific API of your game engine. APIs are essentially a bunch of powerful tools wrapped in simple classes and functions that you can call. APIs make life easier. Way easier.
Lastly:
8) Look at an example project in your chosen game engine.Unreal and Unity both have a ton of free example projects. This’ll let you discover how everything comes together. Plus, you can build your game idea off of the project. (I built my first game off of Corgi Engine.)
A word of encouragement: I know. Coding is scary at first. Nothing makes sense, you’re hitting constant roadblocks, and you might want to quit in the face of failures and exceptions. It doesn’t mean you’re bad at coding. Coding is challenging. It’s understandable to feel incompetent at first.
![How to make a 2d game in dev c 2b 2b 1 How to make a 2d game in dev c 2b 2b 1](https://blogs.unity3d.com/wp-content/uploads/2019/03/image27.png)
But it just takes time, like any other skill. It’ll get easier. And it’ll get fun (at least, it did for me).
Important game programming concepts:
- Object orientation.Makes programming feel more natural.
- Naming conventions.Name your classes, methods, and variables as something that obviously conveys its purpose. For instance, a melee attack function should be named meleeAttack(), not mA() or protecbutalsoattac(). You (and others who read your code) should know what’s going on.
- Decomposition.Put code that repeats itself into a separate function. Call that function instead of duplicating the repeatable code.
- Singleton design pattern. Allows data that a lot of things need to be stored in one place.
- Static avoidance. Beyond singletons, I’d avoid making static variables— their lifetime is the game’s lifetime, they’re slower, and they can have unexpected behaviors in the editor.
- Observer design pattern. Allows things that must happen depending on another thing to not waste the computer’s time checking that other thing.
Important Unity-specific things:
- Coroutines.IEnumerators and Coroutines allow you to start doing things, continue doing things until some time has passed, then stop. I use them all the time: for bursts of visual effects; for lerping movement; for waiting for a scene to load before grabbing the scene’s objects.
- ScriptableObject.These contain data with less overhead than MonoBehaviors.
Resources ?
Game engines:
- Make your own. Requires C/C++. Low level. Really, really low.
- Unity (?). 2D/3D. Requires Javascript/C#. Mid-level. Cross-platform.
- Unreal Engine. 2D/3D. Requires C++. Mid-level. Cross-platform. Notes: 2D support is not great.
- pixi.js (?). 2D. Requires Javascript. Mid-level. Web.
- GameMaker Studio. 2D/3D. Requires GML. Beginner level. Cross-platform.
- Corona. 2D. Requires Lua. Beginner level. Cross-platform.
IDEs:
- Visual Studio Code (?). For MacOS. Gives me no lag and has awesome, VSCode-exclusive features (such as inline reference info, quick navigation (⌘T)).
- Visual Studio (?). For Windows.
- MonoDevelop. Comes with Unity. Tends to lag.
Free Unity assets:
For Unity, tons of free assets exist on the Unity Asset Store, GitHub, bitbucket, and other sites. I use at least 2 in every project. Make your life easier with assets, but realize they’re not perfect. If you spot mistakes, don’t hesitate to fix them and/or ping the developers.
- TextMeshPro (?).
- LeanTween (?).
- Fungus.
- Dialogue System.
- Keijiro Takahashi.Works at Unity. Has amazing open source Unity visual effects projects!
Last but not least, my #1 solution for coding problems: Google!
4. Audio ?
Advice?
First: Do you want audio?
Audio can do wonders Doli saja ke episodes. for immersion and mood. But, it can cost memory.
If the answer’s yes, what audio?
Will you include music? Sound effects? Voiceovers or narration?
For any of the above, record and mix them in a way that matches your game’s mood. For example, Bastion uses organic mouth and instrument sounds, matching its game world. Crypt of the Necrodancer uses a blend of electronic beats and chiptune rock to match the colorful, rhythmic game.
“Immersion is king.”
-Darren Korb, Supergiant Games
If your audio doesn’t match your game’s mood, it could detract from immersion. How will your audio match your game?
Resources ?
Audio tools:
- Logic Pro. $200. MacOS only.
- FL Studio (?). $99–899. Has free demo.
- Reaper. $60–225.
- Audacity (?). Free. Limited capabilities. Useful for cleaning audio.
Retro sound effect generators:
- Chiptone.
- Bfxr.
- Leshy SFMaker.
- as3sfxr.
Free sounds:
- Soundcloud (?). Soundcloud has a ton of gorgeous gems under Creative Commons (CC). Here’s a playlist to get started. Make sure to provide attribution if needed.
- Incompetech (?). CC music. Must attribute.
- Bensound. CC music. Must attribute.
5. Polish ?
Advice?
Hey! You’re here! You made it; that’s absolutely incredible (I’m serious, if you get this far, I’d love to hear about your game; hit me up)!
You’re done. right?
Well. There’s a 99.99999% chance there’re bugs.
It’s time to bug test.
Bug testing your game
- Get others — not you — to play it. Preferably in front of you, because if they encounter a bug, they might not realize or have a hard time describing it.
- Play it on all targeted platforms. It may work in the editor, but does it work where it matters? For Linux and the different versions of Android especially, I find that things get a little wonky.
Alright. You’ve found a bug. What now?
- Check the console for exceptions. Found one? Great! Find the file and line number where the exception was thrown. If the exception sounds like something from Mars, Google it and learn about it. Then figure out why that line number is throwing that exception.
- Still can’t figure it out? Write to console. Start tossing in them log statements in the place(s) you think is causing you trouble. Print variable values, and see whether what’s printed is what’s expected. If not, fix that.
- When worse comes to worse, check logs. The logs of your project will give you way more info than the console. Read the last lines where the exception occurred. Google anything you don’t know. Can you fix it now?
- Sleep. It’ll get fixed in the morning. This is just a bad dream. Right? ?
Common errors
- NullReferenceException.
How To Make A 2d Game In Dev C 2b 2b 4
Problem: You’re doing a thing on a null (nonexistent) variable.
Quick fix: Check if the variable is null before doing the thing.
- SyntaxErrorException.
Problem: Your code has invalid syntax.
Quick fix: In the Exception message, it should tell you what character is throwing the error. Change that character.
Note: If the character is a double quote, make sure you’re using dumb quotes instead of smart quotes:
- Pink or black screen.
Possible problem: Some shader can’t render.
Possible causes: You’re using a 3D shader for a 2D game. Or, you’re using some shader feature unsupported by the target OS. Be sure to use mobile shaders for mobile games.
After you’re done debugging, polish your game off by optimizing its memory usage and performance. This’ll make it download faster and heat up people’s devices less.
General optimization tips
- Set the target frame rate. The frame rate could be 20 for a visual novel or 60 for a first-person shooter. A lower than default target frame rate allows the game to spend less time rendering frames.
- Animation / particles / occlusion culling. Culling means that things invisible to the camera aren’t rendered. Characters’ll only animate, particles’ll only update, and 3D models will only be rendered when in view.
How To Make A 2d Game In Dev C 2b 2b 3
- Compress textures and audio. Crunch compress textures.Stream music and decompress sound effects on load. Decrease the audio quality. Note that compression may or may not decrease the quality of assets noticeably.
- Object pooling. Avoid instantiating and destroying many objects at once to prevent huge spikes. Instead, object pool them in a List, Queue, or other data structure. Things like bullets should be object pooled.
- Don’t let raycasts hit things that don’t need input.Raycasts are like little rays that shoot from your fingers or mouse everytime you tap or click. Remove objects that don’t react to those inputs from raycast calculations.
If you’re up for a challenge:
- Optimize shaders. Give each renderer a material. This’ll save resources in the beginning since the game doesn’t have to create new materials for everything. Have the shader for the material only include what’s functionally needed (for example, a button that doesn’t need masking can use a Sprite shader instead).
- In Unity, Use AssetBundles instead of Resources.AssetBundles will save memory by pulling from online (e.g. dropbox) or local storage (e.g. hard disk). I haven’t tried too much due to the poor documentation, though.
Resources ?
All of these are from Unity but can be applicable to other engines.
Scripts:
- Optimizing scripts in Unity games (?)
Art:
- A guide to optimizing Unity UI (?)
- Art Asset best practice guide (?)
![How to make a 2d game in dev c 2b 2b 1 How to make a 2d game in dev c 2b 2b 1](https://i.ytimg.com/vi/44djqUTg2Sg/maxresdefault.jpg)
Memory:
- Reducing the file size of your build (?)
Platform-specific:
- Practical guide to optimization for mobiles (?)
- WebGL performance considerations (?)
- Memory Considerations when targeting WebGL (?)
6. Market ?
Advice?
Congrats! ?? You’ve made something. It’s time to show the world what you’ve made.
Personally, marketing is my most anxiety-inducing stage. If you, too, get doubtful, the game developer community is helpful. You’re not alone in this. And you’ve come so far — might as well get through to the end, right?
You’ll never know if it’ll be a hit unless you try.
- Draft. Create drafts of your game page on all your targeted game distribution platforms. Find a list of platforms in Resources below.
- Network. If you go the full networking mile, you’ll want toemail game press, showcase in festivals, and attend conferences.
With game press, email your unlisted game page a week before release. Give people some time to write about it. It’s likely they won’t write about it at all. I’ve found that press loves a compelling developer story, unique/controversial concept, and, most importantly, a presskit.
How do you find emails? You can.
- Find writers you like and Google their name. Their email is bound to come up somewhere: Twitter, LinkedIn, etc. Or.
- Find the magazine/new’s company-wide email on their About page. It’s usually in the format of tips@company.com.
Do not email press about your game if they explicitly don’t cover your genre/targeted platform.
Festivals can get you awards and/or professional recognition by other developers and press.
Conferencesare what you make of it: they can be all about networking with other developers, companies, and press (go get them business cards!); updating your latest game dev know-how; playing others’ games; or meeting up with internet friends.
Game conference tickets are expensive. If you’re a student, think about applying for scholarships for them. The IGDA Scholars program gives you some especially amazing networking and event opportunities.
3. Youtubers/Streamers. You can get video coverage of your game by:
- Ranking high on game distribution platforms.
- Emailing. If you email, don’t talk about yourself; talk about the game. Keep it sweet, short, and compelling. Use eye-catching photos and gifs.
How do you find emails? Look at their About page. If you can’t find it there, Google them and see if their other social media have it.
4. Social media.
Social media is an amazing marketing tool. Agar.io found its rise from 4chan, Butterfly Soup got mad boosts from Twitter, and some form of social media always ends up in my top 4 referrers:
My favorite social media platforms for marketing are in Resources below.
A last note — Publisher or self-publish? Game marketing is a lot. Do you want a publisher to take care of all that? Want to go the Hotline Miami x Devolver Digital route, or rely on Farmville and Doki Doki Literature Club’s word-of-mouth?
With a publisher, you’ll have to do your research to find a good one. After, you’ll sign paperwork and go through legal hoops. Plus, it’s a huge financial investment.
By yourself, you’ll have to put a lot of time and effort into learning marketing. You may love it. You may hate it. And you might not do a great job of it, either. But it’s free, and you learn valuable skills.
For me, I’ll always self-publish. I love learning new things. Also, I firmly believe that a truly great game will succeed no matter what, as long as some marketing effort was put.
6. Hit that Publish button!
??Yooo, you DID it!! ?Now relax, sit back, grab a yummy drink, and take some time for yourself! You’ve worked so hard. You deserve it.
And remember that, even if your game doesn’t get the reception you expected, that’s ok. It’s not gonna be perfect your first time. My first game on Steam only has 255 downloads.
The facts are, you made a game. You learned so much. That’s enough.
And there’s always a next time!
Resources ?
Game distribution platforms:
- Steam (?). PC. Requires $100 USD fee per game.
- Origin. PC.
- GOG. PC. Free to publish. Game must get accepted.
- Mac App Store. MacOS. Requires Apple Developer account.
- itch.io (?). PC/Web. Free to publish.
- Game Jolt (?). PC/Web. Free to publish.
- Armor Games (?). Free to publish. Must apply to be a developer.
- Kongregate (?). Web. Free to publish.
- Newgrounds (?). Web. Free to publish.
- GitHub (?). Web. Free to publish on your own site with domain name formatted as “___.github.io”.
- Amazon.Web/Mobile. Free to publish.
- Google Play (?). Mobile. Requires one-time $25 USD fee.
- iOS App Store (?). Mobile. Requires Apple Developer account.
Game press:
- FreeGamesPlanet. Super nice admin.
Game festivals:
- Independent Games Festival (IGF).Deadline around October.
- Indiecade.Deadline around May/June.
- Swedish Game Awards.Deadline around July.
- South by Southwest Festival (SXSW). Deadline around December.
- The Game Awards.Deadline around November.
Game conferences:
- Game Developer’s Conference (GDC). San Francisco.
- Penny Arcade Expo (PAX). Seattle/Boston/Philadelphia/Melbourne.
- Electronic Entertainment Expo (E3). Los Angeles.
- Tokyo Game Show. Japan.
- Steam Dev Days. Seattle. For Steam developers only.
Emailing:
Social media:
- reddit (?). Pick an appropriate subreddit. Some of my favorites are /r/WebGames,/r/IndieGaming/, and /r/visualnovels.
- Facebook (?). Post on your Facebook Page (if you have one) and personal facebook (if you’re comfortable). There’s also tons of Facebook Groups where you can show off your game! Here’s some:
GameDev Show and Test
Welcome to GameDev Show and Test - a sister group to the Indie Game developer groups. The purpose of this group is to…
Indie Game Developers
Independent Game Developers group for small companies and individuals designing and publishing their own games. **READ…
Indie Game Promo
Indie Game Promo has 47,645 members. Sister group to Indie Game Dev and Indie Game Chat for the purpose of promoting…
- Tumblr (?).
- Twitter (?). Try using tags like #gamedev, #indiedev, and #screenshotsaturday to get discovered.
Community:
- /r/gamedev (?).
- Ludum Dare (?).
- Indie Game Devs (?).
Conclusion
There’s no cheat code to making a game. It’s just a lot of determination and effort.
“Behind every Half Life, Minecraft and Uncharted, there are OCEANS of blood, sweat and tears.”
— Ken Levine
You’ll get confused. You’ll make mistakes. You might even cry (I did—and still do).
But that’s okay. It means you’re growing. If you‘re putting in that much effort, I believe in you and your game: You can do it.
If you liked reading my first article, be sure to give a ?(or several — did you know you can give more than one?) It’d mean the world ?
You can also follow/DM me on Twitter, Tumblr, and GitHub, and buy me a coffee if you wish.