//创建摄像机
_camera = Camera::createPerspective(60,visibleSize.width/visibleSize.height,0.1,800);
_camera->setCameraFlag(CameraFlag::USER1);
_camera->setPosition3D(Vec3(-1,1.6,4));
addChild(_camera);
//分别对应红,绿,蓝,黑色背景的图片资源
Terrain::DetailMap r("TerrainTest/dirt.jpg"),g("TerrainTest/Grass2.jpg"),b("TerrainTest/road.jpg"),a("TerrainTest/GreenSkin.jpg");
//一个参数是高度图,用来生成地图高度;第二个参数是地图贴图,用后面4张图片来生成对应的地图纹理
Terrain::TerrainData data("TerrainTest/heightmap16.jpg","TerrainTest/alphamap.png",r,g,b,a);
//创建Terrain地图
_terrain = Terrain::create(data,Terrain::CrackFixedType::SKIRT);
_terrain->setLODDistance(3.2,6.4,9.6);
_terrain->setMaxDetailMapAmount(4);
addChild(_terrain);
_terrain->setCameraMask(2);
_terrain->setDrawWire(false);
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesMoved = CC_CALLBACK_2(TerrainSimple::onTouchesMoved,this); eventDispatcher->addEventListenerWithSceneGraPHPriority(listener,this);
原文链接:https://www.f2er.com/cocos2dx/343152.html