标签:cocos2d-x3.4 游戏 华容道
地图的显示需要在GameLayer中,需要有一个关卡的引用。
Level * m_pLevel;//<关卡数据的引用 cocos2d::Vector<RoleSprite*> m_pRoleSpriteVec ;//<存储角色精灵 GameLayer::GameLayer() :m_pLevel(nullptr) { m_pLevel = Level::s_levelVec.at(0) ; CC_SAFE_RETAIN(m_pLevel) ; } //显示所有角色: void GameLayer::initMap() { Size size = Director::getInstance()->getWinSize(); float x = 0 ; float y = 0 ; float paddingLeft = 10.0f ; float paddingBottom = 53.0f ; for (unsigned i = 0 ; i < m_pLevel->getRoleID().size() ;i++) { Role * pRole = Role::s_roleVec.at(m_pLevel->getRoleID().at(i)) ; Sprite * pp = Sprite::create(pRole->getImageName()->getCString()); int col = m_pLevel->getRolePos().at(i).x ; int row = m_pLevel->getRolePos().at(i).y ; x = paddingLeft + col * 1.0f * 75.0f ; y = paddingBottom + row * 1.0f * 75.0f ; RoleSprite * pRoleSprite = RoleSprite::create(pRole,row,col,Rect(x,y,pp->getContentSize().width,pp->getContentSize().height),this,this->getLocalZOrder()) ; m_pRoleSpriteVec.pushBack(pRoleSprite) ; } } //在GameLayer的init方法中调用initMap就OK了
标签:cocos2d-x3.4 游戏 华容道
原文地址:http://blog.csdn.net/c_boy_lu/article/details/45047387