2D art related topic.

Started by
4 comments, last by Servant of the Lord 11 years, 3 months ago

Hello, everyone. Here is a new beginner for all of you.

Well. Lets put this straight.

I'm currently researching on how videogames are done. For that matter, I still don't understand how 2D/3D art, characters and such things are implemented in games. Is it part of the Engine features? Or is everything programmable? I really am confused on this.

Mi idea is as follows: The programmer works with 2D/3D graphics libraries on his chosen language and use it to import art from 3Ds Max, Maya or so, on the main code for being manageable from there. That means, pressing any button move character from A to Z, while its animation is taking place. Okay, lets be clearer. The user presses any button, then the code runs that character's animation for start moving from A and then walking while the button is till pressed on, to finally run the animation for stopping when arriving at the giving Z point.

Is this how it really works?.

Who does this?

How can it be done?

Is it too hard?

What does it take to accomplish such task?

And then, how programmers make all that to happen on a 3D/2D full environments will complex scenes and NPL character all over the place, plus, collision detection systems and on and on.

I really still don't get how all this is accomplished.

Any feedback will be appreciated.

Advertisement
Is this how it really works?.
Almost.
Who does this?
Programmers.
How can it be done?
By learning how to program code.
Is it too hard?
Yes and no. Sometimes it's very easy, other times it's challenging... but that kind of challenge can be really enjoyable (or can be exceptionally frustrating).
What does it take to accomplish such task?
Learning to program is a lifetime thing, continually expanding and growing in knowledge and skill. but you can learn the basics solidly within about 3 years. Quicker if you make it a full-time focus (40+ hours a week).

By breaking everything into smaller pieces, large challenges can be overcome by tying small simple pieces of code together to build a larger complex system.

(I'm running out the door as I type this, so I'll give a more descriptive response tomorrow unless someone beats me to it - which I hope they generously do smile.png)
By breaking everything into smaller pieces, large challenges can be overcome by tying small simple pieces of code together to build a larger complex system.

(I'm running out the door as I type this, so I'll give a more descriptive response tomorrow unless someone beats me to it - which I hope they generously do smile.png)

I'm learning C (and I will be for the next half year or so. Until there is no chance I can screw code), and the next step is C++ or C# (I'm not sure yet). I hope for a more descriptive response.

Thank you.

Well if your looking for a really code specific answer to your question, here's some pseudo code.

Image puppypicture = loadimage("src/images/cutepictureofpuppy.jpg"); //load your image
int characterX = 200;
int characterY = 200;

void keyeventhandler(keyevent e)
{
if(e.keypresses = keys.leftarrowkey)
{
characterX = characterX - 2; //move two pixels to the left
}
}

void drawstuff(Graphics g)
{
g.drawImage(puppypicture, characterX, characterY);
}


Ok, that code looks a lot more like java than pseudo but I hope this answers your question about key movements. This example pretty much moves a picture of a puppy when you presss the left arrow key.

Once you get the hang of programming and you understand event handling this will make more sense. Games are essentially all about taking input and sending visual output.

When developing a game, you as the programmer are just taking the artists images and 3D models and making them come alive, everything in a game gets done in code.

Stay gold, Pony Boy.

Video games work by breaking time down into little tiny discrete chunks. At the heart of it is a game loop whose job is to execute over and over until the game closes, performing these little chunks of time execution, gathering input from the player(s) and handing it off to interested parties, and drawing the view.

Each time a chunk of time is executed, the game will iterate through all objects and do a few things:

Move any objects that are moving. If the time step is 1/60th of a second, and an object moves at a speed of 3 meters/second, then in one time step the game will move that object 1/20th of a meter (1/60 * 3).

Advance animations. Animations typically have a set of keyframes which are interpolated to get the final pose, and the whole animation is given a duration. So if a Walk animation is 3 seconds long, then a time step of 1/60 will advance it for 1/20th of its duration.

Make decisions. If a character is walking toward (GoalX, GoalY), and has reached its goal in the last movement step, then it's time to decide on a new goal. Maybe an alarm was raised, and an alarm signal was sent to the character, so now the character AI will calculate a new movement goal that will take it nearer to the source of the alarm signal. Or maybe the character is hungry, so it will find a goal that brings it nearer to food. The character might even be in the middle of accomplishing a goal, when the AI overrides the current goal with a new one based on some priority decision. This is the Think() step, and here lives all sorts of goodness and complexity.

Advance timers. Many tasks in a game need to track timing. Say you have a frag grenade that explodes 5 seconds after activation. The grenade would maintain a timer, decrementing it each step by 1/60 until it hits 0, at which point it knows to explode.

Housekeeping. Cleaning up objects marked for termination, running processing tasks to account for updated objects, marking objects dirty so their transformations will update during the draw cycle, etc...

All of this is done in a step every time through the update loop. It sounds like a lot (and it is a lot) but computers are pretty fast. If you do find there to be just too much to do in an update step, then you can implement a staggered approach where objects are processed every Nth timestep, instead of every timestep, breaking up objects into batches to be updated in their turn. That way, you only update a set number of objects each update. However, this can have repercussions on the responsiveness of some objects.

As Servant of the Lord said, you just have to figure out how to take large tasks (representing and updating a huge world full of thousands of objects) and break it down into lots of smaller, easily achievable individual tasks (increment an animation, moving an object).

Well. Lets put this straight.
I'm currently researching on how videogames are done. For that matter, I still don't understand how 2D/3D art, characters and such things are implemented in games. Is it part of the Engine features? Or is everything programmable? I really am confused on this.

First, let's discard the idea of an "engine", as the word is overused and ill-defined. Instead of "engine", we'll use the word "system". I'll define "system" like this: The way every piece of code in your project work together, including the code found 3rd party libraries.

The basic structure (with some variations) of almost every game:

bullets1.png

So, let's say you want to have a red ball that you want to move with the arrow keys and that can't go through walls.


struct Ball
{
    Image image;

    int velocityX, velocityY; //The speed (in pixels) the ball is currently moving, per second.
    int currentX, currentY;
}

Every loop of your game, you check the user input, you update the objects in the game, and you draw the objects.


Ball redBall;
redBall.image = LoadImage("redBallImage.png");


while( the game is still running )
{
      //Check input.
      if(LeftKeyIsHeld)
      {
           redBall.velocityX = BallMovementSpeedPerSecond;
      }
      
      //Update game objects.
      //'deltaTime', in this example, is a float with '1.0' being one second that has passed since the last frame.
      redBall.x += (redBall.velocityX * deltaTime);
      
      if(Collide(wall.boundingBox, redBall.boundingBox))
      {
            //...put the ball right up against the wall, but no longer inside it.
      }
      
      //Draw the game objects.
      Screen.Draw(redBall);
}

This is a very simple (and incomplete) example, but it really is the basis of almost every game. As you add very small and simple pieces of code, the very simple system shown above grows into a very complex system... but that complex system is the result of the interactions of simple pieces of code. How do you do motion in a game?


ObjectPosition += (ObjectVelocity * amountOfTimePassed);

That one line of code adds movement to your game.

How do you know how much time has passed?


currentTime = GetTime();
amountOfTimePassed = (currentTime - lastTimePassed);
lastTimePassed = currentTime;

That calculates the passage of time in your game.

If you try to build a complex system, it can be overwhelming. But when you realize the complex system is the result of simple interactions, it becomes easier: now you just need to discover or study how to make the simple pieces of code to solve your current challenges. ('Simple' relative to the complex system as a whole, but not always 'easy' to code)

How do you check if two objects are colliding? There are many methods. If you are checking for collision between two rectangles that are axis-aligned, you can do it like this:


if... (rectA.right < rectB.left)
or.. (rectA.left > rectB.right)
or.. (rectA.bottom < rectB.top)
or.. (rectA.top > rectB.bottom)
... not colliding...

There are a few problems with this code, which is just for demonstration, but even this "simple" collision is actually itself built of simpler pieces of code. By building up simple pieces of code, you create complex results.

Ofcourse, you don't always need to work at such a low level. Once you or someone else makes a good collision function, you don't need to ever worry about it again and can work on other tiny pieces of code... which, unless buggy, you never need to work on again, so you can work on other pieces of code. And you grow something larger.

I don't have the math skills and knowledge to actually plot pixels in three dimensions onto the 2D screen. Luckily, other people with skill in those areas have already "solved" that problem, so I don't have to. I use their code, so I can focus on the parts of my game that are unique to my game.

I don't have to code how to have a physical hardware keyboard send its input to my game - other people have already solved that.

Instead, I get to put the two together, and say, "WHEN the keyboard input reaches my game, THEN move the objects in the 3D world."

Mi idea is as follows: The programmer works with 2D/3D graphics libraries on his chosen language and use it to import art from 3Ds Max, Maya or so, on the main code for being manageable from there. That means, pressing any button move character from A to Z, while its animation is taking place. Okay, lets be clearer. The user presses any button, then the code runs that character's animation for start moving from A and then walking while the button is till pressed on, to finally run the animation for stopping when arriving at the giving Z point.

Almost. Instead of having the character move from A to Z, give the character a velocity that then automatically moves the character forward. When the character is moving forward, then have an animation automatically play. The animation should be tied to the movement, the movement should be tied to the keypress. But why should the animation know about keypresses or react to them directly?

Likewise, when hitting the key, why should the game say, "Move to point Z". Instead, "WHEN the key is pressed down, THEN change the player's velocity. WHEN the key is released, THEN change the player's velocity back. WHEN the player's collision box intersects the wall's collision box THEN move the player to where he's no longer inside the wall. WHEN the player-avatar is moving forward, THEN play the walking animation. WHEN the avatar collides with the wall THEN play the collision algorithm (and the bump-into-wall noise)"

The smaller pieces that you can break it down into, the easier it is the handle. I'm simplifying my examples... but then again, that's the whole point. Simplify them, break them into steps, and then simplify and break apart those steps.

Let's break apart this 'game feature':

"Let the player move around the game world"

bullets2.png

The complex system is the result of simple pieces of code. Again, 'simple' doesn't mean easy, but rather more bite-size and manageable chunks - bite size portions of food can still be hard to chew - bite-size pieces of code can still take real work and research.

[hr]

One last comment: C++ doesn't require you to learn C first. C# doesn't require you to learn C first. If you are learning C, that's fine, but if someone told you that you have to learn C before you can learn C++, that's a common but 100% incorrect and faulty bit of knowledge. C is a good language to learn, but is definitely not a required stepping stone to C++ or C#. People who want to learn C# start by learning C# itself. Learning to ride a horse-drawn carriage is not a required step to learning to drive a car.

If you've already been learning C for several months now, stick with it! If you are just starting to learn C, consider a different language like C# or Python. If your real goal is learning C#, learn C#. If your real goal is learning C, learn C. If your real goal is learning how to program games, and you don't care how you program games, start with Python (which is very powerful and also more forgiving and easier to learn, but still a very real programming language that has been used in a couple successful commercial games) and if you still want to learn C++ or C# after learning Python, you can always learn it later.

This topic is closed to new replies.

Advertisement