本文整理汇总了C++中TMXTiledMap::setAnchorPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ TMXTiledMap::setAnchorPoint方法的具体用法?C++ TMXTiledMap::setAnchorPoint怎么用?C++ TMXTiledMap::setAnchorPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMXTiledMap
的用法示例。
在下文中一共展示了TMXTiledMap::setAnchorPoint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
PushBoxScene::PushBoxScene()
{
TMXTiledMap* mytmx = TMXTiledMap::create("Pushbox/map.tmx");
mytmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
mytmx->setAnchorPoint(Vec2(0,0));
myx = (visibleSize.width - mytmx->getContentSize().width) / 2;
myy = (visibleSize.height - mytmx->getContentSize().height) / 2;
this->addChild(mytmx, 0);
count = 0;
success = 0;
/*mon = Sprite::create("Pushbox/player.png");
mon->setAnchorPoint(Vec2(0, 0));
mon->setPosition(Vec2(SIZE_BLOCK*1+myx, SIZE_BLOCK*8+myy));
mon->setTag(TAG_PLAYER);
this->addChild(mon, 1);*/
TMXObjectGroup* objects = mytmx->getObjectGroup("wall");
//从对象层中获取对象数组
ValueVector container = objects->getObjects();
//遍历对象
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/wall.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x,y+64));
mywall.pushBack(temp);
this->addChild(temp, 1);
}
TMXObjectGroup* objects1 = mytmx->getObjectGroup("box");
//从对象层中获取对象数组
ValueVector container1 = objects1->getObjects();
//遍历对象
for (auto obj : container1) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/box.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x, y+64));
mybox.pushBack(temp);
this->addChild(temp, 3);
}
TMXObjectGroup* objects2 = mytmx->getObjectGroup("player");
//从对象层中获取对象数组
ValueVector container2 = objects2->getObjects();
//遍历对象
for (auto obj : container2) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/player.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x, y+64));
mon = temp;
this->addChild(temp, 2);
}
TMXObjectGroup* objects3 = mytmx->getObjectGroup("goal");
//从对象层中获取对象数组
ValueVector container3 = objects3->getObjects();
//遍历对象
for (auto obj : container3) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/goal.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x, y+64));
mygoal.pushBack(temp);
this->addChild(temp, 1);
}
}
示例2: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Scene::init() )
{
return false;
}
visibleSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin();
en = false;
TMXTiledMap* tmx = TMXTiledMap::create("map.tmx");
tmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
tmx->setAnchorPoint(Vec2(0.5, 0.5));
tmx->setScale(Director::getInstance()->getContentScaleFactor());
this->addChild(tmx, 0);
//创建一张贴图
auto texture = Director::getInstance()->getTextureCache()->addImage("$lucia_2.png");
//从贴图中以像素单位切割,创建关键帧
auto frame0 = SpriteFrame::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(0, 0, 113, 113)));
//使用第一帧创建精灵
player = Sprite::createWithSpriteFrame(frame0);
player->setPosition(Vec2(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height / 2));
addChild(player, 3);
//hp条
Sprite* sp0 = Sprite::create("hp.png", CC_RECT_PIXELS_TO_POINTS(Rect(0, 320, 420, 47)));
Sprite* sp = Sprite::create("hp.png", CC_RECT_PIXELS_TO_POINTS(Rect(610, 362, 4, 16)));
//使用hp条设置progressBar
hp = 100;
pT = ProgressTimer::create(sp);
pT->setScaleX(90);
pT->setAnchorPoint(Vec2(0, 0));
pT->setType(ProgressTimerType::BAR);
pT->setBarChangeRate(Point(1, 0));
pT->setMidpoint(Point(0, 1));
pT->setPercentage(hp);
pT->setPosition(Vec2(origin.x + 14 * pT->getContentSize().width, origin.y + visibleSize.height - 2 * pT->getContentSize().height));
addChild(pT, 1);
sp0->setAnchorPoint(Vec2(0, 0));
sp0->setPosition(Vec2(origin.x + pT->getContentSize().width, origin.y + visibleSize.height - sp0->getContentSize().height));
addChild(sp0, 0);
// 静态动画
idle.reserve(1);
idle.pushBack(frame0);
// 攻击动画
attack.reserve(17);
for (int i = 0; i < 17; i++) {
auto frame = SpriteFrame::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(113 * i, 0, 113, 113)));
attack.pushBack(frame);
}
// 可以仿照攻击动画
// 死亡动画(帧数:22帧,高:90,宽:79)
auto texture2 = Director::getInstance()->getTextureCache()->addImage("$lucia_dead.png");
// Todo
dead.reserve(22);
for (int i = 0; i < 22; ++i) {
auto frame= SpriteFrame::createWithTexture(texture2, CC_RECT_PIXELS_TO_POINTS(Rect(79 * i, 0, 79, 90)));
dead.pushBack(frame);
}
// 运动动画(帧数:8帧,高:101,宽:68)
auto texture3 = Director::getInstance()->getTextureCache()->addImage("$lucia_forward.png");
// Todo
run.reserve(8);
for (int i = 0; i < 8; ++i) {
auto frame = SpriteFrame::createWithTexture(texture3, CC_RECT_PIXELS_TO_POINTS(Rect(68 * i, 0, 68, 101)));
run.pushBack(frame);
}
auto w = Label::createWithTTF("W", "fonts/arial.ttf", 36);
auto wItem = MenuItemLabel::create(w, CC_CALLBACK_1(HelloWorld::moveWCallback,this));
wItem->setPosition(100, 100);
auto s = Label::createWithTTF("S", "fonts/arial.ttf", 36);
auto sItem = MenuItemLabel::create(s, CC_CALLBACK_1(HelloWorld::moveSCallback, this));
sItem->setPosition(100, 50);
auto a = Label::createWithTTF("A", "fonts/arial.ttf", 36);
auto aItem = MenuItemLabel::create(a, CC_CALLBACK_1(HelloWorld::moveACallback, this));
aItem->setPosition(50, 50);
auto d = Label::createWithTTF("D", "fonts/arial.ttf", 36);
auto dItem = MenuItemLabel::create(d, CC_CALLBACK_1(HelloWorld::moveDCallback, this));
dItem->setPosition(150, 50);
auto x = Label::createWithTTF("X", "fonts/arial.ttf", 36);
auto xItem = MenuItemLabel::create(x, CC_CALLBACK_1(HelloWorld::moveXCallback, this));
xItem->setPosition(visibleSize.width-50, 100);
auto y = Label::createWithTTF("Y", "fonts/arial.ttf", 36);
//.........这里部分代码省略.........
示例3: testTMX
void prep::testTMX()
{
Size visibleSize = Director::getInstance()->getVisibleSize();
//创建游戏
TMXTiledMap* tmx = TMXTiledMap::create("map.tmx");
tmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
tmx->setAnchorPoint(Vec2(0.5, 0.5));
tmx->setName("paopaot");
this->addChild(tmx);
//获取对象层
TMXObjectGroup* objects = tmx->getObjectGroup("bubble");
//对应对象层的对象数组
ValueVector container = objects->getObjects();
//遍历
for (auto obj : container) {
ValueMap values = obj.asValueMap();
//获取坐标(cocos2dx坐标)
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto buble = Sprite::create("bubble.png");
buble->setPosition(Vec2(x, y + 64));
buble->ignoreAnchorPointForPosition(true);
tmx->addChild(buble, 2);
prep::bubbles.pushBack(buble);
}
objects = tmx->getObjectGroup("wall");
container = objects->getObjects();
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto wall = Sprite::create("wall.png");
wall->setPosition(Vec2(x, y + 64));
wall->ignoreAnchorPointForPosition(true);
tmx->addChild(wall, 1);
prep::walls.pushBack(wall);
}
objects = tmx->getObjectGroup("money");
container = objects->getObjects();
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto goal = Sprite::create("money.png");
goal->setPosition(Vec2(x, y + 64));
goal->ignoreAnchorPointForPosition(true);
tmx->addChild(goal, 1);
prep::money.pushBack(goal);
}
objects = tmx->getObjectGroup("player");
container = objects->getObjects();
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto player = Sprite::create("player.png");
player->setPosition(Vec2(x, y + 64));
player->ignoreAnchorPointForPosition(true);
player->setName("player");
tmx->addChild(player, 1);
}
}