Jump to content
  • Advertisement
Sign in to follow this  
zablas

I want to learn programming 2D games. What's the best E-Book?

This topic is 667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone!

I've been programming with C++ for a bit more than a year now. I already have the basic concepts of it like creating functions and multi-file projects and why is that useful. Though I am a bit clunky in OOP. Today I thought to myself that it's finally time to move onto something a bit more advanced than command line projects and I want to make a 2D game (side scroller preffered). For the last few hours I've been doing research on what would be the best E-Book to learn that and there were so many different ones. I looked through all of them and each and every single one them explains stuff in different ways. Though I noticed that they all used Visual Studio so I have just installed it (been using Dev-C++ and might still use it). Since I have zero experience in 2D game making I'd like a book with detail explanations why should something be "like that" and not "like that". What would you recommend me to read? Any help is much appreciated! :)

Share this post


Link to post
Share on other sites
Advertisement

The IDE doesn't really matter. C++ is more or less the same whichever one you use. Just need to figure out where it is that you type in libraries to link, like sdl.dll if you're using SDL.

 

Don't worry too much about OOP. It's a good approach for a lot of things, but not the be-all-end-all of programming. Most likely you'll end up inventing it yourself when you need it :)

 

Regardless of which API you use, the basic approach to realtime programming is to use a function that returns a real time value, such as the WinAPI function GetTickCount(). It continually counts up in milliseconds, so if you want to run at 30 frames per second, do something like this:

int lastTick = GetTickCount();
while(1)
{
    int thisTick = GetTickCount();
    if (thisTick - lastTick >= 1000/30)
    {
        lastTick = thisTick;
        UpdateFrame();
    }
}

And I would recommend running at fixed frame rate. Variable frame rate is a pain, and not particularly beneficial for most 2D games.

 

The basic idea of graphics is that the screen is a huge array of pixels, and each pixel is a number representing its color. Every frame, you update character positions and such based on player input and enemy AI, and then copy all the background and sprite images to the screen at their updated positions. Draw the background first, and then the sprites, so they'll overwrite part of the background. Sprites are actually rectangles, but can look like any shape by using a color key (when copying pixels from the sprite image to the screen, check if the pixel is the transparent color, and if so, skip copying it).

 

Library code often handles all the pixel copying for you, but if you like a barebones approach where you do it all yourself, then SDL is the best. I like to allocate my own chunk of memory to use as the screen (32 bit pixels), and blit 8 bit paletted images to that using my own code. Then when the frame is done, lock the SDL screen surface and copy my screen buffer to it.

Share this post


Link to post
Share on other sites

Though I noticed that they all used Visual Studio so I have just installed it (been using Dev-C++ and might still use it).


The IDE doesn't really matter. C++ is more or less the same whichever one you use.


I don't know when was the last time Dev-C++ was updated but the recommended thing to do is either use Visual Studio or Code::Blocks, for C++ devving.

Share this post


Link to post
Share on other sites

Well are you trying to simply make a game or are you trying to make a game using a programming language, like C++?

 

Isn't GScript a "proper" programming language? Just have to ask :)

I think it's not as powerful as C++, but Godot makes a lot easier.

Edited by Nopp

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!