Mostrando postagens com marcador libGDX. Mostrar todas as postagens
Mostrando postagens com marcador libGDX. Mostrar todas as postagens

quarta-feira, 7 de dezembro de 2011

Make a Game - Sound Effects and Music


First off, sorry for the delay between posts, but I the college semester was ending and I had no time. I'll still write everything I want before the day of the Ludum Dare, I think.

So I'm going to write about sound effects and music for games, trying to display some links and solutions for people who aren't really sound oriented but need to get a quick sound for a game. I'll also explain how I organized music and sound in libGDX.

Music, what to do?
Music is pretty important, of course. A game will become boring without it and it can touch a person's heart when the music is amazing. It's extremely strong in setting the tone in any type of game. Not trying to state the obvious here, but if you can tie in music and gameplay, like playing a faster tone when something action-like happens can really create the moment. Or break it. Look at the moment created here:




I think the video speaks for itself.
So you need to add music to your game. You have three options, really, you can either make it yourself, have someone else do it or use an existing piece. When you're a game company, you'll probably go with "have someone else do it", since they'll be professionals and you can ask them to convey the feelings you wish to pass on. But when you're a indie game designer, you'll want to either make it yourself, if you have some talent and/or experience with creating these things. I don't. I tried messing with some midi files but I got lost.

If you wanna go with music making, I recommend this:

Musagi, music maker
It's pretty beginner oriented. Don't beat yourself up if you can't do it, though. Use free music. Yes, that exists. But you HAVE to be careful, since you have to respect the desires of the authors. Some will ask for a link back, just credits, others may ask for nothing, but you have to respect that, or else you'll be doing something wrong and that is not nice! It may even be a crime.
Here are some sites for music:
Dano's songs, they are cool
Indie Game Music

Sound effects, do I need them?
I used to ask myself that, sometimes. But yes, you do. The experience feels much more bland without those little guys to tell you have made a good choice, if you can't select something or if you killed somebody. In-game, of course. My favorite example for good, well put sound effects are, of course...


 Just pay attention to those genius-like sound effects! Amazing!
So, it's the same as music. If you wanna create some dirty, simplistic old school effects, use this amazing little dude here:
BFXR
It's awesome for making old school stuff, really!
Other than that, you could also get existing sounds, but be careful about the author's wishes and license. Flash Kit has both sounds and music, although it's a little bit hard to navigate.

Flash Kit

If you still need more resources, check this topic in gamedev:
Topic about Free sounds and music in Gamedev

 Sounds and Music in libGDX
That's pretty straightforward, actually. You just load up the classes with the file handlers and call the methods. If you wanna simply grab a code, here is the source code for a class that I use to play and "organize" the sound effects in my game:

SoundPlaying source code for libGDX!





So I think this is it, everybody!

segunda-feira, 14 de novembro de 2011

Make a Game - "Avoiding Game"


So let's talk about our game.

I've put it up on Google Code. You're gonna need a subversion client like Tortoise to download the files. But you can browse the sources code in the web.
If you wanna run the project, you're gonna to import them on Eclipse and fix up some folder problems that will. It's basically properties => Java Build and changing the folders of some Jar files of libGDX. If it doesn't work, just copy the codes in to another project.

Project in Google Code

Screen of the Game. Can Raphael survive this?


So now let me talk about the 3 packages(basically folders) in which I've divided the source code:

Game Package
This package is more libGDX oriented, featuring the Game class and two Screens. The first screen is for the actual game stuff, avoiding the devils and getting the feathers. The other screen is what happens when you lose the game. You can see your highest score yet there and also restart the game.

The main screen will basically draw what the Setup of the Logic Package tells it to draw, and will also send input information to the Setup class.

Logic Package
Handles what actually happens in the game.

  • The Setup class will receive interaction from the Game Package and will handle the main logic of the things, like managing all the beings in the game, including the player. 
  • Every being in the game is an GameObject, which is basically the enemies, the feathers and the player's avatar. 
  • The Board class handles movement of the GameObjects and collision detection
  • The Drawable class holds information on how the objects should be drawn in the screen
  • The GameObjectFactory class allows you to create GameObjects from Beans of the Bean Package. By messing around with this class you can add new enemy behaviors or object behaviors. You could make the feather move around or let the enemy stand still. Anything.
  • The Global class is used to hold the highest score.
  • ScoreListener is an interface to handle changes in score.
  • CollisionResponse is an interface used with collision detection
Collision detection is an important aspect of game programming. It's basically a way of knowing if two objects are touching or not.

In our game, detection collision is pretty simple, since all objects are treated as rectangles, so it's just code that checks if the two rectangles are colliding.

Bean Package
This package holds information about enemies and objects, so the GameObjectFactory can create GameObjects with the properties described by the bean.
The ObjectBean class holds all the possible behavior description for an enemy or an object. By tweaking those objects, the GameObject created later will behave differently.
The SpawnBean holds information about which object beans will be used in the game.

Play with the Code
Mess around with the code, specially the objectBean and the GameObjectFactory, so you can tweak the enemies or create new things.

Understand libGDX and make your own game! :)

Coming up next...
We're going to see sounds next.

Look forward to it!

Make a Game - libGDX architecture

I'm gonna start talking about the basic of libGDX architecture, so you can understand how to program in it better. The tutorials and explanations are a little bit fragmented, so I'll try to unite what you need to know here.

First off, if you don't know Java or Object Orientation, you should at least read something about objects and classes:
About abstraction, classes and objects
Objects, Classes and Interfaces
You need to have libGDX setup too:
Setting up libGDX

The Game and Screen class
The Game class has all the functionality ready to start up a game, it can be used as an effective starting point for your game in general. Basically, the desktop and Android projects call up a method to load an ApplicationListener, which is an interface that allows the game "to be loaded". The Game class is, by itself, a ApplicationListener. By extending the Game class, you're also putting up some extra functionality, like Screen support. It's better than implementing ApplicationListener by yourself, like some examples do.

The Screen interface can be used to describe a screen your game. You can implement this class and then set it to the game class for it to be displayed. This allows you to change screens easily and allows you to organize your code better.

Examples: Screen and Game classes, changing screens and context

SpriteBatch and Textures
This is what you use to draw images. You go to the render method of a Screen, then you start up a SpriteBatch with batch.begin( ), draw, then you call batch.end( ).
There are a bunch of drawing methods to use. What I do, though, is create a texture with an image, and then use the batch to draw that texture. You create the texture inside the show method of the screen and you draw it in the render method.

Here goes a screen code that draws an image devil.png. You're gonna need the image in the assets folder for this to work:

 package game;  
 import com.badlogic.gdx.Gdx;  
 import com.badlogic.gdx.Screen;  
 import com.badlogic.gdx.graphics.GL10;  
 import com.badlogic.gdx.graphics.Texture;  
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;  
 public class CopyOfMainScreen implements Screen {  
      private SpriteBatch batch;  
      private Texture texture1;  
      @Override  
      public void show() {  
           batch = new SpriteBatch();  
           texture1 = new Texture(Gdx.files.internal("devil.png"));  
      }  
      int x = 0;  
      int y = 0;  
      public void render (float delta) {  
           if(Gdx.input.isTouched()){  
                x = Gdx.input.getX();  
                y = Gdx.graphics.getHeight() - Gdx.input.getY();  
                //do something with the input!  
           }  
           Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // This cryptic line clears the screen.  
           batch.begin();  
           batch.draw(texture1, x, y);  
           batch.end();  
      }  
      public void resize (int width, int height) { }  
      public void pause () { }  
      public void resume () { }  
      public void dispose () { }  
      public void hide() { }  
 }  

Handling Input
There are two ways to handle input in libGDX, by polling or by callback events. At this point I'll talk only about polling since it's easier to understand.
You can use the following code to check if the player is, for example, touching the screen, and then getting the coordinates of the touch.
           if(Gdx.input.isTouched()){  
                x = Gdx.input.getX();  
                y = Gdx.input.getY();  
                //do something with the input!  
           }  
Let's say you wanna draw the texture where the player touched, change the render method in your screen to this:

      int x = 0;  
      int y = 0;  
      public void render (float delta) {  
           if(Gdx.input.isTouched()){  
                x = Gdx.input.getX();  
                y = Gdx.graphics.getHeight() - Gdx.input.getY();  
                //do something with the input!  
           }  
           Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // This cryptic line clears the screen.  
           batch.begin();  
           batch.draw(texture1, x, y);  
           batch.end();  
      }  

You need to use getHeight because the coordinate system of the input and the drawing are different, and I'm not sure why.

So, this is it
On another post I'll talk about sound and animations in libGDX, but let's take it one step at a time.
Next, I'm going to show you the code I created for our little game.

sexta-feira, 11 de novembro de 2011

Make a Game - Beginning!


The other articles of Make a Game:


________________________________________________________
This is the Make a Game series, in which I'll go through the entire process of making a game. My engine of choice will be the libGDX. This is me preparing for Ludum Dare of December, so if you follow this, you'll be prepared too! :)

And what is Ludum Dare and why should I care?

Why libGDX? 

  1. It's free
  2. It's Java
  3. It allows me to write a game and get the result in both "pure" Java and Android
So while it's true you won't get any money from the Ludum Dare itself, we'll be looking at ways to make some money with our game :)

Setting up libGDX

First and foremost, you need to setup a project with the engine, and this link below will guide you through it:
Setting up a project with libGDX

Just skip the steps about Android setup if you do not want to work with that right now. It's best to learn how to setup the project by yourself, but I might post a project already all setup for you to jump straight in to development. Kinda.

I can't setup libGDX...
You could download an project already cofigured and go from there!
Try to download one of the open source demos:
libGDX repository Demo projects
You're gonna need a subversion tool, though...
like Tortoisesvn


Play around with libGDX
While I don't get around to writing the rest of the series, why not take a look at some of the tutorials about drawing images?
Drawing images with libGDX

Our next step
We'll start defining what kind of game we're going to make, so we'll take a step back in programming and take a step in design. 

quinta-feira, 10 de novembro de 2011

Ludum Dare and Make A Game series!

What is Ludum Dare?
Ludum Dare is an indie game competition. The rules are simple: make a game, by yourself, within 48 hours, with a given theme!
The prize: a great experience!

Well, yes, there are no cash or other types of prizes, except for your own game. And the knowledge that comes with making it.

Ludum Dare: rapid indeed!
You can read more about the rules and Ludum Dare heere:
The Rules of Ludum Dare

"Can I really make a game in two days?!"
Yes, we can!

I'm going to be entering in my first Ludum Dare this December(from 16th to 19th), and I'm really looking forward to it!

But I need to do some preparing, I need to know more about the engine I'll be using then... The libGDX!
So I've started the "Make a Game" series, in which I'll show the entire process of making a game in libGDX, with open sources codes and exploring various aspects of the entire game design process!

Watch the progress here:
Make a Game Series - Beginning!
Godspeed!

sábado, 5 de novembro de 2011

Getting started developing for Android

So, one day you woke up and decided "I wanna program for Android!", that's actually pretty smart. The mobile market is growing and although some people state the android market in particular is bad (that's an subject for later, though ), I still believe it's a good idea.

Don't know what Android is? http://en.wikipedia.org/wiki/Android_(operating_system) Wikipedia is your best friend!

I have some good news for you. It's absolutely free to start programming in Android. You just need to download some stuff and you can start programming.

You have to begin somewhere

You download the SDK (Starter Development Kit) in the link below:
http://developer.android.com/sdk/index.html 
That little green robot is the Android's mascot. He's not a robot though, he's actually an android. Why did they choose an android to be the mascot? Beats me.

After your download is done (but before installing), go here: http://developer.android.com/sdk/installing.html
You should just follow the procedures in the site and everything should be fine. And before I forget, take the Eclipse path!

About Eclipse:
Eclipse is an IDE( integrated development environment ) that will make your life easier when programming for Android, among other things.
So maybe you like Netbeans( another IDE )? Don't use Netbeans for Android! Google itself supports Eclipse for Android and maybe other IDEs can hold a candle to Eclipse, but if you try using Netbeans and it's plugin, you're inviting headaches. Believe me, I have tried!
If you don't even know what an IDE is, get Eclipse and find out by yourself how much easier it makes your life!

Will problems happen? Maybe. Just comment in the blog and I'll try to help you out!

Some known problems:
  • Try to install the SDK in a folder that has NO WHITESPACES, since that may cause bugs, maybe on the main folder of your hard disk( C: , most likely).
    • The reason for this? I have no idea.
  • You have the JDK(Java Development Kit) but Android SDK Installer says you don't. Well, just hit back once and advance. It should work.

Afterwards you can try to setup the Hello World example.

Ok, now what?

Congratulations if you have setup the SDK, got the emulator running and everything.

Just so you know, Android uses Java as an programming language. I believe that at this point, you have 3 choices:

  • Java is a popular, useful language. Why not program in Android AND some basic Java at the same time? Skip this if you already know some Java.
  • If you want to program any type of application in Android( not just games ), using the native UI( user interface ), maybe get some money in the Android Market, then you should study some basic android:
  • Wanna program for Android solely for games? Then it's better to jump in to a framework straight ahead!
This is Android's native User Interface
But first, what is this native UI that I speak of? It's the default buttons and interfaces that Android comes packed with. You should use them for creating some basic applications, since it saves time and the users are already used to them. You can try to design a game using those things, and while it is possible, it's not a good idea at all, because you'll have little control over rendering (the drawing of your game's graphics), which is BAD, among other problems. And I speak of experience, I've already made that mistake. More about that later, though :D

By using an Framework for games, somebody else has already optimized and organized the way you should handle rendering, input and sound, among other things, which means you'll face less problems trying to design your games and fighting bugs.

One of those Frameworks is AndEngine!

http://www.andengine.org/

Which is pretty well established already and uses OpenGL (Open Graphic Library) , which is a great skill to start picking up. I've never used AndEngine, though. Instead I'm using another Framework... Libgdx.
http://code.google.com/p/libgdx/  
It has a huge trump (for me, anyways)... You program your game once, and it runs on both Desktop AND Android! And since it's Java, that means both Windows and Linux, and maybe anything that has the necessary Java Virtual Machine. Or maybe an Applet straight from the browser? You can do that too! Awesome. It uses OpenGL, like AndEngine.

Frameworks, I'm an expert, I'll make my own!
So maybe you wanna deeply learn Android games mechanics, maybe create your own framework to use in your games, giving you max control and max learning?
Then go program some stuff, get to know a lot about basic Android programmin... And then, start learning about this little guy:
http://android-coding.blogspot.com/2011/05/drawing-on-surfaceview.html

It's called a surface view. It's basically a way for you to control the rendering process completely! If you have this down(you're gonna have to know some threads, so it takes advanced Java), you'll be able to create a good framework. Just search up "SurfaceView Android" on Google and you'll get a lot of stuff.

Uhnnn, I wanna make my own Framework, but...

So maybe you don't know anything about Threads? And you wanna make a pretty good Framework? You wanna have some guiding light? Then I have a book just for you...

http://www.amazon.com/Beginning-Android-Games-Mario-Zechner/dp/1430230428

It takes you step-by-step in to creating a framework in Android and also through creating games(there are 3 game examples made through the book). It's a great read, from the creator of libGDX.

You don't have the money, though? You can still look at his Source Codes as he progresses through the chapters, building frameworks and games:

Look up SVN if you don't already know what it is, to download all the codes at once.

Woosh... I'm tired.

Well, just go program now!