ProgrammingGuide > Other Node Types

Other Node Types

version: Cocos2d-x v3.x
update: Updated almost 3 years ago

TMX and Fast TMX

TMX is an XML-based map format originally designed for tile-based maps but meanwhile also suitable for more generic game levels due to its support for various object types. Tile-based maps can have many layers, determined by a z-order. Each tile has a unique position and id.

1
2
3
4
5
6
7
8
9
10
// reading in a tiled map.
cocos2d::TMXTiledMap* map = cocos2d::TMXTiledMap::create("TileMap.tmx");
addChild(map, 0, kTagTileMap);

// how to get a specific layer and tile
auto layer = map->layerNamed("Layer 0");
auto tile = layer->tileAt(cocos2d::Vec2(1, 63));

// to obtain a specific tiles id
unsigned int gid = layer->tileGIDAt(cocos2d::Vec2(0, 63));

Example Tilemap concepts

Particle

tbd

Parallax

A Parallax Node is a special Node type that simulates a parallax scroller. You can think of many games that function this way, Super Mario Bros being a classic example. Parallax Nodes can be moved around by a Sequence and also manually by mouse, touch, accelerameter or keyboard events.

Parallax nodes are a bit more complex than regular nodes. Why? Because they require the use of multiple nodes to function.

An example of adding multiple Nodes to a Parallax node.

1
2
3
4
5
6
7
8
9
10
11
12
13
// create a void node, a parent node
auto voidNode = ParallaxNode::create();

// NOW add the 3 nodes to the 'void' node

// background image is moved at a ratio of 0.4x, 0.5y
voidNode->addChild(background, -1, Vec2(0.4f,0.5f), Vec2::ZERO);

// tiles are moved at a ratio of 2.2x, 1.0y
voidNode->addChild(tilemap, 1, Vec2(2.2f,1.0f), Vec2(0,-200) );

// top image is moved at a ratio of 3.0x, 2.5y
voidNode->addChild(cocosImage, 2, Vec2(3.0f,2.5f), Vec2(200,800) );

OK, looks and feels familiar, right? Notice a few items! Each Node is given a unique z-order so that they stack on top of each other. Also notice the additional parameters to the addChild() call.

tilemap1.png (272.3 kB) walzer@cocos2d-x.org, 2014-12-03 06:02

tilemap2.png (212.1 kB) walzer@cocos2d-x.org, 2014-12-03 06:02

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.