本文整理汇总了C++中CC_RECT_PIXELS_TO_POINTS函数的典型用法代码示例。如果您正苦于以下问题:C++ CC_RECT_PIXELS_TO_POINTS函数的具体用法?C++ CC_RECT_PIXELS_TO_POINTS怎么用?C++ CC_RECT_PIXELS_TO_POINTS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CC_RECT_PIXELS_TO_POINTS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CCAssert
// CCTMXLayer - obtaining tiles/gids
CCSprite * CCTMXLayer::tileAt(const CCPoint& pos)
{
CCAssert( pos.x < m_tLayerSize.width && pos.y < m_tLayerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
CCAssert( m_pTiles && m_pAtlasIndexArray, "TMXLayer: the tiles map has been released");
CCSprite *tile = NULL;
unsigned int gid = this->tileGIDAt(pos);
// if GID == 0, then no tile is present
if( gid )
{
int z = (int)(pos.x + pos.y * m_tLayerSize.width);
tile = (CCSprite*) this->getChildByTag(z);
// tile not created yet. create it
if( ! tile )
{
CCRect rect = m_pTileSet->rectForGID(gid);
rect = CC_RECT_PIXELS_TO_POINTS(rect);
tile = new CCSprite();
tile->initWithTexture(this->getTexture(), rect);
tile->setBatchNode(this);
tile->setPosition(positionAt(pos));
tile->setVertexZ((float)vertexZForPos(pos));
tile->setAnchorPoint(CCPointZero);
tile->setOpacity(m_cOpacity);
unsigned int indexForZ = atlasIndexForExistantZ(z);
this->addSpriteWithoutQuad(tile, indexForZ, z);
tile->release();
}
}
return tile;
}
示例2: CC_RECT_PIXELS_TO_POINTS
// used only when parsing the map. useless after the map was parsed
// since lot's of assumptions are no longer true
Sprite * TMXLayer::appendTileForGID(int gid, const Point& pos)
{
if (gid != 0 && (static_cast<int>((gid & kFlippedMask)) - _tileSet->_firstGid) >= 0)
{
Rect rect = _tileSet->rectForGID(gid);
rect = CC_RECT_PIXELS_TO_POINTS(rect);
intptr_t z = (intptr_t)(pos.x + pos.y * _layerSize.width);
Sprite *tile = reusedTileWithRect(rect);
setupTileSprite(tile ,pos ,gid);
// optimization:
// The difference between appendTileForGID and insertTileforGID is that append is faster, since
// it appends the tile at the end of the texture atlas
ssize_t indexForZ = _atlasIndexArray->num;
// don't add it using the "standard" way.
insertQuadFromSprite(tile, indexForZ);
// append should be after addQuadFromSprite since it modifies the quantity values
ccCArrayInsertValueAtIndex(_atlasIndexArray, (void*)z, indexForZ);
return tile;
}
return nullptr;
}
示例3: CCASSERT
// TMXLayer - obtaining tiles/gids
Sprite * TMXLayer::getTileAt(const Point& pos)
{
CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
Sprite *tile = nullptr;
int gid = this->getTileGIDAt(pos);
// if GID == 0, then no tile is present
if (gid)
{
int z = (int)(pos.x + pos.y * _layerSize.width);
tile = static_cast<Sprite*>(this->getChildByTag(z));
// tile not created yet. create it
if (! tile)
{
Rect rect = _tileSet->rectForGID(gid);
rect = CC_RECT_PIXELS_TO_POINTS(rect);
tile = Sprite::createWithTexture(this->getTexture(), rect);
tile->setBatchNode(this);
tile->setPosition(getPositionAt(pos));
tile->setVertexZ((float)getVertexZForPos(pos));
tile->setAnchorPoint(Point::ZERO);
tile->setOpacity(_opacity);
ssize_t indexForZ = atlasIndexForExistantZ(z);
this->addSpriteWithoutQuad(tile, static_cast<int>(indexForZ), z);
}
}
return tile;
}
示例4: CC_RECT_PIXELS_TO_POINTS
void Factory::initSpriteFrame(){
auto texture = Director::getInstance()->getTextureCache()->addImage("Monster.png");
monsterDead.reserve(4);
for (int i = 0; i < 4; i++) {
auto frame = SpriteFrame::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(258-48*i,0,42,42)));
monsterDead.pushBack(frame);
}
}
示例5: CC_RECT_PIXELS_TO_POINTS
cocos2d::Animation * BaseSprite::createAnimation(const char* formatStr, float width, float height, int frameCount, float f)
{
cocos2d::Vector<SpriteFrame*> frames;
frames.reserve(frameCount);
auto texture = Director::getInstance()->getTextureCache()->addImage(formatStr);
width = width / frameCount;
for (int i = 0; i < frameCount; i++)
{
auto frame = SpriteFrame::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(width * i, 0, width, height)));
frames.pushBack(frame);
}
return Animation::createWithSpriteFrames(frames, f);
}
示例6: CC_RECT_PIXELS_TO_POINTS
bool CCSpriteFrame::initWithTextureFilename(const char* filename, const CCRect& rect, bool rotated, const CCPoint& offset, const CCSize& originalSize)
{
m_pobTexture = NULL;
m_strTextureFilename = filename;
m_obRectInPixels = rect;
m_obRect = CC_RECT_PIXELS_TO_POINTS( rect );
m_obOffsetInPixels = offset;
m_obOffset = CC_POINT_PIXELS_TO_POINTS( m_obOffsetInPixels );
m_obOriginalSizeInPixels = originalSize;
m_obOriginalSize = CC_SIZE_PIXELS_TO_POINTS( m_obOriginalSizeInPixels );
m_bRotated = rotated;
return true;
}
示例7: CC_RECT_PIXELS_TO_POINTS
bool SpriteFrame::initWithTextureFilename(const std::string& filename, const Rect& rect, bool rotated, const Vec2& offset, const Size& originalSize)
{
_texture = nullptr;
_textureFilename = filename;
_rectInPixels = rect;
_rect = CC_RECT_PIXELS_TO_POINTS( rect );
_offsetInPixels = offset;
_offset = CC_POINT_PIXELS_TO_POINTS( _offsetInPixels );
_originalSizeInPixels = originalSize;
_originalSize = CC_SIZE_PIXELS_TO_POINTS( _originalSizeInPixels );
_rotated = rotated;
return true;
}
示例8: CC_RECT_PIXELS_TO_POINTS
bool SpriteFrame::initWithTextureFilename(const char* filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
{
_texture = NULL;
_textureFilename = filename;
_rectInPixels = rect;
_rect = CC_RECT_PIXELS_TO_POINTS( rect );
_offsetInPixels = offset;
_offset = CC_POINT_PIXELS_TO_POINTS( _offsetInPixels );
_originalSizeInPixels = originalSize;
_originalSize = CC_SIZE_PIXELS_TO_POINTS( _originalSizeInPixels );
_rotated = rotated;
return true;
}
示例9: CCASSERT
void TMXLayer::setTileGID(int gid, const Vec2& tileCoordinate, TMXTileFlags flags)
{
CCASSERT(tileCoordinate.x < _layerSize.width && tileCoordinate.y < _layerSize.height && tileCoordinate.x >=0 && tileCoordinate.y >=0, "TMXLayer: invalid position");
CCASSERT(_tiles, "TMXLayer: the tiles map has been released");
CCASSERT(gid == 0 || gid >= _tileSet->_firstGid, "TMXLayer: invalid gid" );
TMXTileFlags currentFlags;
int currentGID = getTileGIDAt(tileCoordinate, ¤tFlags);
if (currentGID == gid && currentFlags == flags) return;
int gidAndFlags = gid | flags;
// setting gid=0 is equal to remove the tile
if (gid == 0)
{
removeTileAt(tileCoordinate);
}
// empty tile. create a new one
else if (currentGID == 0)
{
int z = tileCoordinate.x + tileCoordinate.y * _layerSize.width;
setFlaggedTileGIDByIndex(z, gidAndFlags);
}
// modifying an existing tile with a non-empty tile
else
{
int z = tileCoordinate.x + tileCoordinate.y * _layerSize.width;
auto it = _spriteContainer.find(z);
if (it != _spriteContainer.end())
{
Sprite *sprite = it->second.first;
Rect rect = _tileSet->getRectForGID(gid);
rect = CC_RECT_PIXELS_TO_POINTS(rect);
sprite->setTextureRect(rect, false, rect.size);
this->reorderChild(sprite, z);
if (flags)
{
setupTileSprite(sprite, sprite->getPosition(), gidAndFlags);
}
it->second.second = gidAndFlags;
}
else
{
setFlaggedTileGIDByIndex(z, gidAndFlags);
}
}
}
示例10: CC_RECT_PIXELS_TO_POINTS
void CCSprite::setTextureRectInPixels(CGRect rect, bool rotated, CGSize size)
{
m_obRectInPixels = rect;
m_obRect = CC_RECT_PIXELS_TO_POINTS(rect);
m_bRectRotated = rotated;
setContentSizeInPixels(size);
updateTextureCoords(m_obRectInPixels);
CGPoint relativeOffsetInPixels = m_obUnflippedOffsetPositionFromCenter;
// issue #732
if (m_bFlipX)
{
relativeOffsetInPixels.x = -relativeOffsetInPixels.x;
}
if (m_bFlipY)
{
relativeOffsetInPixels.y = -relativeOffsetInPixels.y;
}
m_obOffsetPositionInPixels.x = relativeOffsetInPixels.x + (m_tContentSizeInPixels.width - m_obRectInPixels.size.width) / 2;
m_obOffsetPositionInPixels.y = relativeOffsetInPixels.y + (m_tContentSizeInPixels.height - m_obRectInPixels.size.height) / 2;
// rendering using SpriteSheet
if (m_bUsesBatchNode)
{
// update dirty_, don't update recursiveDirty_
m_bDirty = true;
}
else
{
// self rendering
// Atlas: Vertex
float x1 = 0 + m_obOffsetPositionInPixels.x;
float y1 = 0 + m_obOffsetPositionInPixels.y;
float x2 = x1 + m_obRectInPixels.size.width;
float y2 = y1 + m_obRectInPixels.size.height;
// Don't update Z.
m_sQuad.bl.vertices = vertex3(x1, y1, 0);
m_sQuad.br.vertices = vertex3(x2, y1, 0);
m_sQuad.tl.vertices = vertex3(x1, y2, 0);
m_sQuad.tr.vertices = vertex3(x2, y2, 0);
}
}
示例11: CC_RECT_PIXELS_TO_POINTS
bool SpriteFrame::initWithTextureFilename(const std::string& filename, const Rect& rect, bool rotated, const Vec2& offset, const Size& originalSize)
{
if (FileUtils::getInstance()->isFileExist(filename)) {
_texture = nullptr;
_textureFilename = filename;
_rectInPixels = rect;
_rect = CC_RECT_PIXELS_TO_POINTS( rect );
_offsetInPixels = offset;
_offset = CC_POINT_PIXELS_TO_POINTS( _offsetInPixels );
_originalSizeInPixels = originalSize;
_originalSize = CC_SIZE_PIXELS_TO_POINTS( _originalSizeInPixels );
_rotated = rotated;
_anchorPoint = Vec2(NAN, NAN);
_centerRect = Rect(NAN, NAN, NAN, NAN);
return true;
}
return false;
}
示例12: CC_RECT_PIXELS_TO_POINTS
bool CCSpriteFrame::initWithTexture(CCTexture2D* pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize)
{
m_pobTexture = pobTexture;
if (pobTexture)
{
pobTexture->retain();
}
m_obRectInPixels = rect;
m_obRect = CC_RECT_PIXELS_TO_POINTS(rect);
m_bRotated = rotated;
m_obOffsetInPixels = offset;
m_obOriginalSizeInPixels = originalSize;
return true;
}
示例13: CC_SAFE_RETAIN
bool CCSpriteFrame::initWithTexture(CCTexture2D* pobTexture, const CCRect& rect, bool rotated, const CCPoint& offset, const CCSize& originalSize)
{
m_pobTexture = pobTexture;
if (pobTexture)
{
CC_SAFE_RETAIN(pobTexture);
}
m_obRectInPixels = rect;
m_obRect = CC_RECT_PIXELS_TO_POINTS(rect);
m_obOffsetInPixels = offset;
m_obOffset = CC_POINT_PIXELS_TO_POINTS( m_obOffsetInPixels );
m_obOriginalSizeInPixels = originalSize;
m_obOriginalSize = CC_SIZE_PIXELS_TO_POINTS( m_obOriginalSizeInPixels );
m_bRotated = rotated;
return true;
}
示例14: CC_RECT_PIXELS_TO_POINTS
// CCTMXLayer - adding helper methods
CCSprite * CCTMXLayer::insertTileForGID(unsigned int gid, const CCPoint& pos)
{
CCRect rect = m_pTileSet->rectForGID(gid);
rect = CC_RECT_PIXELS_TO_POINTS(rect);
intptr_t z = (intptr_t)(pos.x + pos.y * m_tLayerSize.width);
// if quad optimization is used
CCSprite *tile;
if(m_pAtlasIndexArray)
{
tile = reusedTileWithRect(rect);
setupTileSprite(tile, pos, gid);
// get atlas index
unsigned int indexForZ = atlasIndexForNewZ(z);
// Optimization: add the quad without adding a child
this->insertQuadFromSprite(tile, indexForZ);
// insert it into the local atlasindex array
ccCArrayInsertValueAtIndex(m_pAtlasIndexArray, (void*)z, indexForZ);
// update possible children
if (m_pChildren && m_pChildren->count()>0)
{
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
unsigned int ai = pChild->getAtlasIndex();
if ( ai >= indexForZ )
{
pChild->setAtlasIndex(ai+1);
}
}
}
}
示例15: CC_RECT_PIXELS_TO_POINTS
bool Enemy::init()
{
bool ret = false;
do
{
auto texture = Director::getInstance()->getTextureCache()->addImage("Enemy_walk.png");
auto frame0 = SpriteFrame::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(0, 0, 114, 110)));
CC_BREAK_IF(!this->initWithSpriteFrame(frame0));
Animation* idleAnim = this->createAnimation("Enemy_idle.png", 206, 100, 2, 0.3);
this->setIdleAction(RepeatForever::create(Animate::create(idleAnim)));
Animation* walkAnim = this->createAnimation("Enemy_walk.png", 412, 100, 4, 0.1);
this->setWalkAction(RepeatForever::create(Animate::create(walkAnim)));
Animation* attackAnim = this->createAnimation("Enemy_attack.png", 515, 100, 5, 0.08);
this->setAttackAction(Sequence::create(Animate::create(attackAnim), BaseSprite::createIdleCallbackFunc(), NULL));
Animation* hurtAnim = this->createAnimation("Enemy_idle.png", 228, 110, 2, 0.3); // 因为没有图,所以还没实现
this->setHurtAction(Sequence::create(Animate::create(hurtAnim), BaseSprite::createIdleCallbackFunc(), NULL));
Animation* deadAnim = this->createAnimation("Enemy_idle.png", 228, 110, 2, 0.3); // 因为没有图,所以还没实现
this->setDeadAction(Sequence::create(Animate::create(deadAnim), Blink::create(3, 9), NULL));
ret = true;
} while (0);
return ret;
}