本文整理汇总了C++中BallSprite类的典型用法代码示例。如果您正苦于以下问题:C++ BallSprite类的具体用法?C++ BallSprite怎么用?C++ BallSprite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BallSprite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: actionEndCallback
void BallMap::actionEndCallback(CCNode *node)
{
BallSprite *ball = (BallSprite *)node;
ball->set_isMoving(false);
m_matrix[ball->getRow() * (int)m_size.width + ball->getCol()] = NULL;
ball->removeFromParent();
}
示例2: removeBall
void BallMap::removeBall()
{
// make sequence remove
m_isAnimationing = true;
std::list<BallSprite *>::iterator itList;
for (itList = m_readyRemoveList.begin(); itList != m_readyRemoveList.end(); itList++)
{
BallSprite *ball = dynamic_cast<BallSprite*>(*itList);
if (!ball)
{
continue;
}
if (ball->getIsNeedRemove())
{
m_isNeedFillVacancies = true;//需要掉落
m_isNeedCheckSelf = true;
explodeBall(ball);
}
}
m_readyRemoveList.clear();
}
示例3:
void GameScene_Box2D::delTouchedBalls() {
std::vector<BallSprite*>::iterator tempIterator;
std::vector<BallSprite*> tmpbollArray;
std::vector<std::vector<BallSprite*>::iterator> deleteIteratorArray;
for( tempIterator = _bollArray.begin(); tempIterator != _bollArray.end(); tempIterator++ ) {
BallSprite *ball = (BallSprite *)*tempIterator;
if (ball->getDeleteState()==BallSprite::deleteState::kDelete) {
_delballPos.push_back(ball->getPosition());
// _world->DestroyBody(ball->getB2Body());
ball->deleteParticle(_particleSystem,_particleGroup);
ball->removeFromParent();
}
else {
tmpbollArray.push_back(ball);
}
}
_bollArray.clear();
for (auto nodelball = tmpbollArray.begin(); nodelball != tmpbollArray.end(); nodelball++) {
BallSprite *ball = (BallSprite *)*nodelball;
_bollArray.push_back(ball);
}
}
示例4: getBallRadius
BallSprite *BallSprite::createBallSprite(Node *parent ,b2World *world, const std::string& filename)
{
BallSprite* pInstance = BallSprite::create();
//Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename);
pInstance->setTexture(filename);
// shape.m_radius = sptite->getContentSize().width / PTM_RATIO; // 形状の大きさ
/**
*
剛体は次の手順で作成する。剛体とは物理エンジンの影響をうけることが出来る物質のこと
1. 位置・減衰率などで剛体を定義する。
2. 剛体を作成するためにワールドを使用する。
3. 図形・摩擦・密度などから装備を定義する。
4. 剛体から装備を作成する。
*/
b2Body* body; // 剛体。rigid body。
b2BodyDef bodyDef; // 剛体の定義
b2CircleShape shape; // 装備の形状
float radius = getBallRadius();
shape.m_radius = radius/ PTM_RATIO;;
b2FixtureDef fixtureDef; // 装備の形状定義
// 1. 位置・減衰率などで剛体を定義する。
bodyDef.type = b2_dynamicBody;
//bodyDef.position.Set((winSize.width / 2) / PTM_RATIO, (winSize.height) / PTM_RATIO);
bodyDef.userData = pInstance; // 画像をこの剛体に紐付ける
// 2. 剛体を作成するためにワールドを使用する。
body = world->CreateBody(&bodyDef);
fixtureDef.shape = &shape; // 形状を紐付ける
fixtureDef.density = 1; // 密度
fixtureDef.friction = 0.9; // 摩擦
// 4. 剛体から装備を作成する。
body->CreateFixture(&fixtureDef);
/** PhysicsSpriteに各種情報をセットする */
//parent->addChild(pInstance);
pInstance->setB2Body(body);
pInstance->setPTMRatio(PTM_RATIO);
parent->addChild(pInstance);
return pInstance;
}
示例5: updateBall
void GameScene::updateBall() {
if (!isTouched) {
return;
}
for (int i = 0; i < m_activeballs->count(); i++) {
BallSprite* ball =
dynamic_cast<BallSprite*>(m_activeballs->objectAtIndex(i));
if (!ball)
return;
CCPoint ballPoint = ball->getPosition();
float vx = ball->getVelocityX();
float vy = ball->getVelocityY();
// ボールの移動
// CCLOG("# updateBall1 #ball position X: %f, Y: %f",
// ball->getPositionX(), ball->getPositionY());
ball->setPosition(ccp(ball->getPositionX() + vx,
ball->getPositionY() + vy));
// CCLOG("# updateBall2 #ball position X: %f, Y: %f",
// ball->getPositionX(), ball->getPositionY());
if (ballPoint.y < 0) {
//ユーザーがボールを奈落に落とした
onBallLost(ball);
return;
}
//壁との衝突判定
ball->bounceBall(g_visibleSize);
}
}
示例6: BallSprite
//インスタンス生成
BallSprite* BallSprite::create(BallType type, bool visible)
{
BallSprite *pRet = new BallSprite();
if (pRet && pRet->init(type, visible))
{
pRet->autorelease();
return pRet;
}
else
{
delete pRet;
pRet = nullptr;
return nullptr;
}
}
示例7: BallSprite
BallSprite* BallSprite::create(GameLayer * game, int type, CCPoint position) {
/*
Create sprite with image file name.
Args:
pszFileName: char *, string of file name
Returns:
BallSprite *
*/
BallSprite *sprite = new BallSprite(game, type, position);
if (sprite) {
sprite->initBall();
sprite->autorelease();
return sprite;
}
CC_SAFE_DELETE(sprite);
return NULL;
}
示例8: updateBlocks
void GameScene::updateBlocks() {
for (int i = 0; i < m_activeballs->count(); i++) {
BallSprite* ball =
dynamic_cast<BallSprite*>(m_activeballs->objectAtIndex(i));
if (!ball)
return;
CCRect ballRect = ball->boundingBox();
CCObject* jt = NULL;
CCArray* blocksToDelete = new CCArray;
CCARRAY_FOREACH(m_blocks, jt) {
CCSprite* block = dynamic_cast<CCSprite*>(jt);
// CCLOG("updateGame target.x: %f, target.y: %f, tag: %d",target->getContentSize().width, target->getContentSize().height, target->getTag());
CCRect blockRect = block->boundingBox();
//衝突判定
if (ballRect.intersectsRect(blockRect)) {
// ボールは跳ね返す
ball->bounceBall(blockRect, kTagBlock);
blocksToDelete->addObject(block);
//スコア加算
m_score += 100;
showScore();
//確率に従ってボーナスアイテムを生成する
makeItem(block);
}
}
// 当たったブロックを消す
CCARRAY_FOREACH(blocksToDelete, jt) {
CCSprite *block = dynamic_cast<CCSprite*>(jt);
m_blocks->removeObject(block);
this->removeChild(block, true);
m_blocksDestroyed++;
}
示例9: mt
BallSprite *GameScene_Box2D::createSprite(Vec2 &pos, Vec2 &velocity){
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<double> intval(0,3);
int val = (int)intval(mt);
__String *filename;
BallSprite::ballType type;
switch (val) {
case 0:
filename = String::create("ball.png");
type = BallSprite::ballType::kRed;
break;
case 1:
filename = String::create("pur_ball.png");
type = BallSprite::ballType::kPurple;
break;
case 2:
filename = String::create("blue_ball.png");
type = BallSprite::ballType::kBrue;
break;
case 3:
filename = String::create("yellow_ball.png");
type = BallSprite::ballType::kYellow;
break;
default:
filename = String::create("ball.png");
type = BallSprite::ballType::kBrue;
break;
}
//BallSprite *ball = BallSprite::createBallSprite(this, _world, filename->getCString());
BallSprite *ball = BallSprite::createParticleSprite(this, _world, _particleSystem, _particleGroup, filename->getCString());
//ball->setPosition(pos);
ball->setParticlePpos(_particleSystem, _particleGroup, pos.x, pos.y, velocity.x, velocity.y);
ball->setTag(spriteType::kBall);
ball->setBallType(type);
_bollArray.push_back(ball);
return ball;
}
示例10: setBall
void GameScene::setBall() {
//ボールをバー上に配置する
if (m_balls->count() <= 0) {
return;
}
BallSprite* ball = dynamic_cast<BallSprite*>(m_balls->objectAtIndex(0));
CCNode *bar = this->getChildByTag(kTagBar);
// CCRect rect = bar->boundingBox();
ball->setPosition(
ccp(bar->getPositionX(), bar->getPositionY() + bar->getContentSize().height + 10));
// CCLOG("# setBall #bar.width: %f, height: %f",
// bar->getContentSize().width, bar->getContentSize().height);
// CCLOG("# setBall #bar position X: %f, Y: %f",
// bar->getPositionX(), bar->getPositionY());
// ball->setPosition(
// ccp(bar->getPositionX() + bar->getContentSize().width / 2, bar->getPositionY() + bar->getContentSize().height));
this->addChild(ball);
m_balls->removeObjectAtIndex(0);
m_activeballs->addObject(ball);
}
示例11: createAndDropBall
void BallMap::createAndDropBall(int row, int col)
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
BallSprite *ball = BallSprite::create(row, col);
// create animation
CCPoint endPosition = positionOfItem(ball);
CCPoint startPosition = CCPoint(endPosition.x, endPosition.y + size.height / 2);
ball->setPosition(startPosition);
float speed = startPosition.y / (2.0 * size.height);
ball->runAction(CCSequence::create(
CCMoveTo::create(speed, endPosition),
CCCallFuncN::create(this, callfuncN_selector(BallMap::setBallNoMoving)),
NULL));
// add to BatchNode
m_joyPad->get_spriteNode()->addChild(ball);
m_matrix[row * (int)m_size.width + col] = ball;
}
示例12: mt
BallSprite *GameScene_Chipmunk::createSprite(Vec2 &pos){
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<double> intval(0,3);
int val = (int)intval(mt);
__String *filename;
BallSprite::ballType type;
switch (val) {
case 0:
filename = String::create("ball.png");
type = BallSprite::ballType::kRed;
break;
case 1:
filename = String::create("pur_ball.png");
type = BallSprite::ballType::kPurple;
break;
case 2:
filename = String::create("blue_ball.png");
type = BallSprite::ballType::kBrue;
break;
case 3:
filename = String::create("yellow_ball.png");
type = BallSprite::ballType::kYellow;
break;
default:
filename = String::create("ball.png");
type = BallSprite::ballType::kBrue;
break;
}
BallSprite *ball = BallSprite::createBallSprite(this, filename->getCString());
ball->setCenter(pos);
ball->setTag(spriteType::kBall);
ball->setBallType(type);
_bollArray.push_back(ball);
return ball;
}
示例13: CCRect
BallSprite *BallMap::BallOfPoint(CCPoint *point)
{
BallSprite *Ball = NULL;
CCRect rect = CCRect(0, 0, 0, 0);
for (int i = 0; i < m_size.height * m_size.width; i++)
{
Ball = m_matrix[i];
if (Ball)
{
rect.origin.x = Ball->getPositionX() - (Ball->getContentSize().width / 2);
rect.origin.y = Ball->getPositionY() - (Ball->getContentSize().height / 2);
rect.size = Ball->getContentSize();
if (rect.containsPoint(*point))
{
return Ball;
}
}
}
return NULL;
}
示例14: update
void BallMap::update(float dt)
{
// check if animationing
if (m_isAnimationing) {
// init with false
m_isAnimationing = false;
for (int i = 0; i < m_size.height * m_size.width; i++)
{
BallSprite *ball = m_matrix[i];
if (ball && ball->get_isMoving())
{
m_isAnimationing = true;
break;
}
}
}
// if Ball is moving, ignore use touch event
m_isTouchEnable = !m_isAnimationing;
if (!m_isAnimationing)
{
if (m_isNeedFillVacancies)
{
//爆炸效果结束后才掉落新寿司,增强打击感
fillVacancies();
m_isNeedFillVacancies = false;
} else
{
if (m_isNeedCheckSelf)
{
checkAndRemoveChain();
}
}
}
}
示例15: delTouchedBalls
void GameScene_Chipmunk::delTouchedBalls() {
std::vector<BallSprite*>::iterator tempIterator;
std::vector<BallSprite*> tmpbollArray;
std::vector<std::vector<BallSprite*>::iterator> deleteIteratorArray;
for( tempIterator = _bollArray.begin(); tempIterator != _bollArray.end(); tempIterator++ ) {
BallSprite *ball = (BallSprite *)*tempIterator;
if (ball->getDeleteState()==BallSprite::deleteState::kDelete) {
_delballPos.push_back(ball->getPosition());
ball->removeFromParent();
}
else {
tmpbollArray.push_back(ball);
}
}
_bollArray.clear();
for (auto nodelball = tmpbollArray.begin(); nodelball != tmpbollArray.end(); nodelball++) {
BallSprite *ball = (BallSprite *)*nodelball;
_bollArray.push_back(ball);
}
}