// getContentSize函数来获得节点原始的大小。只是逻辑尺寸,不是像素, 若是DesignResolutionSize跟屏幕尺寸一样大,则getVisibleSize便是getWinSize。
// getContentSizeInPixels获得的是像素点大小
// 像素点和逻辑点关系:逻辑点大小 = 像素大小/contentScaleFactor.
// getVisibleOrigin:获得可视区域的出发点坐标,在处理相对位置时,确保节点在不同分辨率下的位置一致。
auto winSize = Director::getInstance()->getVisibleSize();
// hero
auto hero = Sprite::create(bird_hero);
hero->setPosition(winSize.width / 3, winSize.height*0.8);
hero->setVisible(false);
hero->setTag(TAG_HERO);
this->addChild(hero, 1);
Animation* an = Animation::create();
an->addSpriteFrameWithFileName(bird_hero);
an->addSpriteFrameWithFileName(bird_hero2);
an->addSpriteFrameWithFileName(bird_hero3);
an->setDelayPerUnit(0.5f / 3.0f); //必须设置否则不会动态播放
an->setLoops(-1); //重复次数 (-1:无限循环)
Animate* anim = Animate::create(an);
hero->runAction(anim);
cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("tauren0.png","tauren0.plist","tauren.ExportJson");
armature = cocostudio::Armature::create("tauren");
armature->getAnimation()->playByIndex(0);
armature->setScale(1.0f);
armature->setPosition(Vec2(x.asInt()+50,y.asInt()));
this->addChild(armature);
本文介绍Cocos2d-x中节点尺寸的概念,包括getContentSize与getContentSizeInPixels的区别,以及如何通过getVisibleOrigin调整节点位置。此外,还展示了如何创建精灵动画和使用Cocostudio进行更复杂的动画设计。

248

被折叠的 条评论
为什么被折叠?



