mirror of https://github.com/axmolengine/axmol.git
fixed #3, CCAtlasNode complete, CCNode is short of Action
This commit is contained in:
parent
72b9b13599
commit
e0b4307d30
|
@ -26,13 +26,121 @@ THE SOFTWARE.
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ccColor3B CCAtlasNode::getColor(void)
|
|
||||||
|
// implementation CCAtlasNode
|
||||||
|
|
||||||
|
// CCAtlasNode - Creation & Init
|
||||||
|
|
||||||
|
CCAtlasNode::CCAtlasNode()
|
||||||
|
{
|
||||||
|
/// @todo
|
||||||
|
}
|
||||||
|
|
||||||
|
CCAtlasNode::~CCAtlasNode()
|
||||||
|
{
|
||||||
|
/// @todo
|
||||||
|
m_pTextureAtlas->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
CCAtlasNode * CCAtlasNode::atlasWithTileFile(std::string &tile, int tileWidth, int tileHeight, int itemsToRender)
|
||||||
|
{
|
||||||
|
/// @todo
|
||||||
|
CCAtlasNode * pAtlasNode = new CCAtlasNode();
|
||||||
|
pAtlasNode->initWithTileFile(tile, tileWidth, tileHeight, itemsToRender);
|
||||||
|
pAtlasNode->autorelease();
|
||||||
|
return pAtlasNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCAtlasNode * CCAtlasNode::initWithTileFile(std::string &tile, int tileWidth, int tileHeight, int itemsToRender)
|
||||||
|
{
|
||||||
|
|
||||||
|
m_nItemWidth = tileWidth;
|
||||||
|
m_nItemHeight = tileHeight;
|
||||||
|
|
||||||
|
m_cOpacity = 255;
|
||||||
|
m_tColor = m_tColorUnmodified = ccWHITE;
|
||||||
|
m_bOpacityModifyRGB = true;
|
||||||
|
|
||||||
|
m_tBlendFunc.src = CC_BLEND_SRC;
|
||||||
|
m_tBlendFunc.dst = CC_BLEND_DST;
|
||||||
|
|
||||||
|
// double retain to avoid the autorelease pool
|
||||||
|
// also, using: self.textureAtlas supports re-initialization without leaking
|
||||||
|
this->m_pTextureAtlas = new CCTextureAtlas();
|
||||||
|
m_pTextureAtlas->initWithFile(tile, itemsToRender);
|
||||||
|
|
||||||
|
this->updateBlendFunc();
|
||||||
|
this->updateOpacityModifyRGB();
|
||||||
|
|
||||||
|
this->calculateMaxItems();
|
||||||
|
this->calculateTexCoordsSteps();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CCAtlasNode - Atlas generation
|
||||||
|
|
||||||
|
void CCAtlasNode::calculateMaxItems()
|
||||||
|
{
|
||||||
|
CGSize s = m_pTextureAtlas->getTexture()->getContentSize();
|
||||||
|
m_nItemsPerColumn = (int)(s.height / m_nItemHeight);
|
||||||
|
m_nItemsPerRow = (int)(s.width / m_nItemWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCAtlasNode:: calculateTexCoordsSteps()
|
||||||
|
{
|
||||||
|
CCTexture2D *tex = m_pTextureAtlas->getTexture();
|
||||||
|
m_fTexStepX = m_nItemWidth / (float)tex->getPixelsWide();
|
||||||
|
m_fTexStepY = m_nItemHeight / (float)tex->getPixelsHigh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCAtlasNode::updateAtlasValues()
|
||||||
|
{
|
||||||
|
NSAssert(false, "CCAtlasNode:Abstract updateAtlasValue not overriden");
|
||||||
|
//[NSException raise:@"CCAtlasNode:Abstract" format:@"updateAtlasValue not overriden"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// CCAtlasNode - draw
|
||||||
|
void CCAtlasNode::draw()
|
||||||
|
{
|
||||||
|
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
|
||||||
|
// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY
|
||||||
|
// Unneeded states: GL_COLOR_ARRAY
|
||||||
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
|
glColor4ub( m_tColor.r, m_tColor.g, m_tColor.b, m_cOpacity);
|
||||||
|
|
||||||
|
bool newBlend = false;
|
||||||
|
if( m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST )
|
||||||
|
{
|
||||||
|
newBlend = true;
|
||||||
|
glBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pTextureAtlas->drawQuads();
|
||||||
|
|
||||||
|
if( newBlend )
|
||||||
|
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
|
||||||
|
|
||||||
|
// is this chepear than saving/restoring color state ?
|
||||||
|
// XXX: There is no need to restore the color to (255,255,255,255). Objects should use the color
|
||||||
|
// XXX: that they need
|
||||||
|
// glColor4ub( 255, 255, 255, 255);
|
||||||
|
|
||||||
|
// restore default GL state
|
||||||
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// CCAtlasNode - RGBA protocol
|
||||||
|
|
||||||
|
ccColor3B CCAtlasNode:: color()
|
||||||
{
|
{
|
||||||
if(m_bOpacityModifyRGB)
|
if(m_bOpacityModifyRGB)
|
||||||
{
|
{
|
||||||
return m_tColorUnmodified;
|
return m_tColorUnmodified;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_tColor;
|
return m_tColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,20 +156,57 @@ void CCAtlasNode::setColor(ccColor3B color3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLubyte CCAtlasNode::getOpacity()
|
GLubyte CCAtlasNode::opacity()
|
||||||
{
|
{
|
||||||
return m_cOpacity;
|
return m_cOpacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAtlasNode::setOpacity(GLubyte opacity)
|
void CCAtlasNode::setOpacity(GLubyte opacity)
|
||||||
{
|
{
|
||||||
// special opacity for premultiplied textures
|
|
||||||
m_cOpacity = opacity;
|
m_cOpacity = opacity;
|
||||||
|
|
||||||
// special opacity for premultiplied textures
|
// special opacity for premultiplied textures
|
||||||
// special opacity for premultiplied textures
|
if( m_bOpacityModifyRGB )
|
||||||
if( m_bOpacityModifyRGB ) //v0.99.1
|
this->setColor(m_bOpacityModifyRGB ? m_tColorUnmodified : m_tColor);
|
||||||
setColor( m_bOpacityModifyRGB ? m_tColorUnmodified : m_tColor ); //--> win32 : alwyas used m_colorUnmodified color. "if" state no required( issue )
|
}
|
||||||
|
|
||||||
|
void CCAtlasNode::setOpacityModifyRGB(bool bValue)
|
||||||
|
{
|
||||||
|
ccColor3B oldColor = this->m_tColor;
|
||||||
|
m_bOpacityModifyRGB = bValue;
|
||||||
|
this->m_tColor = oldColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCAtlasNode::doesOpacityModifyRGB()
|
||||||
|
{
|
||||||
|
return m_bOpacityModifyRGB;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCAtlasNode::updateOpacityModifyRGB()
|
||||||
|
{
|
||||||
|
m_bOpacityModifyRGB = m_pTextureAtlas->getTexture()->getHasPremultipliedAlpha();
|
||||||
|
}
|
||||||
|
|
||||||
|
// CCAtlasNode - CocosNodeTexture protocol
|
||||||
|
|
||||||
|
void CCAtlasNode::updateBlendFunc()
|
||||||
|
{
|
||||||
|
if( ! m_pTextureAtlas->getTexture()->getHasPremultipliedAlpha() ) {
|
||||||
|
m_tBlendFunc.src = GL_SRC_ALPHA;
|
||||||
|
m_tBlendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCAtlasNode::setTexture(CCTexture2D *texture)
|
||||||
|
{
|
||||||
|
m_pTextureAtlas->setTexture(texture);
|
||||||
|
this->updateBlendFunc();
|
||||||
|
this->updateOpacityModifyRGB();
|
||||||
|
}
|
||||||
|
|
||||||
|
CCTexture2D * CCAtlasNode::texture()
|
||||||
|
{
|
||||||
|
return m_pTextureAtlas->getTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "../support/CGPointExtension.h"
|
#include "../support/CGPointExtension.h"
|
||||||
|
#include "../cocoa/CGGeometry.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -600,44 +601,53 @@ void CCNode::draw()
|
||||||
|
|
||||||
void CCNode::visit()
|
void CCNode::visit()
|
||||||
{
|
{
|
||||||
/** @todo
|
if (!m_bIsVisible)
|
||||||
if (!visible_)
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
if ( grid_ && grid_.active) {
|
if (m_pGrid && m_pGrid->isActive())
|
||||||
[grid_ beforeDraw];
|
{
|
||||||
[self transformAncestors];
|
m_pGrid->beforeDraw();
|
||||||
|
this->transformAncestors();
|
||||||
}
|
}
|
||||||
|
|
||||||
[self transform];
|
this->transform();
|
||||||
|
|
||||||
ccArray *arrayData;
|
if(m_pChildren && m_pChildren->count() > 0)
|
||||||
int i = 0, nu;
|
{
|
||||||
if(children_){
|
CCNode* pNode;
|
||||||
arrayData = children_->data;
|
NSMutableArrayIterator it;
|
||||||
nu = arrayData->num;
|
for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
|
||||||
for(;i<nu; i++){
|
{
|
||||||
CCNode *child = arrayData->arr[i];
|
pNode = static_cast<CCNode*>(*it);
|
||||||
if ( child.zOrder < 0 )
|
|
||||||
[child visit];
|
if ( pNode && pNode->m_nZOrder < 0 )
|
||||||
|
{
|
||||||
|
pNode->visit();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[self draw];
|
this->draw();
|
||||||
|
|
||||||
if(children_)
|
for ( ; it!=m_pChildren->end(); it++ )
|
||||||
for (;i<nu; i++)
|
{
|
||||||
[arrayData->arr[i] visit];
|
pNode = static_cast<CCNode*>(*it);
|
||||||
|
pNode->visit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_pGrid && m_pGrid->isActive())
|
||||||
|
{
|
||||||
|
m_pGrid->afterDraw(this);
|
||||||
|
}
|
||||||
|
|
||||||
if ( grid_ && grid_.active)
|
glPopMatrix();
|
||||||
[grid_ afterDraw:self];
|
|
||||||
|
|
||||||
glPopMatrix();*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCNode::transformAncestors()
|
void CCNode::transformAncestors()
|
||||||
|
@ -842,83 +852,77 @@ void CCNode::pauseSchedulerAndActions()
|
||||||
[[CCActionManager sharedManager] pauseTarget:self];*/
|
[[CCActionManager sharedManager] pauseTarget:self];*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @todo
|
|
||||||
CGAffineTransform CCNode::nodeToParentTransform(void)
|
CGAffineTransform CCNode::nodeToParentTransform(void)
|
||||||
{
|
{
|
||||||
if ( isTransformDirty_ ) {
|
if ( m_bIsTransformDirty ) {
|
||||||
|
|
||||||
transform_ = CGAffineTransformIdentity;
|
m_tTransform = CGAffineTransformIdentity;
|
||||||
|
|
||||||
if ( !isRelativeAnchorPoint_ && !CGPointEqualToPoint(anchorPointInPixels_, CGPointZero) )
|
if( ! m_bIsRelativeAnchorPoint && ! CGPoint::CGPointEqualToPoint(m_tAnchorPointInPixels, CGPointZero) )
|
||||||
transform_ = CGAffineTransformTranslate(transform_, anchorPointInPixels_.x, anchorPointInPixels_.y);
|
m_tTransform = CGAffineTransformTranslate(m_tTransform, m_tAnchorPointInPixels.x, m_tAnchorPointInPixels.y);
|
||||||
|
|
||||||
if( ! CGPointEqualToPoint(position_, CGPointZero) )
|
if( ! CGPoint::CGPointEqualToPoint(m_tPosition, CGPointZero) )
|
||||||
transform_ = CGAffineTransformTranslate(transform_, position_.x, position_.y);
|
m_tTransform = CGAffineTransformTranslate(m_tTransform, m_tPosition.x, m_tPosition.y);
|
||||||
if( rotation_ != 0 )
|
if( m_fRotation != 0 )
|
||||||
transform_ = CGAffineTransformRotate(transform_, -CC_DEGREES_TO_RADIANS(rotation_));
|
m_tTransform = CGAffineTransformRotate(m_tTransform, -CC_DEGREES_TO_RADIANS(m_fRotation));
|
||||||
if( ! (scaleX_ == 1 && scaleY_ == 1) )
|
if( ! (m_fScaleX == 1 && m_fScaleY == 1) )
|
||||||
transform_ = CGAffineTransformScale(transform_, scaleX_, scaleY_);
|
m_tTransform = CGAffineTransformScale(m_tTransform, m_fScaleX, m_fScaleY);
|
||||||
|
|
||||||
if( ! CGPointEqualToPoint(anchorPointInPixels_, CGPointZero) )
|
if( ! CGPoint::CGPointEqualToPoint(m_tAnchorPointInPixels, CGPointZero) )
|
||||||
transform_ = CGAffineTransformTranslate(transform_, -anchorPointInPixels_.x, -anchorPointInPixels_.y);
|
m_tTransform = CGAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y);
|
||||||
|
|
||||||
isTransformDirty_ = NO;
|
m_bIsTransformDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform_;
|
return m_tTransform;
|
||||||
}*/
|
|
||||||
/** @todo
|
|
||||||
- (CGAffineTransform)parentToNodeTransform
|
|
||||||
{
|
|
||||||
if ( isInverseDirty_ ) {
|
|
||||||
inverse_ = CGAffineTransformInvert([self nodeToParentTransform]);
|
|
||||||
isInverseDirty_ = NO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return inverse_;
|
CGAffineTransform CCNode::parentToNodeTransform(void)
|
||||||
}*/
|
|
||||||
/** @todo
|
|
||||||
- (CGAffineTransform)nodeToWorldTransform
|
|
||||||
{
|
{
|
||||||
CGAffineTransform t = [self nodeToParentTransform];
|
if ( m_bIsInverseDirty ) {
|
||||||
|
m_tInverse = CGAffineTransformInvert(this->nodeToParentTransform());
|
||||||
|
m_bIsInverseDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
for (CCNode *p = parent_; p != nil; p = p.parent)
|
return m_tInverse;
|
||||||
t = CGAffineTransformConcat(t, [p nodeToParentTransform]);
|
}
|
||||||
|
|
||||||
|
CGAffineTransform CCNode::nodeToWorldTransform()
|
||||||
|
{
|
||||||
|
CGAffineTransform t = this->nodeToParentTransform();
|
||||||
|
|
||||||
|
for (CCNode *p = m_pParent; p != NULL; p = p->getParent())
|
||||||
|
t = CGAffineTransformConcat(t, p->nodeToParentTransform());
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}*/
|
}
|
||||||
/** @todo
|
/** @todo*/
|
||||||
- (CGAffineTransform)worldToNodeTransform
|
CGAffineTransform CCNode::worldToNodeTransform(void)
|
||||||
{
|
{
|
||||||
return CGAffineTransformInvert([self nodeToWorldTransform]);
|
return CGAffineTransformInvert(this->nodeToWorldTransform());
|
||||||
}*/
|
}
|
||||||
|
|
||||||
CGPoint CCNode::convertToNodeSpace(CGPoint worldPoint)
|
CGPoint CCNode::convertToNodeSpace(CGPoint worldPoint)
|
||||||
{
|
{
|
||||||
/// @todo return CGPointApplyAffineTransform(worldPoint, [self worldToNodeTransform]);
|
return CGPointApplyAffineTransform(worldPoint, this->worldToNodeTransform());
|
||||||
return CGPoint(0,0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPoint CCNode::convertToWorldSpace(CGPoint nodePoint)
|
CGPoint CCNode::convertToWorldSpace(CGPoint nodePoint)
|
||||||
{
|
{
|
||||||
/// @todo return CGPointApplyAffineTransform(nodePoint, [self nodeToWorldTransform]);
|
return CGPointApplyAffineTransform(nodePoint, this->nodeToWorldTransform());
|
||||||
return CGPoint(0,0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPoint CCNode::convertToNodeSpaceAR(CGPoint worldPoint)
|
CGPoint CCNode::convertToNodeSpaceAR(CGPoint worldPoint)
|
||||||
{
|
{
|
||||||
/** @todo
|
CGPoint nodePoint = this->convertToNodeSpace(worldPoint);
|
||||||
CGPoint nodePoint = [self convertToNodeSpace:worldPoint];
|
return ccpSub(nodePoint, m_tAnchorPointInPixels);
|
||||||
return ccpSub(nodePoint, anchorPointInPixels_);*/
|
|
||||||
return CGPoint(0,0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPoint CCNode::convertToWorldSpaceAR(CGPoint nodePoint)
|
CGPoint CCNode::convertToWorldSpaceAR(CGPoint nodePoint)
|
||||||
{
|
{
|
||||||
/** @todo
|
/** @todo*/
|
||||||
nodePoint = ccpAdd(nodePoint, anchorPointInPixels_);
|
nodePoint = ccpAdd(nodePoint, m_tAnchorPointInPixels);
|
||||||
return [self convertToWorldSpace:nodePoint];*/
|
return this->convertToWorldSpace(nodePoint);
|
||||||
return CGPoint(0,0);
|
|
||||||
}
|
}
|
||||||
/** @todo no declare in .h file
|
/** @todo no declare in .h file
|
||||||
CGPoint CCNode::convertToWindowSpace(CGPoint nodePoint)
|
CGPoint CCNode::convertToWindowSpace(CGPoint nodePoint)
|
||||||
|
|
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
|
#include "CCTextureAtlas.h"
|
||||||
|
|
||||||
/** CCAtlasNode is a subclass of CCNode that implements the CCRGBAProtocol and
|
/** CCAtlasNode is a subclass of CCNode that implements the CCRGBAProtocol and
|
||||||
CCTextureProtocol protocol
|
CCTextureProtocol protocol
|
||||||
|
@ -57,66 +58,52 @@ protected:
|
||||||
int m_nItemHeight;
|
int m_nItemHeight;
|
||||||
|
|
||||||
ccColor3B m_tColorUnmodified;
|
ccColor3B m_tColorUnmodified;
|
||||||
|
|
||||||
|
// protocol variables
|
||||||
bool m_bOpacityModifyRGB;
|
bool m_bOpacityModifyRGB;
|
||||||
|
ccBlendFunc m_tBlendFunc;
|
||||||
/** conforms to CCTextureProtocol protocol */
|
GLubyte m_cOpacity;
|
||||||
CCX_PROPERTY(CCTextureAtlas *, m_tTextureAtlas, TextureAtlas)
|
ccColor3B m_tColor;
|
||||||
|
CCTextureAtlas * m_pTextureAtlas;
|
||||||
/** conforms to CCTextureProtocol protocol */
|
|
||||||
CCX_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc)
|
|
||||||
|
|
||||||
/** conforms to CCRGBAProtocol protocol */
|
|
||||||
CCX_PROPERTY(GLubyte, m_cOpacity, Opacity)
|
|
||||||
|
|
||||||
/** conforms to CCRGBAProtocol protocol */
|
|
||||||
CCX_PROPERTY(ccColor3B, m_tColor, Color)
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void calculateMaxItems(void);
|
|
||||||
void calculateTexCoordsSteps(void);
|
|
||||||
void updateBlendFunc(void);
|
|
||||||
void updateOpacityModifyRGB(void);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CCAtlasNode();
|
CCAtlasNode();
|
||||||
|
~CCAtlasNode();
|
||||||
virtual ~CCAtlasNode();
|
|
||||||
|
|
||||||
/** creates a CCAtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
/** creates a CCAtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
||||||
static CCAtlasNode* atlasWithTileFile(NSString* tile, int tileWidth, int tileHeight, int itemsToRender);
|
static CCAtlasNode * atlasWithTileFile(std::string & tile,int tileWidth, int tileHeight, int itemsToRender);
|
||||||
|
|
||||||
/** initializes an CCAtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
/** initializes an CCAtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
||||||
CCAtlasNode* initWithTileFile(NSString* tile, int tileWidth, int tileHeight, int itemsToRender;
|
CCAtlasNode * initWithTileFile(std::string & tile, int tileWidth, int tileHeight, int itemsToRender);
|
||||||
|
|
||||||
/** updates the Atlas (indexed vertex array).
|
/** updates the Atlas (indexed vertex array).
|
||||||
* Shall be overriden in subclasses
|
* Shall be overriden in subclasses
|
||||||
*/
|
*/
|
||||||
void updateAtlasValues(void);
|
void updateAtlasValues();
|
||||||
|
|
||||||
public: //CCNode methods
|
virtual void draw();
|
||||||
virtual void draw(void);
|
|
||||||
|
public:
|
||||||
|
// CC RGBA protocol
|
||||||
|
|
||||||
public: //CCRGBAProtocol methods
|
|
||||||
/** sets Color
|
/** sets Color
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
virtual void setColor(ccColor3B color) = 0;
|
virtual void setColor(ccColor3B color);
|
||||||
|
|
||||||
/** returns the color
|
/** returns the color
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
virtual ccColor3B color(void) = 0;
|
virtual ccColor3B color(void);
|
||||||
|
|
||||||
// returns the opacity
|
// returns the opacity
|
||||||
virtual GLubyte opacity(void) = 0;
|
virtual GLubyte opacity(void);
|
||||||
|
|
||||||
/** sets the opacity.
|
/** sets the opacity.
|
||||||
@warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed.
|
@warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed.
|
||||||
Values goes from 0 to 255, where 255 means fully opaque.
|
Values goes from 0 to 255, where 255 means fully opaque.
|
||||||
*/
|
*/
|
||||||
virtual void setOpacity(GLubyte opacity) = 0;
|
virtual void setOpacity(GLubyte opacity);
|
||||||
|
|
||||||
// optional
|
// optional
|
||||||
|
|
||||||
|
@ -126,19 +113,34 @@ public: //CCRGBAProtocol methods
|
||||||
Textures with premultiplied alpha will have this property by default on YES. Otherwise the default value is NO
|
Textures with premultiplied alpha will have this property by default on YES. Otherwise the default value is NO
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
virtual void setOpacityModifyRGB(bool bValue) {}
|
virtual void setOpacityModifyRGB(bool bValue);
|
||||||
|
|
||||||
/** returns whether or not the opacity will be applied using glColor(R,G,B,opacity) or glColor(opacity, opacity, opacity, opacity);
|
/** returns whether or not the opacity will be applied using glColor(R,G,B,opacity) or glColor(opacity, opacity, opacity, opacity);
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
virtual bool doesOpacityModifyRGB(void) = { return false;}
|
virtual bool doesOpacityModifyRGB(void);
|
||||||
|
|
||||||
|
// CC Blend protocol
|
||||||
|
|
||||||
|
// set the source blending function for the texture
|
||||||
|
virtual void setBlendFunc(ccBlendFunc blendFunc);
|
||||||
|
|
||||||
|
// returns the blending function used for the texture
|
||||||
|
virtual ccBlendFunc blendFunc(void);
|
||||||
|
|
||||||
|
// CC Texture protocol
|
||||||
|
|
||||||
public: // CCTextureProtocol methods
|
|
||||||
// returns the used texture
|
// returns the used texture
|
||||||
virtual CCTexture2D* texture(void) = 0;
|
virtual CCTexture2D* texture(void);
|
||||||
|
|
||||||
// sets a new texture. it will be retained
|
// sets a new texture. it will be retained
|
||||||
virtual void setTexture(CCTexture2D *texture) {}
|
virtual void setTexture(CCTexture2D *texture);
|
||||||
|
|
||||||
|
private :
|
||||||
|
void calculateMaxItems();
|
||||||
|
void calculateTexCoordsSteps();
|
||||||
|
void updateBlendFunc();
|
||||||
|
void updateOpacityModifyRGB();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ THE SOFTWARE.
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "../CCScheduler.h"
|
#include "../CCScheduler.h"
|
||||||
#include "../cocoa/CGGeometry.h"
|
#include "../cocoa/CGGeometry.h"
|
||||||
|
#include "../cocoa/CGAffineTransform.h"
|
||||||
#include "../cocoa/NSMutableArray.h"
|
#include "../cocoa/NSMutableArray.h"
|
||||||
#include "../cocoa/selector_protocol.h"
|
#include "../cocoa/selector_protocol.h"
|
||||||
#include "../effects/CCGrid.h"
|
#include "../effects/CCGrid.h"
|
||||||
|
@ -97,6 +98,7 @@ Camera:
|
||||||
|
|
||||||
class CCNode : public NSObject, public SelectorProtocol
|
class CCNode : public NSObject, public SelectorProtocol
|
||||||
{
|
{
|
||||||
|
|
||||||
// variable property
|
// variable property
|
||||||
|
|
||||||
/** The z order of the node relative to it's "brothers": children of the same parent */
|
/** The z order of the node relative to it's "brothers": children of the same parent */
|
||||||
|
@ -180,6 +182,9 @@ class CCNode : public NSObject, public SelectorProtocol
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
// transform
|
||||||
|
CGAffineTransform m_tTransform, m_tInverse;
|
||||||
|
|
||||||
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
||||||
GLfloat m_pTransformGL[16];
|
GLfloat m_pTransformGL[16];
|
||||||
#endif
|
#endif
|
||||||
|
@ -438,22 +443,22 @@ public:
|
||||||
/** Returns the local affine transform matrix
|
/** Returns the local affine transform matrix
|
||||||
@since v0.7.1
|
@since v0.7.1
|
||||||
*/
|
*/
|
||||||
/// @todo CGAffineTransform nodeToParentTransform(void);
|
CGAffineTransform nodeToParentTransform(void);
|
||||||
|
|
||||||
/** Returns the inverse local affine transform matrix
|
/** Returns the inverse local affine transform matrix
|
||||||
@since v0.7.1
|
@since v0.7.1
|
||||||
*/
|
*/
|
||||||
/// @todo CGAffineTransform parentToNodeTransform(void);
|
CGAffineTransform parentToNodeTransform(void);
|
||||||
|
|
||||||
/** Retrusn the world affine transform matrix
|
/** Retrusn the world affine transform matrix
|
||||||
@since v0.7.1
|
@since v0.7.1
|
||||||
*/
|
*/
|
||||||
/// @todo CGAffineTransform nodeToWorldTransform(void);
|
CGAffineTransform nodeToWorldTransform(void);
|
||||||
|
|
||||||
/** Returns the inverse world affine transform matrix
|
/** Returns the inverse world affine transform matrix
|
||||||
@since v0.7.1
|
@since v0.7.1
|
||||||
*/
|
*/
|
||||||
/// @todo CGAffineTransform worldToNodeTransform(void);
|
CGAffineTransform worldToNodeTransform(void);
|
||||||
|
|
||||||
/** converts a world coordinate to local coordinate
|
/** converts a world coordinate to local coordinate
|
||||||
@since v0.7.1
|
@since v0.7.1
|
||||||
|
|
|
@ -25,6 +25,8 @@ THE SOFTWARE.
|
||||||
#ifndef __CCPVRTEXTURE_H__
|
#ifndef __CCPVRTEXTURE_H__
|
||||||
#define __CCPVRTEXTURE_H__
|
#define __CCPVRTEXTURE_H__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
//#import <UIKit/UIKit.h>
|
//#import <UIKit/UIKit.h>
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
#include <GLES/glext.h>
|
#include <GLES/glext.h>
|
||||||
|
@ -45,9 +47,9 @@ public:
|
||||||
CCPVRTexture();
|
CCPVRTexture();
|
||||||
~CCPVRTexture();
|
~CCPVRTexture();
|
||||||
|
|
||||||
CCPVRTexture * initWithContentsOfFile(NSString * path);
|
CCPVRTexture * initWithContentsOfFile(std::string & path);
|
||||||
/// @todo CCPVRTexture * initWithContentsOfURL(NSURL *url);
|
/// @todo CCPVRTexture * initWithContentsOfURL(NSURL *url);
|
||||||
static CCPVRTexture * pvrTextureWithContentsOfFile(NSString *path);
|
static CCPVRTexture * pvrTextureWithContentsOfFile(std::string & path);
|
||||||
/// @todo static CCPVRTexture * pvrTextureWithContentsOfURL(NSURL *url);
|
/// @todo static CCPVRTexture * pvrTextureWithContentsOfURL(NSURL *url);
|
||||||
|
|
||||||
CCX_PROPERTY_READONLY(GLuint, m_uName, Name)
|
CCX_PROPERTY_READONLY(GLuint, m_uName, Name)
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
* if back is TRUE then the effect is reversed to appear as if the incoming
|
* if back is TRUE then the effect is reversed to appear as if the incoming
|
||||||
* scene is being turned from left over the outgoing scene
|
* scene is being turned from left over the outgoing scene
|
||||||
*/
|
*/
|
||||||
CCPageTurnTransition* initWithDurationAndScene(ccTime t,CCScene* scene,bool backwards);
|
virtual CCPageTurnTransition* initWithDurationAndScene(ccTime t,CCScene* scene,bool backwards);
|
||||||
|
|
||||||
CCIntervalAction* actionWithSize(ccGridSize vector);
|
CCIntervalAction* actionWithSize(ccGridSize vector);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ THE SOFTWARE.
|
||||||
#define __CCPROTOCOLS_H__
|
#define __CCPROTOCOLS_H__
|
||||||
|
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "textures/CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,12 @@ THE SOFTWARE.
|
||||||
#define __CCTEXTURE2D_H__
|
#define __CCTEXTURE2D_H__
|
||||||
|
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "Cocos2dDefine.h"
|
#include "Cocos2dDefine.h"
|
||||||
#include "../cocoa/NSObject.h"
|
#include "../cocoa/NSObject.h"
|
||||||
#include "../cocoa/CGGeometry.h"
|
#include "../cocoa/CGGeometry.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
//CONSTANTS:
|
//CONSTANTS:
|
||||||
|
|
||||||
|
@ -135,9 +134,9 @@ public:
|
||||||
Note that the generated textures are of type A8 - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
|
Note that the generated textures are of type A8 - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
|
||||||
*/
|
*/
|
||||||
/** Initializes a texture from a string with dimensions, alignment, font name and font size */
|
/** Initializes a texture from a string with dimensions, alignment, font name and font size */
|
||||||
/// @todo CCTexture2D * initWithString(NSString* str, CGSize dimensions, UITextAlignment alignment, NSString* fontName, CGFloat fontSize);
|
/// @todo CCTexture2D * initWithString(string & str, CGSize dimensions, UITextAlignment alignment, string & fontName, CGFloat fontSize);
|
||||||
/** Initializes a texture from a string with font name and font size */
|
/** Initializes a texture from a string with font name and font size */
|
||||||
CCTexture2D * initWithString(NSString* str, NSString* fontName, GLfloat fontSize);
|
CCTexture2D * initWithString(std::string & str, std::string & fontName, GLfloat fontSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Extensions to make it easy to create a CCTexture2D object from a PVRTC file
|
Extensions to make it easy to create a CCTexture2D object from a PVRTC file
|
||||||
|
@ -146,7 +145,7 @@ public:
|
||||||
/** Initializes a texture from a PVRTC buffer */
|
/** Initializes a texture from a PVRTC buffer */
|
||||||
CCTexture2D * initWithPVRTCData(const void* data, int level, int bpp, bool hasAlpha, int length);
|
CCTexture2D * initWithPVRTCData(const void* data, int level, int bpp, bool hasAlpha, int length);
|
||||||
/** Initializes a texture from a PVRTC file */
|
/** Initializes a texture from a PVRTC file */
|
||||||
CCTexture2D * initWithPVRTCFile(NSString* file);
|
CCTexture2D * initWithPVRTCFile(std::string & file);
|
||||||
|
|
||||||
/** sets the min filter, mag filter, wrap s and wrap t texture parameters.
|
/** sets the min filter, mag filter, wrap s and wrap t texture parameters.
|
||||||
If the texture size is NPOT (non power of 2), then in can only use GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}.
|
If the texture size is NPOT (non power of 2), then in can only use GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}.
|
||||||
|
|
|
@ -69,14 +69,14 @@ public:
|
||||||
/** creates a TextureAtlas with an filename and with an initial capacity for Quads.
|
/** creates a TextureAtlas with an filename and with an initial capacity for Quads.
|
||||||
* The TextureAtlas capacity can be increased in runtime.
|
* The TextureAtlas capacity can be increased in runtime.
|
||||||
*/
|
*/
|
||||||
static CCTextureAtlas * textureAtlasWithFile(NSString* file , UINT32 capacity);
|
static CCTextureAtlas * textureAtlasWithFile(std::string & file , UINT32 capacity);
|
||||||
|
|
||||||
/** initializes a TextureAtlas with a filename and with a certain capacity for Quads.
|
/** initializes a TextureAtlas with a filename and with a certain capacity for Quads.
|
||||||
* The TextureAtlas capacity can be increased in runtime.
|
* The TextureAtlas capacity can be increased in runtime.
|
||||||
*
|
*
|
||||||
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
||||||
*/
|
*/
|
||||||
CCTextureAtlas * initWithFile(NSString* file, UINT32 capacity);
|
CCTextureAtlas * initWithFile(std::string & file, UINT32 capacity);
|
||||||
|
|
||||||
/** creates a TextureAtlas with a previously initialized Texture2D object, and
|
/** creates a TextureAtlas with a previously initialized Texture2D object, and
|
||||||
* with an initial capacity for n Quads.
|
* with an initial capacity for n Quads.
|
||||||
|
|
|
@ -25,11 +25,11 @@ THE SOFTWARE.
|
||||||
#ifndef __CCTEXTURE_CACHE_H__
|
#ifndef __CCTEXTURE_CACHE_H__
|
||||||
#define __CCTEXTURE_CACHE_H__
|
#define __CCTEXTURE_CACHE_H__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include "../cocoa/NSObject.h"
|
#include "../cocoa/NSObject.h"
|
||||||
#include "../cocoa/NSString.h"
|
|
||||||
/// @todo #import <Foundation/Foundation.h>
|
/// @todo #import <Foundation/Foundation.h>
|
||||||
/// @todo #import <CoreGraphics/CGImage.h>
|
/// @todo #import <CoreGraphics/CGImage.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
class CCTexture2D;
|
class CCTexture2D;
|
||||||
class CCAsyncObject;
|
class CCAsyncObject;
|
||||||
|
@ -69,7 +69,7 @@ public:
|
||||||
* Otherwise it will return a reference of a previosly loaded image.
|
* Otherwise it will return a reference of a previosly loaded image.
|
||||||
* Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif
|
* Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif
|
||||||
*/
|
*/
|
||||||
CCTexture2D* addImage(NSString* fileimage);
|
CCTexture2D* addImage(std::string &fileimage);
|
||||||
|
|
||||||
/** Returns a Texture2D object given a file image
|
/** Returns a Texture2D object given a file image
|
||||||
* If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it.
|
* If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it.
|
||||||
|
@ -78,7 +78,7 @@ public:
|
||||||
* Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif
|
* Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif
|
||||||
* @since v0.8
|
* @since v0.8
|
||||||
*/
|
*/
|
||||||
/// @todo -(void) addImageAsync:(NSString*) filename target:(id)target selector:(SEL)selector;
|
/// @todo -(void) addImageAsync:(string & ) filename target:(id)target selector:(SEL)selector;
|
||||||
|
|
||||||
void addImageWithAsyncObject(CCAsyncObject* async);
|
void addImageWithAsyncObject(CCAsyncObject* async);
|
||||||
|
|
||||||
|
@ -90,13 +90,13 @@ public:
|
||||||
* bpp can only be 2 or 4. 2 means more compression but lower quality.
|
* bpp can only be 2 or 4. 2 means more compression but lower quality.
|
||||||
* hasAlpha: whether or not the image contains alpha channel
|
* hasAlpha: whether or not the image contains alpha channel
|
||||||
*/
|
*/
|
||||||
CCTexture2D* addPVRTCImage(NSString* fileimage, int bpp, bool hasAlpha, int width);
|
CCTexture2D* addPVRTCImage(std::string &fileimage, int bpp, bool hasAlpha, int width);
|
||||||
|
|
||||||
/** Returns a Texture2D object given an PVRTC filename
|
/** Returns a Texture2D object given an PVRTC filename
|
||||||
* If the file image was not previously loaded, it will create a new CCTexture2D
|
* If the file image was not previously loaded, it will create a new CCTexture2D
|
||||||
* object and it will return it. Otherwise it will return a reference of a previosly loaded image
|
* object and it will return it. Otherwise it will return a reference of a previosly loaded image
|
||||||
*/
|
*/
|
||||||
CCTexture2D* addPVRTCImage(NSString* fileimage);
|
CCTexture2D* addPVRTCImage(std::string &fileimage);
|
||||||
|
|
||||||
/** Returns a Texture2D object given an CGImageRef image
|
/** Returns a Texture2D object given an CGImageRef image
|
||||||
* If the image was not previously loaded, it will create a new CCTexture2D object and it will return it.
|
* If the image was not previously loaded, it will create a new CCTexture2D object and it will return it.
|
||||||
|
@ -105,7 +105,7 @@ public:
|
||||||
* If "key" is nil, then a new texture will be created each time.
|
* If "key" is nil, then a new texture will be created each time.
|
||||||
* @since v0.8
|
* @since v0.8
|
||||||
*/
|
*/
|
||||||
/// @todo CGImageRef CCTexture2D* addCGImage(CGImageRef image, NSString * key);
|
/// @todo CGImageRef CCTexture2D* addCGImage(CGImageRef image, string & key);
|
||||||
|
|
||||||
/** Purges the dictionary of loaded textures.
|
/** Purges the dictionary of loaded textures.
|
||||||
* Call this method if you receive the "Memory Warning"
|
* Call this method if you receive the "Memory Warning"
|
||||||
|
@ -129,7 +129,7 @@ public:
|
||||||
/** Deletes a texture from the cache given a its key name
|
/** Deletes a texture from the cache given a its key name
|
||||||
@since v0.99.4
|
@since v0.99.4
|
||||||
*/
|
*/
|
||||||
void removeTextureForKey(NSString* textureKeyName);
|
void removeTextureForKey(std::string & textureKeyName);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ public:
|
||||||
static CCTransitionScene * transitionWithDurationAndScene(ccTime t, CCScene *scene);
|
static CCTransitionScene * transitionWithDurationAndScene(ccTime t, CCScene *scene);
|
||||||
|
|
||||||
/** initializes a transition with duration and incoming scene */
|
/** initializes a transition with duration and incoming scene */
|
||||||
CCTransitionScene * initWithDurationAndScene(ccTime t,CCScene* scene);
|
virtual CCTransitionScene * initWithDurationAndScene(ccTime t,CCScene* scene);
|
||||||
|
|
||||||
/** called after the transition finishes */
|
/** called after the transition finishes */
|
||||||
void finish(void);
|
void finish(void);
|
||||||
|
@ -111,7 +111,7 @@ public:
|
||||||
/** creates a base transition with duration and incoming scene */
|
/** creates a base transition with duration and incoming scene */
|
||||||
static CCOrientedTransitionScene * transitionWithDurationAndScene(ccTime t,CCScene* scene, tOrientation orientation);
|
static CCOrientedTransitionScene * transitionWithDurationAndScene(ccTime t,CCScene* scene, tOrientation orientation);
|
||||||
/** initializes a transition with duration and incoming scene */
|
/** initializes a transition with duration and incoming scene */
|
||||||
CCOrientedTransitionScene * initWithDurationAndScene(ccTime t,CCScene* scene,tOrientation orientation);
|
virtual CCOrientedTransitionScene * initWithDurationAndScene(ccTime t,CCScene* scene,tOrientation orientation);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** CCRotoZoomTransition:
|
/** CCRotoZoomTransition:
|
||||||
|
@ -368,9 +368,9 @@ public:
|
||||||
*/
|
*/
|
||||||
static CCFadeTransition* transitionWithDurationAndColor(ccTime duration,CCScene* scene, ccColor3B color);
|
static CCFadeTransition* transitionWithDurationAndColor(ccTime duration,CCScene* scene, ccColor3B color);
|
||||||
/** initializes the transition with a duration and with an RGB color */
|
/** initializes the transition with a duration and with an RGB color */
|
||||||
CCFadeTransition* initWithDurationAndColor(ccTime t, CCScene*scene ,ccColor3B color);
|
virtual CCFadeTransition* initWithDurationAndColor(ccTime t, CCScene*scene ,ccColor3B color);
|
||||||
|
|
||||||
CCFadeTransition * initWithDurationAndScene(ccTime t,CCScene* scene);
|
virtual CCFadeTransition * initWithDurationAndScene(ccTime t,CCScene* scene);
|
||||||
virtual void onEnter();
|
virtual void onEnter();
|
||||||
virtual void onExit();
|
virtual void onExit();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue