Example #1
0
bool PlayLayer::init()
{
    if (!Layer::init()) {
        return false;
    }
    Size winSize = Director::getInstance()->getWinSize();
    
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Sprite.plist");
    spriteSheet = SpriteBatchNode::create("Sprite.png");
    addChild(spriteSheet);
    
    map = TMXTiledMap::create("map1.tmx");
    auto bgLayer = map->getLayer("bg");
    bgLayer->setAnchorPoint(Point(0.5f, 0.5f));
    bgLayer->setPosition(Point(winSize.width / 2 ,winSize.height / 2));
	objects = map->getObjectGroup("obj");
    this->addChild(map, -1);
    
    float offX = ( map->getContentSize().width - winSize.width )/ 2;
    initPointsVector(offX);
    addEnemy();
    
    
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan = CC_CALLBACK_2(PlayLayer::onTouchBegan, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
    
    scheduleUpdate();
    return true;
}
Example #2
0
bool MapLayer::init(){
	if (!Layer::init()){
		return false;
	}
	count =4;
	
	

	//地图的载入
	map = TMXTiledMap::create("map.tmx");


	//做好的地图中的背景层
	bgLayer = map->getLayer("bg");
	bgLayer->setZOrder(-1);
	//bgLayer->setNormalizedPosition(Vec2(0.2, 0));
	bossLayer = map->getLayer("boss");
	bossLayer->setVisible(false);
	//偏差
	offX =/*Director::getInstance()->getVisibleSize().width*0.2 -64*/0;
		
	this->addChild(map);

	//对象层获取
	object = map->getObjectGroup("obj");
	//初始化坐标点
	initPointsVector(offX);
// 	log("%d", checkNodeBreak(Vec2(100, 500)));
// 	log("%d", checkNodeBreak(Vec2(100, 100)));
// 	auto sp = Sprite::createWithSpriteFrameName("p1.png");
// 	sp->setPosition(pointsVector.at(0)->getPosition());
// 	this->addChild(sp);
// 	auto sp1 = Sprite::createWithSpriteFrameName("p1.png");
// 	sp1->setPosition(pointsVector.at(1)->getPosition());
// 	this->addChild(sp1);
// 	auto sp2 = Sprite::createWithSpriteFrameName("p1.png");
// 	sp2->setPosition(pointsVector.at(2)->getPosition());
// 	this->addChild(sp2);
// 	auto sp3 = Sprite::createWithSpriteFrameName("p1.png");
// 	sp3->setPosition(pointsVector.at(3)->getPosition());
// 	this->addChild(sp3);
	//
// 	auto sp1 = Sprite::createWithSpriteFrameName("p1.png");
// 	sp1->setPosition(pointsVector.at(1)->getPosition());
// 	this->addChild(sp1);
// 	auto sp2 = Sprite::createWithSpriteFrameName("p1.png");
// 	sp2->setPosition(pointsVector.at(2)->getPosition());
// 	this->addChild(sp2);
// 	auto sp3 = Sprite::createWithSpriteFrameName("p1.png");
// 	sp3->setPosition(pointsVector.at(3)->getPosition());
// 	this->addChild(sp3);
	return true;
}