Many questions about using cocos2d-x


#1

Hi everybody!

I’m learning cocos2d-x and developing a “simple” game with 2 more friends but I’m still a beginner and I have doubts about how to achieve some features in our game…

The game is just a sort of “endless runner” but in 2D. Player can run through the streets of a small town, avoiding obstacles and getting coins and power-ups, very simple and common. We’re making the map with tiled map editor but we’d like to give some “life” to the map (i.e. fluent water river, boys playing in a court, people and cars…). You couldn’t interact with them but we’d like to have all that details, just like a town from a rpg game.

I’m starting to know how cocos2d-x works and I’m wondering if I could do that, because I making a “big town”, with a lot of streets and houses where you could get lost, and it requires quite people doing their stuff.

Can I achieve that with cocos2d-x? How can you add multiple animations on a tilemap? For example, I’d like to see a flowing river when the player goes near it. How can I add that animation to the tilemap? Hardcoding it and adding it to a specific coordenate? If I have multiple animations (people, flags, some animals… many of them are repeated and reused tho), should I add them one by one searching all their respective coordenates on the tilemap? What about memory?

I’d really appreciate some help and guidance in this topic please.

Thanks.


#2

Sure you can do this in cocos2d-x if you are willing to code it.

Basic concept is that you’re going to have a CCLayer holding your tilemap and a bunch of sprites in the tilemap.

The tilemap will have children (CCSprites, CCQuads, etc) that are animated, particle effects, whatever. You’ll add those to your tilemap at a position — and they’ll stay there unless you animate them. If you scroll the tilemap (i assume it is much bigger than the screen of the device) some of those children will move off the screen (tiles beyond the edges and the animated children beyond the edges.)

Depending on how huge we are talking about, you might be better off pausing or pruning objects that are “far away” from the player.

Some of them are repeated and reused? You are probably going to want to look at BatchNodes so that duplicates are just ‘free copies’

Google: CCSpriteBatchNode

Also, if I was you I would start using ‘Spine’ right now =)


#3

Basing on this discussion : https://github.com/bjorn/tiled/issues/57 it seems it is possible to achieve this by setting properties on a tile.


#4

Thanks for your help. I think I need dig into this problem a bit more because I have a problem with the size of my map as well, it’s too big :S