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'm creating a simple game for the iPhone using Cocos2d. I'm having a hard time understanding how add real objects to a tiled map.

I know that you can add an object-layer to the tiled map and set the position of it, but I'm not sure how to define WHAT object it should be.

For example, if I'm creating a simple Super Mario Bros. I want to add different blocks to the map, one should hold a star, one should hold a coin, and so on.

How should I define what object it is?

So my question, how do I correctly create class-objects in a tiled map?

share|improve this question
    
Hey, NSAddict. Do you want to know how to create the object layer, how to create the game objects or how to place them in this layer? I don't think I fully understand your question so if you could clarify it, I can edit my answer to help you better. Thanks. –  Lucas Tulio Feb 3 '13 at 12:33
    
@LucasTulio Sorry if I was unclear. I understand how to create a new layer, but I'm not sure how to create and loop though the objects. –  NSAddict Feb 3 '13 at 12:41
    
You want to loop through which objects? The Tiles in the map or the gameplay objects (star, coin)? The Tiles should have a simple bidimensional int array (x, y) that you can loop through. If you want to loop through a list of your gameplay objects, you should create this array and add all of your coins and stars and mushrooms to it. That way you can always loop through them. –  Lucas Tulio Feb 3 '13 at 12:52
    
I mean gameplay objects like star, coin... So I have to loop though the whole map, even if for example only 1 object is added to the map? –  NSAddict Feb 3 '13 at 12:54
    
Why would you want to loop through them? –  Lucas Tulio Feb 3 '13 at 12:59
show 3 more comments

1 Answer

First, you should have a top layer in your tiled map. This layer will have the same amount of tiles (x, y) as the rest of your map and should be rendered last. In my game, I created a placeEntity(Entity e, int xTile, int yTile) method so you can add the gameplay objects anywhere you want in the map.

About the Stars and Coins, they're just the Star and Coin objects placed at an x and y position using the above method.

share|improve this answer
    
Yes I understand, but how do I loop though the objects? I also saw that you can give them properties, there I could set the entity. –  NSAddict Feb 3 '13 at 12:33
    
Have you seen this tutorial here raywenderlich.com/1163/… it goes through finding the objects in the object layer and doing something with it. I.e spawn point etc... –  Savlon Feb 3 '13 at 23:56
add comment

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.