Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Making 2D game graphics with GTK+ [closed]

I am interested in making a GUI-intensive strategy game with C++ and GTK+. What I would like to know is how feasible it would be to add 2D game graphics to a GTK program. Basically I would be wanting something like a game screen, with interactable 2D graphics, flanked by menus and the ability to navigate to other screens that would be GUI only.

Note that I have never used GTK before, nor have I before programed a GUI (nor graphics either).

like image 908
Matt Munson Avatar asked Jan 16 '23 19:01

Matt Munson


2 Answers

It's certainly possible with GTK, but you have to ask yourself whether you're using the right tool for the job. Use Clutter, which is much more suited to animation and integrates with GTK; or perhaps better yet, use a game programming toolkit.

Here's an example of two non-intensive proof-of-concept games written with Clutter, with links to their source code.

like image 130
ptomato Avatar answered Jan 21 '23 06:01

ptomato


It's possible. I did it with GTK and Vala some time ago. Here is a blog post I wrote about it. Basically it's very much like the games you make with Java and Swing. Just override the expose signal and create a timer for regular redraws. Here's an article on developing a 2D Snake game in PyGTK.

In pseudocode, all you do for the game infrastructure is:

start()
{
    tick_timer( 1.0 / FPS );
    load_all_sprites_etc();
}

tick()
{
    update();
    game_board.expose(); // game_board is a GTKWidget, preferably a DrawingArea
}

expose_event()  // connected to game_board
{
    drawing_code();
}

update() 
{
    game_physics();
    game_logic();
}
like image 41
ApprenticeHacker Avatar answered Jan 21 '23 07:01

ApprenticeHacker