本文整理汇总了C++中Vec2函数的典型用法代码示例。如果您正苦于以下问题:C++ Vec2函数的具体用法?C++ Vec2怎么用?C++ Vec2使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Vec2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cpVert2Point
static Vec2 cpVert2Point(const cpVect &vert)
{
return Vec2(vert.x, vert.y);
}
示例2: drawCenter
void drawCenter(const Vec2 ¢er, const Size<double> &size)
{
draw(Vec2(center.x - size.width / 2, center.y - size.height / 2), size);
}
示例3: MAX
void RichText::formarRenderers()
{
if (_ignoreSize)
{
float newContentSizeWidth = 0.0f;
float newContentSizeHeight = 0.0f;
Vector<Node*>* row = (_elementRenders[0]);
float nextPosX = 0.0f;
for (ssize_t j=0; j<row->size(); j++)
{
Node* l = row->at(j);
l->setAnchorPoint(Vec2::ZERO);
l->setPosition(Vec2(nextPosX, 0.0f));
_elementRenderersContainer->addChild(l, 1);
Size iSize = l->getContentSize();
newContentSizeWidth += iSize.width;
newContentSizeHeight = MAX(newContentSizeHeight, iSize.height);
nextPosX += iSize.width;
}
_elementRenderersContainer->setContentSize(Size(newContentSizeWidth, newContentSizeHeight));
}
else
{
float newContentSizeHeight = 0.0f;
float *maxHeights = new float[_elementRenders.size()];
for (size_t i=0; i<_elementRenders.size(); i++)
{
Vector<Node*>* row = (_elementRenders[i]);
float maxHeight = 0.0f;
for (ssize_t j=0; j<row->size(); j++)
{
Node* l = row->at(j);
maxHeight = MAX(l->getContentSize().height, maxHeight);
}
maxHeights[i] = maxHeight;
newContentSizeHeight += maxHeights[i];
}
float nextPosY = _customSize.height;
for (size_t i=0; i<_elementRenders.size(); i++)
{
Vector<Node*>* row = (_elementRenders[i]);
float nextPosX = 0.0f;
nextPosY -= (maxHeights[i] + _verticalSpace);
for (ssize_t j=0; j<row->size(); j++)
{
Node* l = row->at(j);
l->setAnchorPoint(Vec2::ZERO);
l->setPosition(Vec2(nextPosX, nextPosY));
_elementRenderersContainer->addChild(l, 1);
nextPosX += l->getContentSize().width;
}
}
_elementRenderersContainer->setContentSize(_contentSize);
delete [] maxHeights;
}
size_t length = _elementRenders.size();
for (size_t i = 0; i<length; i++)
{
Vector<Node*>* l = _elementRenders[i];
l->clear();
delete l;
}
_elementRenders.clear();
if (_ignoreSize)
{
Size s = getVirtualRendererSize();
this->setContentSize(s);
}
else
{
this->setContentSize(_customSize);
}
updateContentSizeWithTextureSize(_contentSize);
_elementRenderersContainer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
}
示例4: Vec2
Vec2 Vec2::operator +( const float rhs ) const
{
return Vec2( x + rhs, y + rhs );
}
示例5: physics
bool PlatformerEntityController::update(TimeValue time)
{
// Check there is a character controller to work with
if (!getEntity()->characterController_)
{
LOG_ERROR << "Entity does not have a character controller: " << *getEntity();
return true;
}
// The maximum update rate is tied to the physics update rate
auto timePerSubstep = physics().getSubstepSize();
// Work out how many physics steps there are to run
timeSinceLastUpdate_ += std::min(time, TimeValue(0.1f));
auto substepCount = timeSinceLastUpdate_ / timePerSubstep;
if (substepCount == 0)
return true;
// Roll over any unused time to future frames
timeSinceLastUpdate_ -= timePerSubstep * substepCount;
auto seconds = (physics().getSubstepSize() * substepCount).toSeconds();
// If 10ms has elapsed then add a new past world position
auto currentTime = platform().getTime();
if (pastWorldPositions_.empty() || (currentTime - pastWorldPositions_[0].time).toMilliseconds() > 10.0f)
pastWorldPositions_.prepend(PastWorldPosition(currentTime, getEntity()->getWorldPosition().toVec2()));
// Cull outdated past world positions (> 100ms old)
while ((currentTime - pastWorldPositions_.back().time).toMilliseconds() > 100.0f)
pastWorldPositions_.popBack();
// Determine actual velocity after accounting for collisions, this is only possible if there are sufficient samples
if (pastWorldPositions_.size() >= 2)
{
const auto& p0 = pastWorldPositions_[0];
for (auto i = 1U; i < pastWorldPositions_.size(); i++)
{
if ((p0.time - pastWorldPositions_[i].time).toSeconds() > 0.05f)
{
velocity_ = (p0.position - pastWorldPositions_[i].position) /
(p0.time - pastWorldPositions_[i].time).toSeconds();
break;
}
}
}
// Check for a down axis collision and use the result to track falling distances and report falls
fallDistance_ = 0.0f;
auto collisionNormal = Vec3();
if (physics().getCharacterControllerDownAxisCollision(getEntity()->characterController_, collisionNormal))
{
// Report a fall if the character controller was previously not on the ground
if (reportFallWhenNextOnGround_)
{
fallDistance_ = maximumYSinceLastOnGround_ - getEntity()->getWorldPosition().y;
reportFallWhenNextOnGround_ = false;
}
maximumYSinceLastOnGround_ = getEntity()->getWorldPosition().y;
}
else
{
// The controller is not in contact with the ground so a fall should be reported when the controller is next on
// the ground, the final fall distance is determined based on how high the controller got since it was last on
// the ground.
reportFallWhenNextOnGround_ = true;
maximumYSinceLastOnGround_ = std::max(maximumYSinceLastOnGround_, getEntity()->getWorldPosition().y);
}
// Keyboard control of movement
auto movement = Vec2();
if (isUserInputAllowed_ && platform().isKeyPressed(moveLeftKey_))
movement -= Vec2::UnitX;
if (isUserInputAllowed_ && platform().isKeyPressed(moveRightKey_))
movement += Vec2::UnitX;
if (isJumping_)
movement.x *= jumpHorizontalMovementScale_;
// Calculate any movement offset needed for jumping
auto jumpOffset = 0.0f;
if (isJumping_)
{
// Check whether the character controller has hit something above it. If it has, and the surface hit is fairly
// close to horizontal, then the jump terminates immediately
if (physics().getCharacterControllerUpAxisCollision(getEntity()->characterController_, collisionNormal))
isJumping_ = collisionNormal.dot(-Vec3::UnitY) < 0.95f;
if (isJumping_)
{
auto jumpTimeElapsed = (currentTime - jumpStartTime_).toSeconds();
if (jumpTimeElapsed >= jumpTime_ * 2.0f)
isJumping_ = false;
else
{
// Calculate the vertical jump movement for this timestep
auto t0 = jumpTimeElapsed / jumpTime_;
auto t1 = std::max(jumpTimeElapsed - seconds, 0.0f) / jumpTime_;
//.........这里部分代码省略.........
示例6: addChild
bool ControlButtonTest_HelloVariableSize::init()
{
if (ControlScene::init())
{
auto screenSize = Director::getInstance()->getWinSize();
// Defines an array of title to create buttons dynamically
std::vector<std::string> vec;
vec.push_back("Hello");
vec.push_back("Variable");
vec.push_back("Size");
vec.push_back("!");
auto layer = Node::create();
addChild(layer, 1);
double total_width = 0, height = 0;
int i = 0;
for (auto& title : vec)
{
// Creates a button with this string as title
ControlButton *button = standardButtonWithTitle(title.c_str());
if (i == 0)
{
button->setOpacity(50);
button->setColor(Color3B(0, 255, 0));
}
else if (i == 1)
{
button->setOpacity(200);
button->setColor(Color3B(0, 255, 0));
}
else if (i == 2)
{
button->setOpacity(100);
button->setColor(Color3B(0, 0, 255));
}
button->setPosition(total_width + button->getContentSize().width / 2, button->getContentSize().height / 2);
layer->addChild(button);
// Compute the size of the layer
height = button->getContentSize().height;
total_width += button->getContentSize().width;
i++;
}
layer->setAnchorPoint(Vec2 (0.5, 0.5));
layer->setContentSize(Size(total_width, height));
layer->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
// Add the black background
auto background = Scale9Sprite::create("extensions/buttonBackground.png");
background->setContentSize(Size(total_width + 14, height + 14));
background->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
addChild(background);
return true;
}
return false;
}
示例7: sprintf
void RunnerSprite::extralInit(){
auto roleGroup = this->mMap->getObjectGroup("role");
ValueMap obj = static_cast<ValueMap>(roleGroup->getObject("player"));
float spX = obj["x"].asFloat();
float spY = obj["y"].asFloat();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("playerrun.plist", "playerrun.png");
mRunner = cocos2d::Sprite::createWithSpriteFrameName("image1.png");
mRunner->setPosition(Vec2(spX,spY));
mRunner->setAnchorPoint(Vec2(0.5,0.0));
mMap->addChild(mRunner);
auto runAnim = Animation::create();
for(int i = 1;i<17;i++){
char nameBuf[100] = {0};
sprintf(nameBuf, "image%d.png",i);
auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(nameBuf);
runAnim->addSpriteFrame(frame);
}
runAnim->setDelayPerUnit(0.06f);
runAnim->setRestoreOriginalFrame(true);
AnimationCache::getInstance()->addAnimation(runAnim,"runAction");
auto colGroup = mMap->getObjectGroup("collision");
auto colObj = colGroup->getObjects();
CCLOG("objs %lu",colObj.size());
barriers.reserve(colObj.size());
for(ValueVector::iterator it = colObj.begin(); it != colObj.end(); ++it) {
ValueMap mp = it->asValueMap();
barriers.push_back(Rect(mp["x"].asFloat(), mp["y"].asFloat(), mp["width"].asFloat(), mp["height"].asFloat()));
}
auto colGroup2 = mMap->getObjectGroup("collision");
auto colObj2 = colGroup2->getObjects();
CCLOG("objs %lu",colObj.size());
goldens.reserve(colObj2.size());
goldenSs.reserve(colObj2.size());
int i = 0;
for(ValueVector::iterator it = colObj2.begin(); it != colObj2.end(); ++it) {
ValueMap mp = it->asValueMap();
goldens.push_back(Rect(mp["x"].asFloat(), mp["y"].asFloat(), mp["width"].asFloat(), mp["height"].asFloat()));
auto gold = Sprite::create("gold.png");
gold->setAnchorPoint(Vec2(0.5,0.5));
gold->setPosition(Vec2(mp["x"].asFloat(), mp["y"].asFloat() + 180));
gold->setScale(0.2, 0.2);
gold->setTag(2800+i);
mMap->getLayer("ground")->addChild(gold);
goldenSs.push_back(gold);
i++;
}
setRunState(kROLERUN);
auto runAim = RepeatForever::create(Animate::create(AnimationCache::getInstance()->getAnimation("runAction"))) ;
this->mRunner->runAction(runAim);
gNum = 0;
mNum = 0;
}
示例8:
ShaderNode::ShaderNode()
:_center(Vec2(0.0f, 0.0f))
,_resolution(Vec2(0.0f, 0.0f))
,_time(0.0f)
{
}
示例9: CC_CALLBACK_2
RenderTextureZbuffer::RenderTextureZbuffer()
{
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = CC_CALLBACK_2(RenderTextureZbuffer::onTouchesBegan, this);
listener->onTouchesMoved = CC_CALLBACK_2(RenderTextureZbuffer::onTouchesMoved, this);
listener->onTouchesEnded = CC_CALLBACK_2(RenderTextureZbuffer::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
auto size = Director::getInstance()->getWinSize();
auto label = Label::createWithTTF("vertexZ = 50", "fonts/Marker Felt.ttf", 64);
label->setPosition(Vec2(size.width / 2, size.height * 0.25f));
this->addChild(label);
auto label2 = Label::createWithTTF("vertexZ = 0", "fonts/Marker Felt.ttf", 64);
label2->setPosition(Vec2(size.width / 2, size.height * 0.5f));
this->addChild(label2);
auto label3 = Label::createWithTTF("vertexZ = -50", "fonts/Marker Felt.ttf", 64);
label3->setPosition(Vec2(size.width / 2, size.height * 0.75f));
this->addChild(label3);
label->setPositionZ(50);
label2->setPositionZ(0);
label3->setPositionZ(-50);
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/bugs/circle.plist");
mgr = SpriteBatchNode::create("Images/bugs/circle.png", 9);
this->addChild(mgr);
sp1 = Sprite::createWithSpriteFrameName("circle.png");
sp2 = Sprite::createWithSpriteFrameName("circle.png");
sp3 = Sprite::createWithSpriteFrameName("circle.png");
sp4 = Sprite::createWithSpriteFrameName("circle.png");
sp5 = Sprite::createWithSpriteFrameName("circle.png");
sp6 = Sprite::createWithSpriteFrameName("circle.png");
sp7 = Sprite::createWithSpriteFrameName("circle.png");
sp8 = Sprite::createWithSpriteFrameName("circle.png");
sp9 = Sprite::createWithSpriteFrameName("circle.png");
mgr->addChild(sp1, 9);
mgr->addChild(sp2, 8);
mgr->addChild(sp3, 7);
mgr->addChild(sp4, 6);
mgr->addChild(sp5, 5);
mgr->addChild(sp6, 4);
mgr->addChild(sp7, 3);
mgr->addChild(sp8, 2);
mgr->addChild(sp9, 1);
sp1->setPositionZ(400);
sp2->setPositionZ(300);
sp3->setPositionZ(200);
sp4->setPositionZ(100);
sp5->setPositionZ(0);
sp6->setPositionZ(-100);
sp7->setPositionZ(-200);
sp8->setPositionZ(-300);
sp9->setPositionZ(-400);
sp9->setScale(2);
sp9->setColor(Color3B::YELLOW);
}
示例10: if
void GameNext::update(float dt)
{
//Director::getInstance()->replaceScene(GameMain::createScene());
//std::string str = Value(game_round-1).asString();
second = second + 1;
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
if(second == 10){
std::string pass_pic = "next/next" + gr_pic + "_" + gl_pic + ".png";
auto gameover_pass_pic = Sprite::create(pass_pic);
gameover_pass_pic->setPosition(Vec2(origin.x + visibleSize.width/2-20,
origin.y + visibleSize.height/2+150));
this->addChild(gameover_pass_pic,103);
}else if (second == 50)
{
//if(game_level-1==5)
if(game_level-1==2)
{
Director::getInstance()->replaceScene(First::createScene());
}
else if((game_level-1)<=2)
{
Director::getInstance()->replaceScene(GameMain::createScene());
}
}
/*
if(second == 10)
{
auto gameover_bg = Sprite::create("setting/passpic_bg.png");
gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height/2));
log("%f",visibleSize.width/2);
log("%f",visibleSize.height/2);
this->addChild(gameover_bg,102);
std::string pass_pic = "level/level"+ str +".png";
auto gameover_pass_pic = Sprite::create(pass_pic);
gameover_pass_pic->setPosition(Vec2(origin.x + visibleSize.width/2-20,
origin.y + visibleSize.height/2+150));
this->addChild(gameover_pass_pic,103);
}else if (second == 30)
{
std::string pass_pic = "level/level"+ str +"_ok.png";
auto gameover_bg = Sprite::create(pass_pic);
gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2+250,
origin.y + visibleSize.height/2+180));
this->addChild(gameover_bg,103);
}else if (second == 50)
{
std::string pass_pic = "level/level"+ str +"_got.png";
auto gameover_bg = Sprite::create(pass_pic);
gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height/2-50));
this->addChild(gameover_bg,103);
auto feed_this = CCLabelTTF::create("", "Arial", 50);
feed_this->setColor(cocos2d::Color3B(100, 60, 60));
feed_this->retain();
feed_this->setPosition(origin.x + visibleSize.width/2-10,
origin.y + visibleSize.height/2-68);
char str_1[100];
sprintf(str_1, " %d ", feed_index);
feed_this->setString(str_1);
feed_this->setVisible(true);
this->addChild(feed_this, 103);
}else if (second == 70)
{
std::string pass_pic = "level/level"+ str +"_oh.png";
auto gameover_bg = Sprite::create(pass_pic);
gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2+285,
origin.y + visibleSize.height/2-60));
this->addChild(gameover_bg,103);
}else if (second == 120)
{
if(baby>0)
{
std::string pass_pic = "level/level"+ str +"_gotnew.png";
auto gameover_bg = Sprite::create(pass_pic);
//.........这里部分代码省略.........
示例11: Size
// on "init" you need to initialize your instance
bool S_About::init()
{
m_bClose = false;
// super init
if ( !BaseScene::init((E::P.C100)) )
{
return false;
}
m_titleBar = TitleBar::create(S("About", "关于"));
this->addChild(m_titleBar, 1000);
m_heartBtn = EdgedBallButton::create(CC_CALLBACK_1(S_About::menuCallback, this));
m_heartBtn->setScale(0.3f);
m_heartBtn->setPosition(Vec2(48, 40));
m_heartBtn->setTag(TAG_BACK);
m_titleBar->addChild(m_heartBtn, 1000);
m_heartIcon = Sprite::create("ui/ob_go_back.png");
m_heartIcon->setColor(C3B(E::P.C700));
m_heartIcon->setScale(0.9f);
m_heartIcon->setAnchorPoint(Vec2(0.5, 0.5));
m_heartIcon->setPosition(m_heartBtn->getContentSize() / 2);
m_heartBtn->addChild(m_heartIcon, 1000);
// create solid color background
m_btmBg = BallButton::create(E::P.C50);
m_btmBg->setScale(0.3f);
m_btmBg->setPosition(Vec2(E::visibleWidth/2, 128+(-9/15.0f)*128));
// m_btmBg->setTag(TAG_BTM_BG);
this->addChild(m_btmBg, 0);
// create solid color background
m_bgTop = LayerColor::create(C4B(E::P.C100));
// m_bgTop->setTag(TAG_BG_TOP);
m_bgTop->setContentSize(Size(E::visibleWidth, E::visibleHeight - BTM_HEIGHT));
m_bgTop->setPosition(0, BTM_HEIGHT);
this->addChild(m_bgTop, 0);
// create the shadow
m_shadow = Sprite::create("ui/shadow.png");
m_shadow->setScale(1.0f);
m_shadow->setAnchorPoint(Vec2(0, 1));
m_shadow->setScaleX(E::visibleWidth / DESIGNED_WIDTH);
m_shadow->setPosition(0, BTM_HEIGHT);
// m_shadow->setTag(TAG_SHADOW);
m_shadow->setOpacity(0);
this->addChild(m_shadow, 0);
//============================================================
auto icon = Sprite::create("icon.png");
icon->setScale(0.6f);
icon->setPosition(E::visibleWidth/2, E::originY + 640 - 24);
this->addChild(icon, 0);
auto lbTitle = Label::createWithTTF(GAME_TITLE, FONT_BOLD, 24,
Size(256, 32), TextHAlignment::CENTER, TextVAlignment::CENTER);
lbTitle->setPosition(E::visibleWidth/2, E::originY + 480 + 32);
lbTitle->setAnchorPoint(Vec2(0.5, 0.5));
lbTitle->setColor(C3B(E::P.C900));
this->addChild(lbTitle, 0);
auto lbVersion = Label::createWithTTF("Ver: " VERSION, FONT_MAIN, 24,
Size(256, 32), TextHAlignment::CENTER, TextVAlignment::CENTER);
lbVersion->setPosition(E::visibleWidth/2, E::originY + 480);
lbVersion->setAnchorPoint(Vec2(0.5, 0.5));
lbVersion->setColor(C3B(E::P.C900));
this->addChild(lbVersion, 0);
#define OFFSET_Y__ (320)
auto iconCharmy = Sprite::create("g_charmy_av.png");
iconCharmy->setScale(0.6f);
iconCharmy->setAnchorPoint(Vec2(0, 0.5));
iconCharmy->setPosition(E::originX + 24, E::originY + OFFSET_Y__);
this->addChild(iconCharmy, 0);
auto lbCharmy = Label::createWithTTF(S("CharmySoft", "尘泯网络"), FONT_BOLD, 28,
Size(320, 64), TextHAlignment::CENTER, TextVAlignment::CENTER);
lbCharmy->setPosition(E::visibleWidth/2 + 80, E::originY + OFFSET_Y__ + 48);
lbCharmy->setAnchorPoint(Vec2(0.5, 0.5));
lbCharmy->setColor(C3B(E::P.C900));
this->addChild(lbCharmy, 0);
auto lbCharmyDetail = Label::createWithTTF(S("Charmy Game and Software Development", "尘羽泯游戏软件开发"), FONT_MAIN, 24,
Size(320, 64), TextHAlignment::CENTER, TextVAlignment::CENTER);
lbCharmyDetail->setPosition(E::visibleWidth/2 + 80, E::originY + OFFSET_Y__ );
lbCharmyDetail->setAnchorPoint(Vec2(0.5, 0.5));
lbCharmyDetail->setColor(C3B(E::P.C900));
this->addChild(lbCharmyDetail, 0);
auto lbLink = Label::createWithTTF(S("http://www.CharmySoft.com", "www.CharmySoft.com"), FONT_MAIN, 24,
Size(256, 64), TextHAlignment::CENTER, TextVAlignment::CENTER);
lbLink->setPosition(E::visibleWidth/2 + 80, E::originY + OFFSET_Y__ - 48);
lbLink->setAnchorPoint(Vec2(0.5, 0.5));
lbLink->setColor(C3B(E::P.C900));
this->addChild(lbLink, 0);
//.........这里部分代码省略.........
示例12: glfwGetCursorPos
Vec2 GameWindow::GetWindowMPos()
{
double mousex, mousey;
glfwGetCursorPos(wnd, &mousex, &mousey);
return Vec2(mousex, mousey);
}
示例13: InitPositions
void LightManager::InitPositions()
{
m_positions.push_back(Vec2(0,0)); //dummy
m_positions.push_back(Vec2(50 + 15, 95 - 10)); //1
m_positions.push_back(Vec2(222+18, 94 - 7));
m_positions.push_back(Vec2(60 + 15, 201- 7)); //2
m_positions.push_back(Vec2(217 + 15, 200 - 5));
m_positions.push_back(Vec2(86 + 10, 290 - 5)); //3
m_positions.push_back(Vec2(209 + 13, 290 - 5));
m_positions.push_back(Vec2(93 + 11, 356)); //4
m_positions.push_back(Vec2(204 + 10, 357 - 3));
m_positions.push_back(Vec2(102 + 10, 414-1)); //5
m_positions.push_back(Vec2(202 + 5, 416 - 3));
m_positions.push_back(Vec2(110 + 7, 468)); //6
m_positions.push_back(Vec2(194 + 11, 470));
}
示例14: Vec2
bool RunnerSprite::isCollisionWithRight(cocos2d::Rect box){
auto manBox = mRunner->boundingBox();
Vec2 manPoint = Vec2(manBox.getMaxX(),manBox.getMidY());
return box.containsPoint(manPoint);
}
示例15: calculateItemPositionWithAnchor
static Vec2 calculateItemPositionWithAnchor(Widget* item, const Vec2& itemAnchorPoint)
{
Vec2 origin(item->getLeftBoundary(), item->getBottomBoundary());
Size size = item->getContentSize();
return origin + Vec2(size.width * itemAnchorPoint.x, size.height * itemAnchorPoint.y);
}