1. 创建地图
this._tilemap = cc.TMXTiledMap.create(s_resprefix + "TileMaps/orthogonal-test2.tmx");
2. 创建视差结点
this._parentNode = cc.ParallaxNode.create();
// NOW add the 3 layers to the 'void' node
// background image is moved at a ratio of 0.4x, 0.5y
this._parentNode.addChild(this._background, -1, cc.p(0.4, 0.5), cc.p(0,0));
// tiles are moved at a ratio of 2.2x, 1.0y
this._parentNode.addChild(this._tilemap, 1, cc.p(2.2, 1.0), cc.p(0, 0));
// top image is moved at a ratio of 3.0x, 2.5y
this._parentNode.addChild(this._cocosimage, 2, cc.p(3.0, 2.5), cc.p(0, 0));
3.移动
if( 'touches' in cc.sys.capabilities ){
cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ALL_AT_ONCE,
onTouchesMoved:function (touches, event) {
var touch = touches[0];
var node = event.getCurrentTarget().getChildByTag(TAG_NODE);
node.x += touch.getDelta().x;
node.y += touch.getDelta().y;
}
}, this);
} else if ('mouse' in cc.sys.capabilities ){
cc.eventManager.addListener({
event: cc.EventListener.MOUSE,
onMouseMove: function(event){
var node = event.getCurrentTarget().getChildByTag(TAG_NODE);
node.x += event.getDeltaX();
node.y += event.getDeltaY();
}
}, this);
}