![]() PlayerPos.y getMapSize().height * _tileMap->getMapSize().height) & If (playerPos.x getMapSize().width * _tileMap->getMapSize().width) & PlayerPos.y -= _tileMap->getTileSize().height / 2 PlayerPos.y += _tileMap->getTileSize().height / 2 PlayerPos.x -= _tileMap->getTileSize().width / 2 PlayerPos.x += _tileMap->getTileSize().width / 2 TouchLocation = this->convertToNodeSpace(touchLocation) This->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this) Īnd: void HelloWorld::onTouchEnded(Touch *touch, Event *unused_event)Īuto actionTo1 = RotateTo::create(0, 0, 180) Īuto actionTo2 = RotateTo::create(0, 0, 0) Īuto touchLocation = touch->getLocation() Listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this) In the ‘HelloWorldScene.cpp’: void HelloWorld::setViewPointCenter(Point position) Void setViewPointCenter(cocos2d::Point position) In the ‘HelloWorldScene.h’: class HelloWorld : public cocos2d::Layer Next, we add a new function, ‘setViewPointCenter’. And we get object’s position from the map and set the position coordinate to our sprite. By using the ‘getObjectGroup’ function, we get the object layer. We add the judgment statement to decide whether the object has been uploaded. SetViewPointCenter(_player->getPosition()) _player->setPosition(x + _tileMap->getTileSize().width / 2, y + _tileMap->getTileSize().height / 2) TMXObjectGroup *objects = _tileMap->getObjectGroup("Object-Player") ĬCASSERT(NULL != objects, "'Object-Player' object group not found") Īuto playerShowUpPoint = objects->getObject("PlayerShowUpPoint") ĬCASSERT(!playerShowUpPoint.empty(), "PlayerShowUpPoint object not found") In the ‘HelloWorldScene.cpp’: bool HelloWorld::init() In the ‘HelloWorldScene.h’, we now do some coding: Right-click on this rectangle and setting some properties for it. And draw a rectangle on the map where you want your character shows up. Select the ‘Object layer’ to create a new one. Right-click on the ‘Layer Section’ of the Tiled Map editor. (It will solve the problem above, or you can build your map on the lower left corner.) And then, we will create the sprite, our character, and let the window set the view on the character. ![]() ) So if there is no problem happens when VS is debugging, everything is OK. The default setting only shows the lower left corner of the tile map. ( Because the map size which we have created is too big and the window size is not large enough to hold the whole scene. We will get the map, or more preciously, part of the map. Here, we have called the class of the TMXTileLayer to upload our tile map. _background = _tileMap->layerNamed("Background") _tileMap = TMXTiledMap::createWithXML(str->getCString(),"") (You can delete the old code in ’bool HelloWorld::init()’.) bool HelloWorld::init()Īuto str = String::createWithContentsOfFile (FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str()) Then open the ‘HelloWorldScene.cpp’, make some changes. Open the ‘HelloWorldScene.h’, add some member variables: We now register the files which will be used in the head file. Like the Object-C language, The C++ has the head files and the implementation files (I learn Object-C first.).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |