views:

586

answers:

3

I'm trying to make an easy side scrolling game just to learn the ropes of game programming on android. I came up with a solution of how to make it but I don't really think it is the most elegant solution. I wanted to get some different ideas on how to implement my game, as I really have no other solution right now.

Here is a quick explanation of how it works..

I basically have blocks or objects fall from the top of the screen. The blocks are defined from a pre-defined string I create using a custom 'map-editor'.

I create all the blocks at compile time, position them on or off the screen and simply increment their coordinates with each iteration of the gameloop.

It is actually done a little bit better then that, but that gives a short easy explanation on the basic idea.

I heard from a few people that instead of incrementing each block position, have the blocks stay there and simply change the viewable area. That makes sense, but I have no idea how to do it.

Can anyone share some ideas or links on how I can implement something like this? I know my current solution isn't the greatest.

Thanks!

+3  A: 

If the blocks/objects are independent from each other, I'd continue to treat them as independent objects and update their position separately. After all, you may wish someday to make some of them move differently from each other. In game development, it's good to leave the engine as flexible as you can for as long as you can - polishing a game involves a lot of playtesting and fine-tuning of the mechanics of the game, and the more things you have to tweak the more polished you can get it. Optimize only if necessary.

But if the blocks aren't independent, and won't be, changing the viewing area rather than moving each block may be a good idea, though more information about your game would help - is it a platformer? A shooter? If there is some kind of player-controlled object on the playfield you'll have to change its position to keep it onscreen as you change the viewable area, which may make things overly complicated. It's hard to advise without more details.

Good question, though!

EDIT:

Following your comment, and I saw your other question http://stackoverflow.com/questions/3057623/problem-decrementing-in-java-with; I think I understand your question a little better - the main thing I'd change, from a design point of view, would be to create the blocks as needed, rather than creating all of them at once. In other words, create the blocks on the frame before they are going to appear on the screen and, once they are off the screen, delete them. Unless the game design calls for a large persistent world, of course - but it doesn't sound like that kind of game. Can the player backtrack, or do you allow only one-way scrolling?

Bob Montgomery
Thank you for the reply. The basic dumbed-down idea of the game is you have a character, blocks fall down and you try to dodge them by moving the character. So the blocks are independent. I would need to keep a location of all of them for collision detection I'm assuming. So maybe I have the right idea.
hanesjw
+2  A: 

For learning the ropes for game programming on android I would point you at this I/O session from last year and this one from the 2010 sessions.

People telling you about changing the viewable area are probably assuming you're using OpenGL ES, which you might not be, but probably should consider.

jqpubliq
These are great links, thank you very much
hanesjw
+2  A: 

Replica Island (http://code.google.com/p/replicaisland/) is a open source Jump & Run game on Android. (It's from the guy who made the Writing Real Time talks) Maybe you can get some good Ideas from it.

nuriaion