Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I would like to make an adventure type game functioning similarly to machinarium or broken sword. The only way I can think of doing this is to draw an image as a background on a canvas and use some animated sprites that moves around and responds to touches on the screen.

But having a runnable that keeps re-drawing the canvas seems like a waste of memory to me, especially when it comes to larger images like the background.

I'm pretty new to game development and canvas animations and I was wondering if anyone could point me in the right direction? What would be good training for an adventure type game?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

One of the most commonly used methods to render images involves double buffering. All of the data to be drawn to the screen is drawn to the "Back Buffer", and at the end of the draw routine, it swaps positions with the "Front Buffer" which is located on the screen. Your 2D screen has no understanding of the concept of layering, so if you don't redraw the background each frame (or use an algorithm to only redraw the exposed pixels) then you wont have a background. This is just one (though the main) approach to rendering to the screen, but there is no way to get around having to draw what you want to see on the screen.

Your initial idea is going in the right direction. Stay the course.

share|improve this answer
    
Well that's not entirely true, you actually can just draw the whole background once and invalidate the parts that over lap with sprite animation. While that would technically be a more efficient solution it is not exactly friendly to less experienced developers. I would definitely recommend you draw the background each time to simplify development but I just wanted to let you know there are more efficient (although hard to use) methods for rendering. –  Benjamin Danger Johnson Jan 30 '13 at 17:55
    
If you track the movement of all objects over the background and only redraw the areas that have become exposed you could keep from redrawing the entire background. Though the overhead involved in tracking the movement for per-pixel redrawing might produce more performance problems than simply redrawing the entire texture to the screen. –  Evan Jan 30 '13 at 18:35
    
very true, it really depends on the number of objects and complexity of the scene. While this is technically the optimal method for the GPU you are very right in that it can require a lot of CPU overhead depending how it is implemented. Either way my suggestion is not recommended for beginners (which is why I didn't post it as an answer), just kind of meant as a note about alternatives. –  Benjamin Danger Johnson Jan 31 '13 at 0:10

My generic advice would be not to worry too much about performance when you're starting out. As mentioned in the other answers, it's possible to redraw only those portions that have changed, but you're already getting into a level of performance optimization that's premature when you're learning to create the basic architecture of your game. When you're ready to do optimization, it's worth analyzing the problem in terms of what are the ACTUAL bottlenecks of your game, not what seem like they ought to be.

In general, it's very common to have a main game loop that cycles through:

  1. Getting user input
  2. Updating Game Logic
  3. Drawing the scene

Where, in step 3, you're drawing the entire scene, even those parts that don't necessarily need to be redrawn. As far as a useful starting point, I recommend this blog post:

http://www.godpatterns.com/2010/08/how-to-make-adventure-game.html

In particular, you're going to want to learn about such things as navmeshes, which are pretty fundamental to that genre.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.