本文整理汇总了C++中Global::getInstance方法的典型用法代码示例。如果您正苦于以下问题:C++ Global::getInstance方法的具体用法?C++ Global::getInstance怎么用?C++ Global::getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Global
的用法示例。
在下文中一共展示了Global::getInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: moveAgent
//移动角色
void Player::moveAgent(const cocos2d::Vec3 &des)
{
if (m_canAct == false)
{
return;
}
Global *global = Global::getInstance();
if (global->getInstance()->_playerObj != this)
{
return;
}
NavMeshAgent::MoveCallback callback = [](NavMeshAgent *agent, float totalTimeAfterMove)
{
AgentUserData *data = static_cast<AgentUserData *>(agent->getUserData());
if (agent->isOnOffMeshLink())
{
agent->setAutoTraverseOffMeshLink(false);
agent->setAutoOrientation(false);
OffMeshLinkData linkdata = agent->getCurrentOffMeshLinkData();
agent->getOwner()->setPosition3D(jump(&linkdata.startPosition, &linkdata.endPosition, 10.0f, data->time));
Vec3 dir = linkdata.endPosition - linkdata.startPosition;
dir.y = 0.0f;
dir.normalize();
Vec3 axes;
Vec3 refAxes = Vec3(-1.0f, 0.0f, 1.0f);
refAxes.normalize();
Vec3::cross(refAxes, dir, &axes);
float angle = Vec3::dot(refAxes, dir);
agent->getOwner()->setRotationQuat(Quaternion(axes, acosf(angle)));
data->time += 0.01f;
if (1.0f < data->time)
{
agent->completeOffMeshLink();
agent->setAutoOrientation(true);
data->time = 0.0f;
}
}
};
m_agent->move(des, callback);
}
示例2: update
void Player::update(float dt)
{
Global *global = Global::getInstance();
if (global->getInstance()->_playerObj != this)
{
return;
}
int a = global->multiBtn->getDirValue();
float angle = a;
// log("----->%f %f %f", global->hitPosition.x, global->hitPosition.y, global->hitPosition.z);
float rotation = calAngle();
this->setPlayerAngle(a);
// log("-------> %f", rotation);
// log("-----------> %f %f %f", barrelV.x, barrelV.y, barrelV.z);
// rotation = rotation + 180 -90;
if (global->multiBtn->getIsFired())
{
this->setIsFired(global->multiBtn->getIsFired());//////////////////////////////////////////
Bomb *bomb = Bomb::create();
m_curBomb = bomb;
Physics3DRigidBodyDes rbDes;
// rbDes.originalTransform.translate(global->_camera->getPosition3D());
rbDes.mass = 1.f;
rbDes.shape = Physics3DShape::createSphere(0.5f);
Vec3 start = m_tank->getPosition3D();
bomb->set3DParams("model/box.c3t", "Icon.png", &rbDes, start, 0.5f);
bomb->setRigidParams(Vec3::ONE, Vec3::ZERO, 0.5f, 0.4f);
float l = 6.0f;
float x0 = 0.0f, y0 = 0.0f, z0 = 0.0f;
y0 = l * std::sin(angle * PI / 180);
float l0 = l * std::cos(angle * PI / 180);
x0 = start.x + l0 * std::sin(rotation * PI / 180);
z0 = start.z + l0 * std::cos(rotation * PI / 180);
Vec3 dir(x0, y0, z0);//方向向量
dir = dir - start;
float power = 100; //power
bomb->setDirAndPower(dir, power);
bomb->setCameraMask((unsigned short)CameraFlag::USER1);
this->addChild(bomb);
//////////////////////////////////////////
global->multiBtn->setIsFired(false);
}
if (m_curBomb == nullptr)
{
return;
}
if (m_curBomb->getBombIsDead())
{
setIsBombDidLanded(1);
m_curBomb->setBombIsDead(0);
// this->removeFromParent();
}
}