Note: I've searched through existing answers but can't really find something from this perspective. Please comment if you find a duplicate.
I've been working in development for many years, but I have no (zip!) experience of game/graphic development.
Like many others I thought it would be fun to try to write a small game for Android. However I can't really picture the steps needed to create the simplest of animations.
For instance, say I wou开发者_JAVA百科ld like to draw a small vehicle moving over a landscape or map. I wouldn't really know where to start.
I guess I would need to draw every single frame of how the car looks as it drives, i.e. spinning wheels, some twitching etc. Is this basically it? - Drawing 10 images in paint and then looping them? Next Q would the be - how to loop them? I would guess there's some kind of animation object/system which I load something into and then run? This probably varies between platforms and sdk's, but I also suspect the principles usually are the same, just like the principles of most widget/gui systems.
Then I guess the car needs to be animated as moving over the map. And this animation runs in paralell with the other animation?
.. etc. etc. This is really a question of the fundamentals of simple game animations. There's some work flow which is common in all games, i.e. someone who wrote games for iphone still knows most parts of how to do the same for android.
To perhaps state the obvious, I'm not looking into 3d animation or anything requiring advanced physics, advanced math, matrix, mesh-stuff etc. I'm only interested in the kind of graphics you for instance see in tower defence games (like "Robo Defence"), platform, "diablo"-games etc.
Thanks.
In a GUI/Widget application you will typically have an event loop which calls back into your code when the user clicks on a button or moves a slider or whatever.
In a typical game you will have a game loop, which will repeatedly poll the input, drive the state of the world forwards one step on the basis of that input, and then draw the state of the world onto the display. For example (in C++ because it is the language that I am most comfortable with):
//Holds everything in the game: the locations and velocities (and so on)
//of all the dynamic elements, the map, the terrain, everything.
WorldState worldState;
while (worldState.continueGame()) {
Input input(InputSystem.pollInput());
worldState.advanceByFrame(input);
OutputSystem.display(worldState);
sleep(1/stepTime);
}
I hope this gives you an idea, but don't think that this is good enough for an actual game loop. The timing code in particular is rather broken.
If you wanted to have a vehicle that moved over terrain, then you could implement WorldState like this:
struct WorldState {
void advanceByFrame(Input const& input) {
vehicle.moveOver(terrain);
}
Terrain terrain;
Vehicle vehicle;
};
struct Vehicle {
double xPosition;
double yPosition;
int frameNumber;
void moveOver(Terrain const& terrain) {
/** some logic based on terrain */
//just filler, but you can change xPosition and yPosition
//in whatever way you want.
xPosition += 32.;
//where numberOfFrames is determined somewhere else.
frameNumber = (frameNumber + 1) % numberOfFrames;
}
};
struct Terrain {
/** stuff, maybe an 2d-array or whatever */
};
As you can see: your game elements persist over the length of the game, and are modified by the application of input to a game state. Animations can be done by looping over a set of numbers that indicate the frame number of the current image to display from a set of possible images.
This is all very shallow, but I hope it gives you an idea of the overall structure of a typical game.
精彩评论