Game Dev for�Business Developers
Dylan Wolf
@dylanwolf
My background
Dylan Wolf
@dylanwolf
How I thought it was going to be...
Step 1: You already know this:
Step 3: Profit:
Step 2: ???
How it actually works...
Already know how to do this:
Web, Desktop, or Service Development Patterns
With this:
Game Development Patterns
(not really useful in learning)
(helps with learning)
(used to write code for)
So what’s different?
The Game Loop
You’re probably used to this...
Web request
Web response
Database read and/orwrite
Render HTML, JSON, XML, etc.
Button click�(or other UI interaction)
Event handler
Model or UI change
Service begins processing task
Database or message queue reads
Database write
Processing
Client-side Javascript
More or less event-driven.
How games work...
Player presses a button
Sprite begins moving
Sprite moves a little farther
Sprite moves a little farther
Sprite moves a little farther
Sprite moves a little farther
Sprite moves a little farther
Sprite moves a little farther
Player releases button
Sprite stops
A simple game loop
Draw
Update
(Happens 30-60 times a second)
Can have events, but not really event-driven.
A more complex game loop (Unity)
Awake()
Start()
FixedUpdate()
Trigger/Collision events
Mouse events
Update()
LateUpdate()
Render events
OnDestroy()
(physics updates)
(input updates)
(internal init)
(init with other components)
Game Loop
Events in Unity
They exist, but they’re not all created equal.
1 frame = 1/60th of a second
Let’s go back to this example...
Anything that runs over a long process needs to be broken up into tiny pieces.
Player presses a button
Sprite begins moving
Sprite moves a little farther
Sprite moves a little farther
Sprite moves a little farther
Sprite moves a little farther
Sprite moves a little farther
Sprite moves a little farther
Player releases button
Sprite stops
Converting to frame scale (Unity)
Timers (Unity)
Coroutines (Unity)
Frame-to-frame state changes
Necessary for components to track this in order to make big-picture features work.
Examples:
Button is up
Button was just pressed
Button is down
Button was released
Button is up
Touch began
No touches
Touch moved or paused
Touch ended
No touches
How I learned to stop worrying�and love GUI editors
I’ve been burned by GUIs before
But...
This is all XNA gives you by default.
Draw
Update
What do I get with a GUI like Unity?
You can go even further...
Some tools have no-code workflows like PlayMaker for Unity
What do I lose with a GUI like Unity?
Is it worth it?
Maybe.
I find I’m more productive with Unity than I ever was with XNA, but YMMV.
Performance
Performance probably doesn’t matter to you
At least, not at first.
TL;DR: You can learn patterns for better performance as you go, as necessary.
Garbage collection
In managed code like .NET and Java, cleans up objects that are no longer referenced.
It’s the price you pay for not having to manage memory yourself.
Garbage collection on desktop or server
In this environment:
So:
Garbage collection on XBox 360
In this environment:
So:
So what’s the solution?
Profiling
Questions? Comments?