Top down 2D system for iPhone?

Previous topic - Next topic

jobieadobe

I want to make a top down game where the player can walk north south east and west while the map scrolls underneath him.

I had an idea to make a list of all the entities on the map and loop through them every time the screen is drawn to check if they are in a certain radius of the player and hence should be drawn. Is this a viable option and if so would an iPhone have the processing power to handle it?

P.S. I was thinking I could create an DIM with numbers that correlate to tiles, but I don't think I would like the way it would look in the end. Plus, I was hoping at some point having a multi-player option and I would think my solution would also work on drawing the networked players position.

Update: Modified subject from "is this possible" to "Top down 2D system for iPhone?"

Slydog

#1
Are you planning on creating a 2D top-down game, or a 3D game.
Either would work.

If 3D, then the camera would just follow the player, and the world would scroll automatically.
It would look nicer with 3D models and be easier (or not!) with model animation.
You wouldn't need physics if you kept it simple enough, just basic colliders.
You could either create your world map in a 3D modeling package,
or use a text file like a tile map and dynamically create your world 3D model.
I've done it the tile map way, its not as bad as it sounds, just create basic functions like Mesh_AddQuad() etc.
Then if you want to add a 'wall' tile, it would just be 5 quads at that x/z co-ordinate. (4 walls and a top)

2D may be much simpler in other ways.
But you have to handle the scrolling yourself.
If you had a 2nd map of all your entities rounded to nearest 'tile_size', then you can simply draw only entities within a screen width/height around your player like:
Code (glbasic) Select

FOR x = player.mappos.x - (tiles_wide / 2) TO player.mappos.x + (tiles_wide /2)
  FOR y = player.mappos.y - (tiles_tall / 2) TO player.mappos.y + (tiles_tall /2)
    IF entity_map[y][x] > 0
       DrawEntity(entity_map[y][x])   // Draw entity with ID stored at map location
    ENDIF
  NEXT
NEXT

Then have an array of all you entities, with pixel locations etc.
And, I'm sure the iPhone can handle it, as I've seen a lot more complicated games released!

For multiplayer/network, each loop would refer to that player's position.
I've read some good tile map tutorials from these forums, may be a good place to start.
Good luck,

[Edit]
Depending on how many entities you have, your way may be faster / simpler.
Just loop for all entities, and check if within a certain x / y position.
The more entities you have NOT on the screen, the slower this would be.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Wampus

Quote from: jobieadobe on 2010-Jun-29
P.S. I was thinking I could create an DIM with numbers that correlate to tiles, but I don't think I would like the way it would look in the end. Plus, I was hoping at some point having a multi-player option and I would think my solution would also work on drawing the networked players position.

Word of warning - if you are thinking of implementing multi-player support later on make sure your app is created with that in mind from the very beginning. Adding multi-player support after your game engine is built and your content is mostly complete would probably be very difficult otherwise.

jobieadobe

Thanks for the great input guys! :good: I will get to work and let know how things turn out. Oh by the way I'm going to aim for 2D, seems like it will make everything simpler.

jobieadobe

I have another question couple questions.

Can using a tile based system render good frame rates for the iPhone?

How could one do a 2D top down system without the use of tiles?

Thanks in advance!

Ian Price

QuoteHow could one do a 2D top down system without the use of tiles?

You could create large bitmap images and use those as the backgrounds for your game, then draw your characters, items etc. over the top. Just scroll the bitmap under the player.

Obviously the problem with this is that a large bitmap will take up large amounts of memory and slow down the loading - either at the start of the game, or as the images are required. They also take a lot longer to draw (not display) as a whole than a lot of similar tiles.

Tiles really are the way to go - hence why so many games (top down and side view) use them, and have done since the early 8bit days.
I came. I saw. I played.