mirror of https://github.com/axmolengine/axmol.git
merge commit 928a28e37d3469fcd41aff14cb136b1415f2fc86
This commit is contained in:
parent
40ec8a3b3d
commit
355e27dada
|
@ -66,7 +66,7 @@ using namespace cocos2d;
|
|||
unsigned int g_uNumberOfDraws = 0;
|
||||
|
||||
NS_CC_BEGIN
|
||||
// XXX it shoul be a Director ivar. Move it there once support for multiple directors is added
|
||||
// XXX it shoul be a Director ivar. Move it there once support for multiple directors is added
|
||||
|
||||
// singleton stuff
|
||||
static CCDisplayLinkDirector s_sharedDirector;
|
||||
|
|
|
@ -504,9 +504,10 @@ void CCRepeatForever::step(ccTime dt)
|
|||
m_pInnerAction->step(dt);
|
||||
if (m_pInnerAction->isDone())
|
||||
{
|
||||
ccTime diff = dt + m_pInnerAction->getDuration() - m_pInnerAction->getElapsed();
|
||||
ccTime diff = m_pInnerAction->getElapsed() - m_pInnerAction->getDuration();
|
||||
m_pInnerAction->startWithTarget(m_pTarget);
|
||||
// to prevent jerk. issue #390
|
||||
// to prevent jerk. issue #390, 1247
|
||||
m_pInnerAction->step(0.0f);
|
||||
m_pInnerAction->step(diff);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,11 +126,10 @@ public:
|
|||
Note that RGBA type textures will have their alpha premultiplied - use the blending mode (GL_ONE, GL_ONE_MINUS_SRC_ALPHA).
|
||||
*/
|
||||
/** Initializes a texture from a UIImage object */
|
||||
#if 0// TODO: (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
bool initWithImage(CCImage * uiImage, ccResolutionType resolution);
|
||||
#else
|
||||
bool initWithImage(CCImage * uiImage);
|
||||
#endif
|
||||
|
||||
bool initWithImage(CCImage * uiImage);
|
||||
|
||||
bool initWithImage(CCImage *uiImage, ccResolutionType resolution);
|
||||
|
||||
/**
|
||||
Extensions to make it easy to create a CCTexture2D object from a string of text.
|
||||
|
@ -247,19 +246,19 @@ private:
|
|||
/** whether or not the texture has their Alpha premultiplied */
|
||||
CC_PROPERTY_READONLY(bool, m_bHasPremultipliedAlpha, HasPremultipliedAlpha);
|
||||
|
||||
/** shader program used by drawAtPoint and drawInRect */
|
||||
CC_PROPERTY(CCGLProgram*, m_pShaderProgram, ShaderProgram);
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
/** Returns the resolution type of the texture.
|
||||
Is it a RetinaDisplay texture, an iPad texture or an standard texture ?
|
||||
Only valid on iOS. Not valid on OS X.
|
||||
|
||||
Should be a readonly property. It is readwrite as a hack.
|
||||
|
||||
@since v1.1
|
||||
*/
|
||||
CC_SYNTHESIZE(ccResolutionType, m_resolutionType, ResolutionType);
|
||||
/** shader program used by drawAtPoint and drawInRect */
|
||||
CC_PROPERTY(CCGLProgram*, m_pShaderProgram, ShaderProgram);
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
/** Returns the resolution type of the texture.
|
||||
Is it a RetinaDisplay texture, an iPad texture or an standard texture ?
|
||||
Only valid on iOS. Not valid on OS X.
|
||||
|
||||
Should be a readonly property. It is readwrite as a hack.
|
||||
|
||||
@since v1.1
|
||||
*/
|
||||
CC_SYNTHESIZE(ccResolutionType, m_eResolutionType, ResolutionType);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
|
|
@ -211,36 +211,6 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios.
|
|||
#define CC_TEXTURE_NPOT_SUPPORT 0
|
||||
#endif
|
||||
|
||||
/** @def CC_RETINA_DISPLAY_SUPPORT
|
||||
If enabled, cocos2d supports retina display.
|
||||
For performance reasons, it's recommended disable it in games without retina display support, like iPad only games.
|
||||
|
||||
To enable set it to 1. Use 0 to disable it. Enabled by default.
|
||||
|
||||
This value governs only the PNG, GIF, BMP, images.
|
||||
This value DOES NOT govern the PVR (PVR.GZ, PVR.CCZ) files. If NPOT PVR is loaded, then it will create an NPOT texture ignoring this value.
|
||||
|
||||
@deprecated This value will be removed in 1.1 and NPOT textures will be loaded by default if the device supports it.
|
||||
|
||||
@since v0.99.5
|
||||
*/
|
||||
#ifndef CC_RETINA_DISPLAY_SUPPORT
|
||||
#define CC_RETINA_DISPLAY_SUPPORT 1
|
||||
#endif
|
||||
|
||||
/** @def CC_RETINA_DISPLAY_FILENAME_SUFFIX
|
||||
It's the suffix that will be appended to the files in order to load "retina display" images.
|
||||
|
||||
On an iPhone4 with Retina Display support enabled, the file @"sprite-hd.png" will be loaded instead of @"sprite.png".
|
||||
If the file doesn't exist it will use the non-retina display image.
|
||||
|
||||
Platforms: Only used on Retina Display devices like iPhone 4.
|
||||
|
||||
@since v0.99.5
|
||||
*/
|
||||
#ifndef CC_RETINA_DISPLAY_FILENAME_SUFFIX
|
||||
#define CC_RETINA_DISPLAY_FILENAME_SUFFIX "-hd"
|
||||
#endif
|
||||
|
||||
/** @def CC_USE_LA88_LABELS
|
||||
If enabled, it will use LA88 (Luminance Alpha 16-bit textures) for CCLabelTTF objects.
|
||||
|
@ -312,12 +282,6 @@ To enable set it to a value different than 0. Disabled by default.
|
|||
#define CC_ENABLE_PROFILERS 0
|
||||
#endif
|
||||
|
||||
#if CC_RETINA_DISPLAY_SUPPORT
|
||||
#define CC_IS_RETINA_DISPLAY_SUPPORTED 1
|
||||
#else
|
||||
#define CC_IS_RETINA_DISPLAY_SUPPORTED 0
|
||||
#endif
|
||||
|
||||
/** Enable Lua engine debug log */
|
||||
#ifndef CC_LUA_ENGINE_DEBUG
|
||||
#define CC_LUA_ENGINE_DEBUG 0
|
||||
|
|
|
@ -1,337 +1,361 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCTYPES_H__
|
||||
#define __CCTYPES_H__
|
||||
|
||||
#include "CCGeometry.h"
|
||||
|
||||
#include "CCGL.h"
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
/** RGB color composed of bytes 3 bytes
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccColor3B
|
||||
{
|
||||
GLubyte r;
|
||||
GLubyte g;
|
||||
GLubyte b;
|
||||
} ccColor3B;
|
||||
|
||||
//! helper macro that creates an ccColor3B type
|
||||
static inline ccColor3B
|
||||
ccc3(const GLubyte r, const GLubyte g, const GLubyte b)
|
||||
{
|
||||
ccColor3B c = {r, g, b};
|
||||
return c;
|
||||
}
|
||||
//ccColor3B predefined colors
|
||||
//! White color (255,255,255)
|
||||
static const ccColor3B ccWHITE={255,255,255};
|
||||
//! Yellow color (255,255,0)
|
||||
static const ccColor3B ccYELLOW={255,255,0};
|
||||
//! Blue color (0,0,255)
|
||||
static const ccColor3B ccBLUE={0,0,255};
|
||||
//! Green Color (0,255,0)
|
||||
static const ccColor3B ccGREEN={0,255,0};
|
||||
//! Red Color (255,0,0,)
|
||||
static const ccColor3B ccRED={255,0,0};
|
||||
//! Magenta Color (255,0,255)
|
||||
static const ccColor3B ccMAGENTA={255,0,255};
|
||||
//! Black Color (0,0,0)
|
||||
static const ccColor3B ccBLACK={0,0,0};
|
||||
//! Orange Color (255,127,0)
|
||||
static const ccColor3B ccORANGE={255,127,0};
|
||||
//! Gray Color (166,166,166)
|
||||
static const ccColor3B ccGRAY={166,166,166};
|
||||
|
||||
/** RGBA color composed of 4 bytes
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccColor4B
|
||||
{
|
||||
GLubyte r;
|
||||
GLubyte g;
|
||||
GLubyte b;
|
||||
GLubyte a;
|
||||
} ccColor4B;
|
||||
//! helper macro that creates an ccColor4B type
|
||||
static inline ccColor4B
|
||||
ccc4(const GLubyte r, const GLubyte g, const GLubyte b, const GLubyte o)
|
||||
{
|
||||
ccColor4B c = {r, g, b, o};
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/** RGBA color composed of 4 floats
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccColor4F {
|
||||
GLfloat r;
|
||||
GLfloat g;
|
||||
GLfloat b;
|
||||
GLfloat a;
|
||||
} ccColor4F;
|
||||
|
||||
static inline ccColor4F
|
||||
ccc4f(const GLfloat r, const GLfloat g, const GLfloat b, const GLfloat a)
|
||||
{
|
||||
ccColor4F c = {r, g, b, a};
|
||||
return c;
|
||||
}
|
||||
|
||||
/** Returns a ccColor4F from a ccColor3B. Alpha will be 1.
|
||||
@since v0.99.1
|
||||
*/
|
||||
static inline ccColor4F ccc4FFromccc3B(ccColor3B c)
|
||||
{
|
||||
ccColor4F c4 = {c.r/255.f, c.g/255.f, c.b/255.f, 1.f};
|
||||
return c4;
|
||||
}
|
||||
|
||||
/** Returns a ccColor4F from a ccColor4B.
|
||||
@since v0.99.1
|
||||
*/
|
||||
static inline ccColor4F ccc4FFromccc4B(ccColor4B c)
|
||||
{
|
||||
ccColor4F c4 = {c.r/255.f, c.g/255.f, c.b/255.f, c.a/255.f};
|
||||
return c4;
|
||||
}
|
||||
|
||||
/** returns YES if both ccColor4F are equal. Otherwise it returns NO.
|
||||
@since v0.99.1
|
||||
*/
|
||||
static inline bool ccc4FEqual(ccColor4F a, ccColor4F b)
|
||||
{
|
||||
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
|
||||
}
|
||||
|
||||
/** A vertex composed of 2 floats: x, y
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccVertex2F
|
||||
{
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
} ccVertex2F;
|
||||
|
||||
static inline ccVertex2F vertex2(const float x, const float y)
|
||||
{
|
||||
ccVertex2F c = {x, y};
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/** A vertex composed of 2 floats: x, y
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccVertex3F
|
||||
{
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
GLfloat z;
|
||||
} ccVertex3F;
|
||||
|
||||
static inline ccVertex3F vertex3(const float x, const float y, const float z)
|
||||
{
|
||||
ccVertex3F c = {x, y, z};
|
||||
return c;
|
||||
}
|
||||
|
||||
/** A texcoord composed of 2 floats: u, y
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccTex2F {
|
||||
GLfloat u;
|
||||
GLfloat v;
|
||||
} ccTex2F;
|
||||
|
||||
static inline ccTex2F tex2(const float u, const float v)
|
||||
{
|
||||
ccTex2F t = {u , v};
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
//! Point Sprite component
|
||||
typedef struct _ccPointSprite
|
||||
{
|
||||
ccVertex2F pos; // 8 bytes
|
||||
ccColor4B color; // 4 bytes
|
||||
GLfloat size; // 4 bytes
|
||||
} ccPointSprite;
|
||||
|
||||
//! A 2D Quad. 4 * 2 floats
|
||||
typedef struct _ccQuad2 {
|
||||
ccVertex2F tl;
|
||||
ccVertex2F tr;
|
||||
ccVertex2F bl;
|
||||
ccVertex2F br;
|
||||
} ccQuad2;
|
||||
|
||||
|
||||
//! A 3D Quad. 4 * 3 floats
|
||||
typedef struct _ccQuad3 {
|
||||
ccVertex3F bl;
|
||||
ccVertex3F br;
|
||||
ccVertex3F tl;
|
||||
ccVertex3F tr;
|
||||
} ccQuad3;
|
||||
|
||||
//! A 2D grid size
|
||||
typedef struct _ccGridSize
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} ccGridSize;
|
||||
|
||||
//! helper function to create a ccGridSize
|
||||
static inline ccGridSize
|
||||
ccg(const int x, const int y)
|
||||
{
|
||||
ccGridSize v = {x, y};
|
||||
return v;
|
||||
}
|
||||
|
||||
//! a Point with a vertex point, a tex coord point and a color 4B
|
||||
typedef struct _ccV2F_C4B_T2F
|
||||
{
|
||||
//! vertices (2F)
|
||||
ccVertex2F vertices;
|
||||
//! colors (4B)
|
||||
ccColor4B colors;
|
||||
//! tex coords (2F)
|
||||
ccTex2F texCoords;
|
||||
} ccV2F_C4B_T2F;
|
||||
|
||||
//! a Point with a vertex point, a tex coord point and a color 4F
|
||||
typedef struct _ccV2F_C4F_T2F
|
||||
{
|
||||
//! vertices (2F)
|
||||
ccVertex2F vertices;
|
||||
//! colors (4F)
|
||||
ccColor4F colors;
|
||||
//! tex coords (2F)
|
||||
ccTex2F texCoords;
|
||||
} ccV2F_C4F_T2F;
|
||||
|
||||
//! a Point with a vertex point, a tex coord point and a color 4B
|
||||
typedef struct _ccV3F_C4B_T2F
|
||||
{
|
||||
//! vertices (3F)
|
||||
ccVertex3F vertices; // 12 bytes
|
||||
// char __padding__[4];
|
||||
|
||||
//! colors (4B)
|
||||
ccColor4B colors; // 4 bytes
|
||||
// char __padding2__[4];
|
||||
|
||||
// tex coords (2F)
|
||||
ccTex2F texCoords; // 8 byts
|
||||
} ccV3F_C4B_T2F;
|
||||
|
||||
//! 4 ccVertex2FTex2FColor4B Quad
|
||||
typedef struct _ccV2F_C4B_T2F_Quad
|
||||
{
|
||||
//! bottom left
|
||||
ccV2F_C4B_T2F bl;
|
||||
//! bottom right
|
||||
ccV2F_C4B_T2F br;
|
||||
//! top left
|
||||
ccV2F_C4B_T2F tl;
|
||||
//! top right
|
||||
ccV2F_C4B_T2F tr;
|
||||
} ccV2F_C4B_T2F_Quad;
|
||||
|
||||
//! 4 ccVertex3FTex2FColor4B
|
||||
typedef struct _ccV3F_C4B_T2F_Quad
|
||||
{
|
||||
//! top left
|
||||
ccV3F_C4B_T2F tl;
|
||||
//! bottom left
|
||||
ccV3F_C4B_T2F bl;
|
||||
//! top right
|
||||
ccV3F_C4B_T2F tr;
|
||||
//! bottom right
|
||||
ccV3F_C4B_T2F br;
|
||||
} ccV3F_C4B_T2F_Quad;
|
||||
|
||||
//! 4 ccVertex2FTex2FColor4F Quad
|
||||
typedef struct _ccV2F_C4F_T2F_Quad
|
||||
{
|
||||
//! bottom left
|
||||
ccV2F_C4F_T2F bl;
|
||||
//! bottom right
|
||||
ccV2F_C4F_T2F br;
|
||||
//! top left
|
||||
ccV2F_C4F_T2F tl;
|
||||
//! top right
|
||||
ccV2F_C4F_T2F tr;
|
||||
} ccV2F_C4F_T2F_Quad;
|
||||
|
||||
//! Blend Function used for textures
|
||||
typedef struct _ccBlendFunc
|
||||
{
|
||||
//! source blend function
|
||||
GLenum src;
|
||||
//! destination blend function
|
||||
GLenum dst;
|
||||
} ccBlendFunc;
|
||||
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCTYPES_H__
|
||||
#define __CCTYPES_H__
|
||||
|
||||
#include "CCGeometry.h"
|
||||
|
||||
#include "CCGL.h"
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
/** RGB color composed of bytes 3 bytes
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccColor3B
|
||||
{
|
||||
GLubyte r;
|
||||
GLubyte g;
|
||||
GLubyte b;
|
||||
} ccColor3B;
|
||||
|
||||
//! helper macro that creates an ccColor3B type
|
||||
static inline ccColor3B
|
||||
ccc3(const GLubyte r, const GLubyte g, const GLubyte b)
|
||||
{
|
||||
ccColor3B c = {r, g, b};
|
||||
return c;
|
||||
}
|
||||
//ccColor3B predefined colors
|
||||
//! White color (255,255,255)
|
||||
static const ccColor3B ccWHITE={255,255,255};
|
||||
//! Yellow color (255,255,0)
|
||||
static const ccColor3B ccYELLOW={255,255,0};
|
||||
//! Blue color (0,0,255)
|
||||
static const ccColor3B ccBLUE={0,0,255};
|
||||
//! Green Color (0,255,0)
|
||||
static const ccColor3B ccGREEN={0,255,0};
|
||||
//! Red Color (255,0,0,)
|
||||
static const ccColor3B ccRED={255,0,0};
|
||||
//! Magenta Color (255,0,255)
|
||||
static const ccColor3B ccMAGENTA={255,0,255};
|
||||
//! Black Color (0,0,0)
|
||||
static const ccColor3B ccBLACK={0,0,0};
|
||||
//! Orange Color (255,127,0)
|
||||
static const ccColor3B ccORANGE={255,127,0};
|
||||
//! Gray Color (166,166,166)
|
||||
static const ccColor3B ccGRAY={166,166,166};
|
||||
|
||||
/** RGBA color composed of 4 bytes
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccColor4B
|
||||
{
|
||||
GLubyte r;
|
||||
GLubyte g;
|
||||
GLubyte b;
|
||||
GLubyte a;
|
||||
} ccColor4B;
|
||||
//! helper macro that creates an ccColor4B type
|
||||
static inline ccColor4B
|
||||
ccc4(const GLubyte r, const GLubyte g, const GLubyte b, const GLubyte o)
|
||||
{
|
||||
ccColor4B c = {r, g, b, o};
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/** RGBA color composed of 4 floats
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccColor4F {
|
||||
GLfloat r;
|
||||
GLfloat g;
|
||||
GLfloat b;
|
||||
GLfloat a;
|
||||
} ccColor4F;
|
||||
|
||||
|
||||
/** Returns a ccColor4F from a ccColor3B. Alpha will be 1.
|
||||
@since v0.99.1
|
||||
*/
|
||||
static inline ccColor4F ccc4FFromccc3B(ccColor3B c)
|
||||
{
|
||||
ccColor4F c4 = {c.r/255.f, c.g/255.f, c.b/255.f, 1.f};
|
||||
return c4;
|
||||
}
|
||||
|
||||
//! helper that creates a ccColor4f type
|
||||
static inline ccColor4F
|
||||
ccc4f(const GLfloat r, const GLfloat g, const GLfloat b, const GLfloat a)
|
||||
{
|
||||
return (ccColor4F){r, g, b, a};
|
||||
}
|
||||
|
||||
/** Returns a ccColor4F from a ccColor4B.
|
||||
@since v0.99.1
|
||||
*/
|
||||
static inline ccColor4F ccc4FFromccc4B(ccColor4B c)
|
||||
{
|
||||
ccColor4F c4 = {c.r/255.f, c.g/255.f, c.b/255.f, c.a/255.f};
|
||||
return c4;
|
||||
}
|
||||
|
||||
/** returns YES if both ccColor4F are equal. Otherwise it returns NO.
|
||||
@since v0.99.1
|
||||
*/
|
||||
static inline bool ccc4FEqual(ccColor4F a, ccColor4F b)
|
||||
{
|
||||
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
|
||||
}
|
||||
|
||||
/** A vertex composed of 2 floats: x, y
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccVertex2F
|
||||
{
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
} ccVertex2F;
|
||||
|
||||
static inline ccVertex2F vertex2(const float x, const float y)
|
||||
{
|
||||
ccVertex2F c = {x, y};
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/** A vertex composed of 2 floats: x, y
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccVertex3F
|
||||
{
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
GLfloat z;
|
||||
} ccVertex3F;
|
||||
|
||||
static inline ccVertex3F vertex3(const float x, const float y, const float z)
|
||||
{
|
||||
ccVertex3F c = {x, y, z};
|
||||
return c;
|
||||
}
|
||||
|
||||
/** A texcoord composed of 2 floats: u, y
|
||||
@since v0.8
|
||||
*/
|
||||
typedef struct _ccTex2F {
|
||||
GLfloat u;
|
||||
GLfloat v;
|
||||
} ccTex2F;
|
||||
|
||||
static inline ccTex2F tex2(const float u, const float v)
|
||||
{
|
||||
ccTex2F t = {u , v};
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
//! Point Sprite component
|
||||
typedef struct _ccPointSprite
|
||||
{
|
||||
ccVertex2F pos; // 8 bytes
|
||||
ccColor4B color; // 4 bytes
|
||||
GLfloat size; // 4 bytes
|
||||
} ccPointSprite;
|
||||
|
||||
//! A 2D Quad. 4 * 2 floats
|
||||
typedef struct _ccQuad2 {
|
||||
ccVertex2F tl;
|
||||
ccVertex2F tr;
|
||||
ccVertex2F bl;
|
||||
ccVertex2F br;
|
||||
} ccQuad2;
|
||||
|
||||
|
||||
//! A 3D Quad. 4 * 3 floats
|
||||
typedef struct _ccQuad3 {
|
||||
ccVertex3F bl;
|
||||
ccVertex3F br;
|
||||
ccVertex3F tl;
|
||||
ccVertex3F tr;
|
||||
} ccQuad3;
|
||||
|
||||
//! A 2D grid size
|
||||
typedef struct _ccGridSize
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} ccGridSize;
|
||||
|
||||
//! helper function to create a ccGridSize
|
||||
static inline ccGridSize
|
||||
ccg(const int x, const int y)
|
||||
{
|
||||
ccGridSize v = {x, y};
|
||||
return v;
|
||||
}
|
||||
|
||||
//! a Point with a vertex point, a tex coord point and a color 4B
|
||||
typedef struct _ccV2F_C4B_T2F
|
||||
{
|
||||
//! vertices (2F)
|
||||
ccVertex2F vertices;
|
||||
//! colors (4B)
|
||||
ccColor4B colors;
|
||||
//! tex coords (2F)
|
||||
ccTex2F texCoords;
|
||||
} ccV2F_C4B_T2F;
|
||||
|
||||
//! a Point with a vertex point, a tex coord point and a color 4F
|
||||
typedef struct _ccV2F_C4F_T2F
|
||||
{
|
||||
//! vertices (2F)
|
||||
ccVertex2F vertices;
|
||||
//! colors (4F)
|
||||
ccColor4F colors;
|
||||
//! tex coords (2F)
|
||||
ccTex2F texCoords;
|
||||
} ccV2F_C4F_T2F;
|
||||
|
||||
//! a Point with a vertex point, a tex coord point and a color 4B
|
||||
typedef struct _ccV3F_C4B_T2F
|
||||
{
|
||||
//! vertices (3F)
|
||||
ccVertex3F vertices; // 12 bytes
|
||||
// char __padding__[4];
|
||||
|
||||
//! colors (4B)
|
||||
ccColor4B colors; // 4 bytes
|
||||
// char __padding2__[4];
|
||||
|
||||
// tex coords (2F)
|
||||
ccTex2F texCoords; // 8 byts
|
||||
} ccV3F_C4B_T2F;
|
||||
|
||||
//! 4 ccVertex2FTex2FColor4B Quad
|
||||
typedef struct _ccV2F_C4B_T2F_Quad
|
||||
{
|
||||
//! bottom left
|
||||
ccV2F_C4B_T2F bl;
|
||||
//! bottom right
|
||||
ccV2F_C4B_T2F br;
|
||||
//! top left
|
||||
ccV2F_C4B_T2F tl;
|
||||
//! top right
|
||||
ccV2F_C4B_T2F tr;
|
||||
} ccV2F_C4B_T2F_Quad;
|
||||
|
||||
//! 4 ccVertex3FTex2FColor4B
|
||||
typedef struct _ccV3F_C4B_T2F_Quad
|
||||
{
|
||||
//! top left
|
||||
ccV3F_C4B_T2F tl;
|
||||
//! bottom left
|
||||
ccV3F_C4B_T2F bl;
|
||||
//! top right
|
||||
ccV3F_C4B_T2F tr;
|
||||
//! bottom right
|
||||
ccV3F_C4B_T2F br;
|
||||
} ccV3F_C4B_T2F_Quad;
|
||||
|
||||
//! 4 ccVertex2FTex2FColor4F Quad
|
||||
typedef struct _ccV2F_C4F_T2F_Quad
|
||||
{
|
||||
//! bottom left
|
||||
ccV2F_C4F_T2F bl;
|
||||
//! bottom right
|
||||
ccV2F_C4F_T2F br;
|
||||
//! top left
|
||||
ccV2F_C4F_T2F tl;
|
||||
//! top right
|
||||
ccV2F_C4F_T2F tr;
|
||||
} ccV2F_C4F_T2F_Quad;
|
||||
|
||||
//! Blend Function used for textures
|
||||
typedef struct _ccBlendFunc
|
||||
{
|
||||
//! source blend function
|
||||
GLenum src;
|
||||
//! destination blend function
|
||||
GLenum dst;
|
||||
} ccBlendFunc;
|
||||
|
||||
//! ccResolutionType
|
||||
typedef enum
|
||||
{
|
||||
//! Unknonw resolution type
|
||||
kCCResolutionUnknown,
|
||||
//! iPhone resolution type
|
||||
kCCResolutioniPhone,
|
||||
//! RetinaDisplay resolution type
|
||||
kCCResolutioniPhoneRetinaDisplay,
|
||||
//! iPad resolution type
|
||||
kCCResolutioniPad,
|
||||
//! iPad Retina Display resolution type
|
||||
kCCResolutioniPadRetinaDisplay,
|
||||
//! Unknonw resolution type
|
||||
kCCResolutionUnknown,
|
||||
//! iPhone resolution type
|
||||
kCCResolutioniPhone,
|
||||
//! RetinaDisplay resolution type
|
||||
kCCResolutioniPhoneRetinaDisplay,
|
||||
//! iPad resolution type
|
||||
kCCResolutioniPad,
|
||||
//! iPad Retina Display resolution type
|
||||
kCCResolutioniPadRetinaDisplay,
|
||||
|
||||
} ccResolutionType;
|
||||
|
||||
} ccResolutionType;
|
||||
|
||||
//! delta time type
|
||||
//! if you want more resolution redefine it as a double
|
||||
typedef float ccTime;
|
||||
//typedef double ccTime;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CCTextAlignmentLeft,
|
||||
CCTextAlignmentCenter,
|
||||
CCTextAlignmentRight,
|
||||
} CCTextAlignment;
|
||||
|
||||
}//namespace cocos2d
|
||||
|
||||
#endif //__CCTYPES_H__
|
||||
//! delta time type
|
||||
//! if you want more resolution redefine it as a double
|
||||
typedef float ccTime;
|
||||
//typedef double ccTime;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CCTextAlignmentLeft,
|
||||
CCTextAlignmentCenter,
|
||||
CCTextAlignmentRight,
|
||||
} CCTextAlignment;
|
||||
|
||||
// types for animation in particle systems
|
||||
|
||||
// texture coordinates for a quad
|
||||
typedef struct _ccT2F_Quad
|
||||
{
|
||||
//! bottom left
|
||||
ccTex2F bl;
|
||||
//! bottom right
|
||||
ccTex2F br;
|
||||
//! top left
|
||||
ccTex2F tl;
|
||||
//! top right
|
||||
ccTex2F tr;
|
||||
} ccT2F_Quad;
|
||||
|
||||
// struct that holds the size in pixels, texture coordinates and delays for animated CCParticleSystemQuad
|
||||
typedef struct
|
||||
{
|
||||
ccT2F_Quad texCoords;
|
||||
ccTime delay;
|
||||
CCSize size;
|
||||
} ccAnimationFrameData;
|
||||
|
||||
}//namespace cocos2d
|
||||
|
||||
#endif //__CCTYPES_H__
|
||||
|
|
|
@ -32,11 +32,11 @@ THE SOFTWARE.
|
|||
#include "CCDirector.h"
|
||||
#include "CCPointExtension.h"
|
||||
#include "CCScriptSupport.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "CCGLProgram.h"
|
||||
#include "ccGLStateCache.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "CCGLProgram.h"
|
||||
#include "ccGLStateCache.h"
|
||||
#include "support/TransformUtils.h"
|
||||
// extern
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
||||
namespace cocos2d {
|
||||
|
@ -453,26 +453,26 @@ bool CCLayerColor::init()
|
|||
|
||||
bool CCLayerColor::initWithColor(const ccColor4B& color, GLfloat w, GLfloat h)
|
||||
{
|
||||
if( CCLayer::init() ) {
|
||||
|
||||
// default blend function
|
||||
m_tBlendFunc.src = GL_SRC_ALPHA;
|
||||
m_tBlendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
|
||||
|
||||
m_tColor.r = color.r;
|
||||
m_tColor.g = color.g;
|
||||
m_tColor.b = color.b;
|
||||
m_cOpacity = color.a;
|
||||
|
||||
for (int i = 0; i<sizeof(m_pSquareVertices) / sizeof( m_pSquareVertices[0]); i++ ) {
|
||||
m_pSquareVertices[i].x = 0.0f;
|
||||
m_pSquareVertices[i].y = 0.0f;
|
||||
}
|
||||
|
||||
updateColor();
|
||||
setContentSize(CCSizeMake(w, h));
|
||||
|
||||
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor));
|
||||
if( CCLayer::init() ) {
|
||||
|
||||
// default blend function
|
||||
m_tBlendFunc.src = GL_SRC_ALPHA;
|
||||
m_tBlendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
|
||||
|
||||
m_tColor.r = color.r;
|
||||
m_tColor.g = color.g;
|
||||
m_tColor.b = color.b;
|
||||
m_cOpacity = color.a;
|
||||
|
||||
for (int i = 0; i<sizeof(m_pSquareVertices) / sizeof( m_pSquareVertices[0]); i++ ) {
|
||||
m_pSquareVertices[i].x = 0.0f;
|
||||
m_pSquareVertices[i].y = 0.0f;
|
||||
}
|
||||
|
||||
updateColor();
|
||||
setContentSize(CCSizeMake(w, h));
|
||||
|
||||
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -523,18 +523,18 @@ void CCLayerColor::updateColor()
|
|||
|
||||
void CCLayerColor::draw()
|
||||
{
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_Color );
|
||||
|
||||
//
|
||||
// Attributes
|
||||
//
|
||||
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, m_pSquareVertices);
|
||||
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, m_pSquareColors);
|
||||
|
||||
ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
|
||||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_Color );
|
||||
|
||||
//
|
||||
// Attributes
|
||||
//
|
||||
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, m_pSquareVertices);
|
||||
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, m_pSquareColors);
|
||||
|
||||
ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
CC_INCREMENT_GL_DRAWS(1);
|
||||
|
|
|
@ -38,6 +38,10 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
static const char *__suffixiPhoneRetinaDisplay = "-hd";
|
||||
static const char *__suffixiPad = "-ipad";
|
||||
static const char *__suffixiPadRetinaDisplay = "-ipadhd";
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SAX_NONE = 0,
|
||||
|
@ -266,25 +270,24 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path)
|
||||
{
|
||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
std::string& CCFileUtils::removeSuffixFromFile(std::string& path)
|
||||
{
|
||||
// XXX win32 now can only support iphone retina, because
|
||||
// we don't know it is ipad retina or iphone retina.
|
||||
// fixe me later
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 2 )
|
||||
{
|
||||
std::string::size_type pos = path.rfind("/") + 1; // the begin index of last part of path
|
||||
|
||||
std::string::size_type suffixPos = path.rfind(CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
std::string::size_type suffixPos = path.rfind(__suffixiPhoneRetinaDisplay);
|
||||
if (std::string::npos != suffixPos && suffixPos > pos)
|
||||
{
|
||||
CCLog("cocos2d: FilePath(%s) contains suffix(%s), remove it.", path.c_str(),
|
||||
CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
path.replace(suffixPos, strlen(CC_RETINA_DISPLAY_FILENAME_SUFFIX), "");
|
||||
__suffixiPhoneRetinaDisplay);
|
||||
path.replace(suffixPos, strlen(__suffixiPhoneRetinaDisplay), "");
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
@ -344,6 +347,47 @@ unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const
|
|||
return pBuffer;
|
||||
}
|
||||
|
||||
|
||||
/// functions iOS specific
|
||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType)
|
||||
{
|
||||
assert(0);
|
||||
return "";
|
||||
}
|
||||
|
||||
void CCFileUtils::setiPhoneRetinaDisplaySuffix(const char *suffix)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
void CCFileUtils::setiPadSuffix(const char *suffix)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
void CCFileUtils::setiPadRetinaDisplaySuffix(const char *suffix)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
bool CCFileUtils::iPadFileExistsAtPath(const char *filename)
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCFileUtils::iPadRetinaDisplayFileExistsAtPath(const char *filename)
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCFileUtils::iPhoneRetinaDisplayFileExistsAtPath(const char *filename)
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Notification support when getFileData from invalid file path.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -53,11 +53,15 @@ public:
|
|||
*/
|
||||
static unsigned char* getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize);
|
||||
|
||||
/** removes the HD suffix from a path
|
||||
@returns const char * without the HD suffix
|
||||
@since v0.99.5
|
||||
*/
|
||||
static std::string& ccRemoveHDSuffixFromFile(std::string& path);
|
||||
/** removes the suffix from a path
|
||||
* On RetinaDisplay it will remove the -hd suffix
|
||||
* On iPad it will remove the -ipad suffix
|
||||
* On iPhone it will remove the (empty) suffix
|
||||
Only valid on iOS. Not valid for OS X.
|
||||
|
||||
@since v0.99.5
|
||||
*/
|
||||
static std::string& removeSuffixFromFile(std::string& path);
|
||||
|
||||
/**
|
||||
@brief Generate the absolute path of the file.
|
||||
|
@ -69,10 +73,68 @@ public:
|
|||
*/
|
||||
static const char* fullPathFromRelativePath(const char *pszRelativePath);
|
||||
|
||||
/** Returns the fullpath of an filename including the resolution of the image.
|
||||
|
||||
If in RetinaDisplay mode, and a RetinaDisplay file is found, it will return that path.
|
||||
If in iPad mode, and an iPad file is found, it will return that path.
|
||||
|
||||
Examples:
|
||||
|
||||
* In iPad mode: "image.png" -> "/full/path/image-ipad.png" (in case the -ipad file exists)
|
||||
* In RetinaDisplay mode: "image.png" -> "/full/path/image-hd.png" (in case the -hd file exists)
|
||||
|
||||
If an iPad file is found, it will set resolution type to kCCResolutioniPad
|
||||
If a RetinaDisplay file is found, it will set resolution type to kCCResolutionRetinaDisplay
|
||||
|
||||
*/
|
||||
static const char* fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType);
|
||||
|
||||
/// @cond
|
||||
static const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile);
|
||||
/// @endcond
|
||||
|
||||
/** Sets the iPhone RetinaDisplay suffix to load resources.
|
||||
By default it is "-hd".
|
||||
Only valid on iOS. Not valid for OS X.
|
||||
|
||||
@since v1.1
|
||||
*/
|
||||
static void setiPhoneRetinaDisplaySuffix(const char *suffix);
|
||||
|
||||
/** Sets the iPad suffix to load resources.
|
||||
By default it is "".
|
||||
Only valid on iOS. Not valid for OS X.
|
||||
|
||||
|
||||
*/
|
||||
static void setiPadSuffix(const char *suffix);
|
||||
|
||||
/** Sets the iPad Retina Display suffix to load resources.
|
||||
By default it is "-ipadhd".
|
||||
Only valid on iOS. Not valid for OS X.
|
||||
|
||||
@since v1.1
|
||||
*/
|
||||
static void setiPadRetinaDisplaySuffix(const char *suffix);
|
||||
|
||||
/** Returns whether or not a given filename exists with the iPad suffix.
|
||||
Only available on iOS. Not supported on OS X.
|
||||
@since v1.1
|
||||
*/
|
||||
bool iPadFileExistsAtPath(const char *filename);
|
||||
|
||||
/** Returns whether or not a given filename exists with the iPad RetinaDisplay suffix.
|
||||
Only available on iOS. Not supported on OS X.
|
||||
|
||||
*/
|
||||
bool iPadRetinaDisplayFileExistsAtPath(const char *filename);
|
||||
|
||||
/** Returns whether or not a given path exists with the iPhone RetinaDisplay suffix.
|
||||
Only available on iOS. Not supported on OS X.
|
||||
@since v1.1
|
||||
*/
|
||||
bool iPhoneRetinaDisplayFileExistsAtPath(const char *filename);
|
||||
|
||||
/**
|
||||
@brief Set the ResourcePath,we will find resource in this path
|
||||
@param pszResourcePath The absolute resource path
|
||||
|
|
|
@ -61,6 +61,11 @@ void CCEGLView::setFrameWidthAndHeight(int width, int height)
|
|||
m_sSizeInPixel.height = height;
|
||||
}
|
||||
|
||||
bool CCEGLView::isIpad()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void CCEGLView::create(int width, int height)
|
||||
{
|
||||
if (width == 0 || height == 0)
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
|
||||
CCSize getSize();
|
||||
bool isOpenGLReady();
|
||||
bool isIpad();
|
||||
/**
|
||||
* the width and height is the real size of phone
|
||||
*/
|
||||
|
|
|
@ -241,6 +241,11 @@ CCRect CCEGLView::getFrame()
|
|||
return rc;
|
||||
}
|
||||
|
||||
bool CCEGLView::isIpad()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCEGLView::isOpenGLReady()
|
||||
{
|
||||
return (NULL != m_pEGL);
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
CCRect getFrame();
|
||||
CCSize getSize();
|
||||
bool isOpenGLReady();
|
||||
bool isIpad();
|
||||
void release();
|
||||
void setTouchDelegate(EGLTouchDelegate * pDelegate);
|
||||
void swapBuffers();
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
CCSize getSize();
|
||||
bool isOpenGLReady();
|
||||
bool canSetContentScaleFactor();
|
||||
bool isIpad();
|
||||
void setContentScaleFactor(float contentScaleFactor);
|
||||
|
||||
// keep compatible
|
||||
|
|
|
@ -47,6 +47,11 @@ cocos2d::CCSize CCEGLView::getSize()
|
|||
return size;
|
||||
}
|
||||
|
||||
bool CCEGLView::isIpad()
|
||||
{
|
||||
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
|
||||
}
|
||||
|
||||
bool CCEGLView::isOpenGLReady()
|
||||
{
|
||||
return [EAGLView sharedEGLView] != NULL;
|
||||
|
|
|
@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIDevice.h>
|
||||
|
||||
#include <string>
|
||||
#include <stack>
|
||||
|
@ -42,104 +43,74 @@ using namespace cocos2d;
|
|||
static void static_addValueToCCDict(id key, id value, CCDictionary* pDict);
|
||||
static void static_addItemToCCArray(id item, CCArray* pArray);
|
||||
|
||||
static const char *static_ccRemoveHDSuffixFromFile( const char *pszPath)
|
||||
static NSString *__suffixiPhoneRetinaDisplay =@"-hd";
|
||||
static NSString *__suffixiPad =@"-ipad";
|
||||
static NSString *__suffixiPadRetinaDisplay =@"-ipadhd";
|
||||
static NSFileManager *__localFileManager= [[NSFileManager alloc] init];
|
||||
|
||||
static NSString* removeSuffixFromPath(NSString *suffix, NSString *path)
|
||||
{
|
||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
if(cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 ) {
|
||||
NSString *path = [NSString stringWithUTF8String: pszPath];
|
||||
NSString *name = [path lastPathComponent];
|
||||
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
||||
|
||||
CCLOG("cocos2d: Filename(%@) contains %@ suffix. Removing it. See cocos2d issue #1040", path, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
|
||||
NSString *newLastname = [name stringByReplacingOccurrencesOfString: suffix withString:@""];
|
||||
|
||||
NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent];
|
||||
return [[pathWithoutLastname stringByAppendingPathComponent:newLastname] UTF8String];
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
return pszPath;
|
||||
}
|
||||
|
||||
static NSString* getDoubleResolutionImage(NSString* path)
|
||||
{
|
||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
if( cocos2d::CC_CONTENT_SCALE_FACTOR() == 2 )
|
||||
{
|
||||
|
||||
NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
|
||||
NSString *name = [pathWithoutExtension lastPathComponent];
|
||||
NSString *suffix = [NSString stringWithUTF8String: CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString: suffix].location != NSNotFound ) {
|
||||
|
||||
CCLOG("cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.", name, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
NSString *extension = [path pathExtension];
|
||||
|
||||
if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] )
|
||||
{
|
||||
// All ccz / gz files should be in the format filename.xxx.ccz
|
||||
// so we need to pull off the .xxx part of the extension as well
|
||||
extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension];
|
||||
pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
|
||||
NSString *retinaName = [pathWithoutExtension stringByAppendingString: suffix];
|
||||
retinaName = [retinaName stringByAppendingPathExtension:extension];
|
||||
|
||||
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
|
||||
if( [fileManager fileExistsAtPath:retinaName] )
|
||||
return retinaName;
|
||||
|
||||
CCLOG("cocos2d: CCFileUtils: Warning HD file not found: %@", [retinaName lastPathComponent] );
|
||||
}
|
||||
|
||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static const char* static_fullPathFromRelativePath(const char *pszRelativePath)
|
||||
|
||||
{
|
||||
|
||||
// NSAssert(pszRelativePath != nil, @"CCFileUtils: Invalid path");
|
||||
|
||||
// do not convert an absolute path (starting with '/')
|
||||
NSString *relPath = [NSString stringWithUTF8String: pszRelativePath];
|
||||
NSString *fullpath = nil;
|
||||
|
||||
// only if it is not an absolute path
|
||||
if( ! [relPath isAbsolutePath] )
|
||||
// quick return
|
||||
if( ! suffix || [suffix length] == 0 )
|
||||
{
|
||||
NSString *file = [relPath lastPathComponent];
|
||||
NSString *imageDirectory = [relPath stringByDeletingLastPathComponent];
|
||||
|
||||
fullpath = [[NSBundle mainBundle] pathForResource:file
|
||||
ofType:nil
|
||||
inDirectory:imageDirectory];
|
||||
return path;
|
||||
}
|
||||
|
||||
NSString *name = [path lastPathComponent];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString:suffix].location != NSNotFound ) {
|
||||
|
||||
CCLOG("cocos2d: Filename(%s) contains %s suffix. Removing it. See cocos2d issue #1040", [path UTF8String], [suffix UTF8String]);
|
||||
|
||||
NSString *newLastname = [name stringByReplacingOccurrencesOfString:suffix withString:@""];
|
||||
|
||||
NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent];
|
||||
return [pathWithoutLastname stringByAppendingPathComponent:newLastname];
|
||||
}
|
||||
|
||||
if (fullpath == nil)
|
||||
fullpath = relPath;
|
||||
|
||||
fullpath = getDoubleResolutionImage(fullpath);
|
||||
|
||||
return [fullpath UTF8String];
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static NSString* getPathForSuffix(NSString *path, NSString *suffix)
|
||||
{
|
||||
// quick return
|
||||
if( ! suffix || [suffix length] == 0 )
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
|
||||
NSString *name = [pathWithoutExtension lastPathComponent];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString:suffix].location != NSNotFound ) {
|
||||
|
||||
CCLOG("cocos2d: WARNING Filename(%s) already has the suffix %s. Using it.", [name UTF8String], [suffix UTF8String]);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
NSString *extension = [path pathExtension];
|
||||
|
||||
if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] )
|
||||
{
|
||||
// All ccz / gz files should be in the format filename.xxx.ccz
|
||||
// so we need to pull off the .xxx part of the extension as well
|
||||
extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension];
|
||||
pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
|
||||
NSString *newName = [pathWithoutExtension stringByAppendingString:suffix];
|
||||
newName = [newName stringByAppendingPathExtension:extension];
|
||||
|
||||
if( [__localFileManager fileExistsAtPath:newName] )
|
||||
return newName;
|
||||
|
||||
CCLOG("cocos2d: CCFileUtils: Warning file not found: %s", [[newName lastPathComponent] UTF8String] );
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
static void static_addItemToCCArray(id item, CCArray *pArray)
|
||||
|
@ -274,15 +245,164 @@ namespace cocos2d {
|
|||
return size;
|
||||
}
|
||||
|
||||
std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path )
|
||||
std::string& CCFileUtils::removeSuffixFromFile(std::string& cpath )
|
||||
{
|
||||
path = static_ccRemoveHDSuffixFromFile(path.c_str());
|
||||
return path;
|
||||
NSString *ret = nil;
|
||||
NSString *path = [NSString stringWithUTF8String:cpath.c_str()];
|
||||
|
||||
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
|
||||
{
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 2 )
|
||||
{
|
||||
ret = removeSuffixFromPath(__suffixiPadRetinaDisplay, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = removeSuffixFromPath(__suffixiPad, path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 2 )
|
||||
{
|
||||
ret = removeSuffixFromPath(__suffixiPhoneRetinaDisplay, [NSString stringWithUTF8String:cpath.c_str()]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cpath = [ret UTF8String];
|
||||
return cpath;
|
||||
}
|
||||
|
||||
void CCFileUtils::setiPhoneRetinaDisplaySuffix(const char *suffix)
|
||||
{
|
||||
[__suffixiPhoneRetinaDisplay release];
|
||||
__suffixiPhoneRetinaDisplay = [[NSString stringWithUTF8String:suffix] retain];
|
||||
}
|
||||
|
||||
void CCFileUtils::setiPadSuffix(const char *suffix)
|
||||
{
|
||||
[__suffixiPad release];
|
||||
__suffixiPad = [[NSString stringWithUTF8String:suffix] retain];
|
||||
}
|
||||
|
||||
void CCFileUtils::setiPadRetinaDisplaySuffix(const char *suffix)
|
||||
{
|
||||
[__suffixiPadRetinaDisplay release];
|
||||
__suffixiPadRetinaDisplay = [[NSString stringWithUTF8String:suffix] retain];
|
||||
}
|
||||
|
||||
bool fileExistsAtPath(const char *cpath, const char *csuffix)
|
||||
{
|
||||
NSString *fullpath = nil;
|
||||
NSString *relPath = [NSString stringWithUTF8String:cpath];
|
||||
NSString *suffix = [NSString stringWithUTF8String:csuffix];
|
||||
|
||||
// only if it is not an absolute path
|
||||
if( ! [relPath isAbsolutePath] ) {
|
||||
// pathForResource also searches in .lproj directories. issue #1230
|
||||
NSString *file = [relPath lastPathComponent];
|
||||
NSString *imageDirectory = [relPath stringByDeletingLastPathComponent];
|
||||
|
||||
fullpath = [[NSBundle mainBundle] pathForResource:file
|
||||
ofType:nil
|
||||
inDirectory:imageDirectory];
|
||||
|
||||
}
|
||||
|
||||
if (fullpath == nil)
|
||||
fullpath = relPath;
|
||||
|
||||
NSString *path = getPathForSuffix(fullpath, suffix);
|
||||
|
||||
return ( path != nil );
|
||||
}
|
||||
|
||||
bool CCFileUtils::iPhoneRetinaDisplayFileExistsAtPath(const char *cpath)
|
||||
{
|
||||
return fileExistsAtPath(cpath, [__suffixiPhoneRetinaDisplay UTF8String]);
|
||||
}
|
||||
|
||||
bool CCFileUtils::iPadFileExistsAtPath(const char *cpath)
|
||||
{
|
||||
return fileExistsAtPath(cpath, [__suffixiPad UTF8String]);
|
||||
}
|
||||
|
||||
bool CCFileUtils::iPadRetinaDisplayFileExistsAtPath(const char *cpath)
|
||||
{
|
||||
return fileExistsAtPath(cpath, [__suffixiPadRetinaDisplay UTF8String]);
|
||||
}
|
||||
|
||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||
{
|
||||
return static_fullPathFromRelativePath(pszRelativePath);
|
||||
ccResolutionType ignore;
|
||||
return fullPathFromRelativePath(pszRelativePath, &ignore);
|
||||
}
|
||||
|
||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType)
|
||||
{
|
||||
CCAssert(pszRelativePath != NULL, "CCFileUtils: Invalid path");
|
||||
|
||||
NSString *fullpath = nil;
|
||||
NSString *relPath = [NSString stringWithUTF8String:pszRelativePath];
|
||||
|
||||
// only if it is not an absolute path
|
||||
if( ! [relPath isAbsolutePath] ) {
|
||||
|
||||
// pathForResource also searches in .lproj directories. issue #1230
|
||||
NSString *file = [relPath lastPathComponent];
|
||||
NSString *imageDirectory = [relPath stringByDeletingLastPathComponent];
|
||||
|
||||
fullpath = [[NSBundle mainBundle] pathForResource:file
|
||||
ofType:nil
|
||||
inDirectory:imageDirectory];
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (fullpath == nil)
|
||||
{
|
||||
fullpath = relPath;
|
||||
}
|
||||
|
||||
NSString *ret = nil;
|
||||
|
||||
// iPad?
|
||||
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
|
||||
{
|
||||
// Retina Display ?
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 2 ) {
|
||||
ret = getPathForSuffix(fullpath, __suffixiPadRetinaDisplay);
|
||||
*pResolutionType = kCCResolutioniPadRetinaDisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = getPathForSuffix(fullpath, __suffixiPad);
|
||||
*pResolutionType = kCCResolutioniPad;
|
||||
}
|
||||
}
|
||||
// iPhone ?
|
||||
else
|
||||
{
|
||||
// Retina Display ?
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 2 ) {
|
||||
ret = getPathForSuffix(fullpath, __suffixiPhoneRetinaDisplay);
|
||||
*pResolutionType = kCCResolutioniPhoneRetinaDisplay;
|
||||
}
|
||||
}
|
||||
|
||||
// If it is iPhone Non RetinaDisplay, or if the previous "getPath" failed, then use iPhone images.
|
||||
if( ret == nil )
|
||||
{
|
||||
*pResolutionType = kCCResolutioniPhone;
|
||||
ret = fullpath;
|
||||
}
|
||||
|
||||
return [ret UTF8String];
|
||||
}
|
||||
|
||||
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
||||
|
|
|
@ -278,6 +278,11 @@ bool CCEGLView::isOpenGLReady()
|
|||
return bIsInit;
|
||||
}
|
||||
|
||||
bool CCEGLView::isIpad()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void CCEGLView::release()
|
||||
{
|
||||
/* Exits from GLFW */
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
|
||||
CCSize getSize();
|
||||
bool isOpenGLReady();
|
||||
bool isIpad();
|
||||
void release();
|
||||
void setTouchDelegate(EGLTouchDelegate * pDelegate);
|
||||
void swapBuffers();
|
||||
|
|
|
@ -265,6 +265,11 @@ bool CCEGLView::isOpenGLReady()
|
|||
return (IwGLIsInitialised() && m_sSizeInPixel.width != 0 && m_sSizeInPixel.height !=0);
|
||||
}
|
||||
|
||||
bool CCEGLView::isIpad()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void CCEGLView::release()
|
||||
{
|
||||
IW_CALLSTACK("CCEGLView::release");
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
|
||||
CCSize getSize();
|
||||
bool isOpenGLReady();
|
||||
bool isIpad();
|
||||
/**
|
||||
* the width and height is the real size of phone
|
||||
*/
|
||||
|
|
|
@ -786,6 +786,11 @@ bool CCEGLView::isOpenGLReady()
|
|||
return (m_isGLInitialized && m_sSizeInPixel.width != 0 && m_sSizeInPixel.height != 0);
|
||||
}
|
||||
|
||||
bool CCEGLView::isIpad()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void CCEGLView::release()
|
||||
{
|
||||
if (!m_eglContext || !m_eglDisplay)
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
|
||||
CCSize getSize();
|
||||
bool isOpenGLReady();
|
||||
bool isIpad();
|
||||
/**
|
||||
* the width and height is the real size of phone
|
||||
*/
|
||||
|
|
|
@ -419,6 +419,11 @@ bool CCEGLView::isOpenGLReady()
|
|||
return (NULL != m_pEGL);
|
||||
}
|
||||
|
||||
bool CCEGLView::isIpad()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void CCEGLView::release()
|
||||
{
|
||||
if (m_hWnd)
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
|
||||
CCSize getSize();
|
||||
bool isOpenGLReady();
|
||||
bool isIpad();
|
||||
void release();
|
||||
void setTouchDelegate(EGLTouchDelegate * pDelegate);
|
||||
void swapBuffers();
|
||||
|
|
|
@ -218,9 +218,7 @@ bool CCTexture2D::initWithData(const void *data, CCTexture2DPixelFormat pixelFor
|
|||
|
||||
m_bHasPremultipliedAlpha = false;
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
m_resolutionType = kCCResolutionUnknown;
|
||||
#endif
|
||||
m_eResolutionType = kCCResolutionUnknown;
|
||||
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture));
|
||||
|
||||
return true;
|
||||
|
@ -235,11 +233,13 @@ char * CCTexture2D::description(void)
|
|||
}
|
||||
|
||||
// implementation CCTexture2D (Image)
|
||||
#if 0// TODO: #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
bool CCTexture2D::initWithImage(CCImage *uiImage)
|
||||
{
|
||||
return initWithImage(uiImage, kCCResolutionUnknown);
|
||||
}
|
||||
|
||||
bool CCTexture2D::initWithImage(CCImage * uiImage, ccResolutionType resolution)
|
||||
#else
|
||||
bool CCTexture2D::initWithImage(CCImage * uiImage)
|
||||
#endif
|
||||
{
|
||||
unsigned int POTWide, POTHigh;
|
||||
|
||||
|
@ -273,9 +273,7 @@ bool CCTexture2D::initWithImage(CCImage * uiImage)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#if 0//TODO (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
m_resolutionType = resolution;
|
||||
#endif
|
||||
m_eResolutionType = resolution;
|
||||
|
||||
// always load premultiplied images
|
||||
return initPremultipliedATextureWithImage(uiImage, POTWide, POTHigh);
|
||||
|
@ -486,11 +484,8 @@ bool CCTexture2D::initWithString(const char *text, const CCSize& dimensions, CCT
|
|||
{
|
||||
return false;
|
||||
}
|
||||
#if 0// TODO: (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
return initWithImage(&image, m_resolutionType);
|
||||
#else
|
||||
|
||||
return initWithImage(&image);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ void CCTextureCache::addImageAsync(const char *path, CCObject *target, SEL_CallF
|
|||
// optimization
|
||||
|
||||
std::string pathKey = path;
|
||||
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
||||
CCFileUtils::removeSuffixFromFile(pathKey);
|
||||
|
||||
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
||||
texture = (CCTexture2D*)m_pTextures->objectForKey(pathKey.c_str());
|
||||
|
@ -330,7 +330,8 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
|||
|
||||
// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
|
||||
std::string pathKey = path;
|
||||
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
||||
ccResolutionType resolution;
|
||||
CCFileUtils::removeSuffixFromFile(pathKey);
|
||||
|
||||
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
||||
texture = (CCTexture2D*)m_pTextures->objectForKey(pathKey.c_str());
|
||||
|
@ -360,7 +361,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
|||
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtJpg));
|
||||
|
||||
texture = new CCTexture2D();
|
||||
texture->initWithImage(&image);
|
||||
texture->initWithImage(&image, resolution);
|
||||
|
||||
if( texture )
|
||||
{
|
||||
|
@ -388,7 +389,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
|||
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtPng));
|
||||
|
||||
texture = new CCTexture2D();
|
||||
texture->initWithImage(&image);
|
||||
texture->initWithImage(&image, resolution);
|
||||
|
||||
if( texture )
|
||||
{
|
||||
|
@ -423,7 +424,7 @@ CCTexture2D* CCTextureCache::addPVRTCImage(const char* path, int bpp, bool hasAl
|
|||
CCTexture2D * texture;
|
||||
|
||||
std::string temp(path);
|
||||
CCFileUtils::ccRemoveHDSuffixFromFile(temp);
|
||||
CCFileUtils::removeSuffixFromFile(temp);
|
||||
|
||||
if ( (texture = (CCTexture2D*)m_pTextures->objectForKey(temp.c_str())) )
|
||||
{
|
||||
|
@ -459,7 +460,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
|
|||
CCTexture2D * tex;
|
||||
std::string key(path);
|
||||
// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
|
||||
CCFileUtils::ccRemoveHDSuffixFromFile(key);
|
||||
CCFileUtils::removeSuffixFromFile(key);
|
||||
|
||||
if( (tex = (CCTexture2D*)m_pTextures->objectForKey(key.c_str())) )
|
||||
{
|
||||
|
@ -471,9 +472,9 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
|
|||
tex = new CCTexture2D();
|
||||
if( tex->initWithPVRFile(fullpath.c_str()) )
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||
// cache the texture file name
|
||||
VolatileTexture::addImageTexture(tex, fullpath.c_str(), CCImage::kFmtRawData);
|
||||
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||
// cache the texture file name
|
||||
VolatileTexture::addImageTexture(tex, fullpath.c_str(), CCImage::kFmtRawData);
|
||||
#endif
|
||||
m_pTextures->setObject(tex, key.c_str());
|
||||
tex->autorelease();
|
||||
|
@ -511,7 +512,7 @@ CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
|
|||
|
||||
// prevents overloading the autorelease pool
|
||||
texture = new CCTexture2D();
|
||||
texture->initWithImage(image);
|
||||
texture->initWithImage(image, kCCResolutionUnknown);
|
||||
|
||||
if(key && texture)
|
||||
{
|
||||
|
@ -743,38 +744,38 @@ void VolatileTexture::reloadAllTextures()
|
|||
|
||||
switch (vt->m_eCashedImageType)
|
||||
{
|
||||
case kImageFile:
|
||||
{
|
||||
CCImage image;
|
||||
std::string lowerCase(vt->m_strFileName.c_str());
|
||||
for (unsigned int i = 0; i < lowerCase.length(); ++i)
|
||||
{
|
||||
lowerCase[i] = tolower(lowerCase[i]);
|
||||
}
|
||||
|
||||
if (std::string::npos != lowerCase.find(".pvr"))
|
||||
{
|
||||
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
|
||||
|
||||
vt->texture->initWithPVRFile(vt->m_strFileName.c_str());
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCFileData data(vt->m_strFileName.c_str(), "rb");
|
||||
unsigned long nSize = data.getSize();
|
||||
unsigned char* pBuffer = data.getBuffer();
|
||||
|
||||
if (image.initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage))
|
||||
{
|
||||
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
|
||||
vt->texture->initWithImage(&image);
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
case kImageFile:
|
||||
{
|
||||
CCImage image;
|
||||
std::string lowerCase(vt->m_strFileName.c_str());
|
||||
for (unsigned int i = 0; i < lowerCase.length(); ++i)
|
||||
{
|
||||
lowerCase[i] = tolower(lowerCase[i]);
|
||||
}
|
||||
|
||||
if (std::string::npos != lowerCase.find(".pvr"))
|
||||
{
|
||||
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
|
||||
|
||||
vt->texture->initWithPVRFile(vt->m_strFileName.c_str());
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCFileData data(vt->m_strFileName.c_str(), "rb");
|
||||
unsigned long nSize = data.getSize();
|
||||
unsigned char* pBuffer = data.getBuffer();
|
||||
|
||||
if (image.initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage))
|
||||
{
|
||||
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
|
||||
vt->texture->initWithImage(&image);
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case kImageData:
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "EffectsAdvancedTest.h"
|
||||
|
||||
#include "EffectsAdvancedTest.h"
|
||||
|
||||
enum
|
||||
{
|
||||
kTagTextLayer = 1,
|
||||
|
@ -9,17 +9,17 @@ enum
|
|||
|
||||
kTagBackground = 1,
|
||||
kTagLabel = 2,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Effect1
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void Effect1::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
void Effect1::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
CCNode* target = getChildByTag(kTagBackground);
|
||||
|
||||
// To reuse a grid the grid size and the grid type must be the same.
|
||||
|
@ -38,23 +38,23 @@ void Effect1::onEnter()
|
|||
CCActionInterval* orbit_back = orbit->reverse();
|
||||
|
||||
target->runAction( CCRepeatForever::actionWithAction( (CCActionInterval *)(CCSequence::actions( orbit, orbit_back, NULL) ) ) );
|
||||
target->runAction( CCSequence::actions(lens, delay, reuse, waves, NULL) );
|
||||
}
|
||||
|
||||
target->runAction( CCSequence::actions(lens, delay, reuse, waves, NULL) );
|
||||
}
|
||||
|
||||
std::string Effect1::title()
|
||||
{
|
||||
return "Lens + Waves3d and OrbitCamera";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Effect2
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void Effect2::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
void Effect2::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
CCNode* target = getChildByTag(kTagBackground);
|
||||
|
||||
// To reuse a grid the grid size and the grid type must be the same.
|
||||
|
@ -79,24 +79,24 @@ void Effect2::onEnter()
|
|||
// id orbit_back = [orbit reverse];
|
||||
//
|
||||
// [target runAction: [RepeatForever::actionWithAction: [Sequence actions: orbit, orbit_back, nil]]];
|
||||
target->runAction( (CCActionInterval *)(CCSequence::actions( shaky, delay, reuse, shuffle, delay->copy()->autorelease(), turnoff, turnon, NULL) ) );
|
||||
}
|
||||
|
||||
target->runAction( (CCActionInterval *)(CCSequence::actions( shaky, delay, reuse, shuffle, delay->copy()->autorelease(), turnoff, turnon, NULL) ) );
|
||||
}
|
||||
|
||||
std::string Effect2::title()
|
||||
{
|
||||
return "ShakyTiles + ShuffleTiles + TurnOffTiles";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Effect3
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void Effect3::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
void Effect3::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
CCNode* bg = getChildByTag(kTagBackground);
|
||||
CCNode* target1 = bg->getChildByTag(kTagSprite1);
|
||||
CCNode* target2 = bg->getChildByTag(kTagSprite2);
|
||||
|
@ -109,51 +109,51 @@ void Effect3::onEnter()
|
|||
|
||||
// moving background. Testing issue #244
|
||||
CCActionInterval* move = CCMoveBy::actionWithDuration(3, ccp(200,0) );
|
||||
bg->runAction(CCRepeatForever::actionWithAction( (CCActionInterval *)(CCSequence::actions(move, move->reverse(), NULL) ) ) );
|
||||
}
|
||||
|
||||
bg->runAction(CCRepeatForever::actionWithAction( (CCActionInterval *)(CCSequence::actions(move, move->reverse(), NULL) ) ) );
|
||||
}
|
||||
|
||||
std::string Effect3::title()
|
||||
{
|
||||
return "Effects on 2 sprites";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Effect4
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void Effect4::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
void Effect4::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
CCActionInterval* lens = CCLens3D::actionWithPosition(ccp(100,180), 150, ccg(32,24), 10);
|
||||
//id move = [MoveBy::actionWithDuration:5 position:ccp(400,0)];
|
||||
|
||||
/**
|
||||
@todo we only support CCNode run actions now.
|
||||
*/
|
||||
// CCActionInterval* move = CCJumpBy::actionWithDuration(5, ccp(380,0), 100, 4);
|
||||
// CCActionInterval* move_back = move->reverse();
|
||||
// CCActionInterval* seq = (CCActionInterval *)(CCSequence::actions( move, move_back, NULL));
|
||||
// CCActionManager::sharedManager()->addAction(seq, lens, false);
|
||||
|
||||
runAction( lens );
|
||||
}
|
||||
|
||||
//id move = [MoveBy::actionWithDuration:5 position:ccp(400,0)];
|
||||
|
||||
/**
|
||||
@todo we only support CCNode run actions now.
|
||||
*/
|
||||
// CCActionInterval* move = CCJumpBy::actionWithDuration(5, ccp(380,0), 100, 4);
|
||||
// CCActionInterval* move_back = move->reverse();
|
||||
// CCActionInterval* seq = (CCActionInterval *)(CCSequence::actions( move, move_back, NULL));
|
||||
// CCActionManager::sharedManager()->addAction(seq, lens, false);
|
||||
|
||||
runAction( lens );
|
||||
}
|
||||
|
||||
std::string Effect4::title()
|
||||
{
|
||||
return "Jumpy Lens3D";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Effect5
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void Effect5::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
void Effect5::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
//CCDirector::sharedDirector()->setProjection(CCDirectorProjection2D);
|
||||
|
||||
|
@ -168,80 +168,80 @@ void Effect5::onEnter()
|
|||
NULL) );
|
||||
|
||||
CCNode* bg = getChildByTag(kTagBackground);
|
||||
bg->runAction(stopEffect);
|
||||
}
|
||||
|
||||
bg->runAction(stopEffect);
|
||||
}
|
||||
|
||||
std::string Effect5::title()
|
||||
{
|
||||
return "Test Stop-Copy-Restar";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Effect5::onExit()
|
||||
{
|
||||
EffectAdvanceTextLayer::onExit();
|
||||
|
||||
CCDirector::sharedDirector()->setProjection(CCDirectorProjection3D);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Effect5
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void Issue631::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
CCActionInterval* effect = (CCActionInterval*)(CCSequence::actions( CCDelayTime::actionWithDuration(2.0f), CCShaky3D::actionWithRange(16, false, ccg(5, 5), 5.0f), NULL));
|
||||
|
||||
// cleanup
|
||||
CCNode* bg = getChildByTag(kTagBackground);
|
||||
removeChild(bg, true);
|
||||
|
||||
// background
|
||||
CCLayerColor* layer = CCLayerColor::layerWithColor( ccc4(255,0,0,255) );
|
||||
addChild(layer, -10);
|
||||
CCSprite* sprite = CCSprite::spriteWithFile("Images/grossini.png");
|
||||
sprite->setPosition( ccp(50,80) );
|
||||
layer->addChild(sprite, 10);
|
||||
|
||||
// foreground
|
||||
CCLayerColor* layer2 = CCLayerColor::layerWithColor(ccc4( 0, 255,0,255 ) );
|
||||
CCSprite* fog = CCSprite::spriteWithFile("Images/Fog.png");
|
||||
|
||||
ccBlendFunc bf = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA};
|
||||
fog->setBlendFunc(bf);
|
||||
layer2->addChild(fog, 1);
|
||||
addChild(layer2, 1);
|
||||
|
||||
layer2->runAction( CCRepeatForever::actionWithAction(effect) );
|
||||
}
|
||||
|
||||
std::string Issue631::title()
|
||||
{
|
||||
return "Testing Opacity";
|
||||
}
|
||||
|
||||
std::string Issue631::subtitle()
|
||||
{
|
||||
return "Effect image should be 100% opaque. Testing issue #631";
|
||||
}
|
||||
|
||||
void Issue631::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
|
||||
CCActionInterval* effect = (CCActionInterval*)(CCSequence::actions( CCDelayTime::actionWithDuration(2.0f), CCShaky3D::actionWithRange(16, false, ccg(5, 5), 5.0f), NULL));
|
||||
|
||||
// cleanup
|
||||
CCNode* bg = getChildByTag(kTagBackground);
|
||||
removeChild(bg, true);
|
||||
|
||||
// background
|
||||
CCLayerColor* layer = CCLayerColor::layerWithColor( ccc4(255,0,0,255) );
|
||||
addChild(layer, -10);
|
||||
CCSprite* sprite = CCSprite::spriteWithFile("Images/grossini.png");
|
||||
sprite->setPosition( ccp(50,80) );
|
||||
layer->addChild(sprite, 10);
|
||||
|
||||
// foreground
|
||||
CCLayerColor* layer2 = CCLayerColor::layerWithColor(ccc4( 0, 255,0,255 ) );
|
||||
CCSprite* fog = CCSprite::spriteWithFile("Images/Fog.png");
|
||||
|
||||
ccBlendFunc bf = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA};
|
||||
fog->setBlendFunc(bf);
|
||||
layer2->addChild(fog, 1);
|
||||
addChild(layer2, 1);
|
||||
|
||||
layer2->runAction( CCRepeatForever::actionWithAction(effect) );
|
||||
}
|
||||
|
||||
std::string Issue631::title()
|
||||
{
|
||||
return "Testing Opacity";
|
||||
}
|
||||
|
||||
std::string Issue631::subtitle()
|
||||
{
|
||||
return "Effect image should be 100% opaque. Testing issue #631";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// EffectAdvanceTextLayer
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
IDC_NEXT = 100,
|
||||
IDC_BACK,
|
||||
IDC_RESTART
|
||||
};
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
#define MAX_LAYER 6
|
||||
|
||||
CCLayer* nextEffectAdvanceAction();
|
||||
|
@ -293,12 +293,12 @@ CCLayer* restartEffectAdvanceAction()
|
|||
pLayer->autorelease();
|
||||
|
||||
return pLayer;
|
||||
}
|
||||
|
||||
|
||||
void EffectAdvanceTextLayer::onEnter(void)
|
||||
{
|
||||
CCLayer::onEnter();
|
||||
}
|
||||
|
||||
|
||||
void EffectAdvanceTextLayer::onEnter(void)
|
||||
{
|
||||
CCLayer::onEnter();
|
||||
float x,y;
|
||||
|
||||
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
||||
|
@ -329,13 +329,13 @@ void EffectAdvanceTextLayer::onEnter(void)
|
|||
addChild(label);
|
||||
label->setTag( kTagLabel );
|
||||
|
||||
std::string strSubtitle = subtitle();
|
||||
if( ! strSubtitle.empty() )
|
||||
{
|
||||
CCLabelTTF* l = CCLabelTTF::labelWithString(strSubtitle.c_str(), "Thonburi", 16);
|
||||
addChild(l, 101);
|
||||
l->setPosition( ccp(size.width/2, size.height-80) );
|
||||
}
|
||||
std::string strSubtitle = subtitle();
|
||||
if( ! strSubtitle.empty() )
|
||||
{
|
||||
CCLabelTTF* l = CCLabelTTF::labelWithString(strSubtitle.c_str(), "Thonburi", 16);
|
||||
addChild(l, 101);
|
||||
l->setPosition( ccp(size.width/2, size.height-80) );
|
||||
}
|
||||
|
||||
CCMenuItemImage *item1 = CCMenuItemImage::itemWithNormalImage("Images/b1.png", "Images/b2.png", this, menu_selector(EffectAdvanceTextLayer::backCallback) );
|
||||
CCMenuItemImage *item2 = CCMenuItemImage::itemWithNormalImage("Images/r1.png","Images/r2.png", this, menu_selector(EffectAdvanceTextLayer::restartCallback) );
|
||||
|
@ -349,12 +349,12 @@ void EffectAdvanceTextLayer::onEnter(void)
|
|||
item3->setPosition( ccp( size.width/2 + 100,30) );
|
||||
|
||||
addChild(menu, 1);
|
||||
}
|
||||
|
||||
EffectAdvanceTextLayer::~EffectAdvanceTextLayer(void)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EffectAdvanceTextLayer::~EffectAdvanceTextLayer(void)
|
||||
{
|
||||
}
|
||||
|
||||
std::string EffectAdvanceTextLayer::title()
|
||||
{
|
||||
return "No title";
|
||||
|
@ -389,12 +389,12 @@ void EffectAdvanceTextLayer::backCallback(CCObject* pSender)
|
|||
s->addChild( backEffectAdvanceAction() );
|
||||
CCDirector::sharedDirector()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void EffectAdvanceScene::runThisTest()
|
||||
{
|
||||
CCLayer* pLayer = nextEffectAdvanceAction();
|
||||
|
||||
addChild(pLayer);
|
||||
CCDirector::sharedDirector()->replaceScene(this);
|
||||
}
|
||||
}
|
||||
|
||||
void EffectAdvanceScene::runThisTest()
|
||||
{
|
||||
CCLayer* pLayer = nextEffectAdvanceAction();
|
||||
|
||||
addChild(pLayer);
|
||||
CCDirector::sharedDirector()->replaceScene(this);
|
||||
}
|
||||
|
|
|
@ -300,50 +300,50 @@ std::string LayerTestBlend::title()
|
|||
// LayerGradient
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
LayerGradient::LayerGradient()
|
||||
{
|
||||
CCLayerGradient* layer1 = CCLayerGradient::layerWithColor(ccc4(255,0,0,255), ccc4(0,255,0,255), ccp(0.9f, 0.9f));
|
||||
addChild(layer1, 0, kTagLayer);
|
||||
|
||||
setIsTouchEnabled(true);
|
||||
|
||||
CCLabelTTF *label1 = CCLabelTTF::labelWithString("Compressed Interpolation: Enabled", "Marker Felt", 26);
|
||||
CCLabelTTF *label2 = CCLabelTTF::labelWithString("Compressed Interpolation: Disabled", "Marker Felt", 26);
|
||||
CCMenuItemLabel *item1 = CCMenuItemLabel::itemWithLabel(label1);
|
||||
CCMenuItemLabel *item2 = CCMenuItemLabel::itemWithLabel(label2);
|
||||
CCMenuItemToggle *item = CCMenuItemToggle::itemWithTarget(this, menu_selector(LayerGradient::toggleItem), item1, item2, NULL);
|
||||
|
||||
CCMenu *menu = CCMenu::menuWithItems(item, NULL);
|
||||
addChild(menu);
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
menu->setPosition(ccp(s.width / 2, 100));
|
||||
}
|
||||
|
||||
void LayerGradient::toggleItem(CCObject *sender)
|
||||
{
|
||||
CCLayerGradient *gradient = (CCLayerGradient*)getChildByTag(kTagLayer);
|
||||
gradient->setIsCompressedInterpolation(! gradient->getIsCompressedInterpolation());
|
||||
}
|
||||
|
||||
void LayerGradient::ccTouchesMoved(CCSet * touches, CCEvent *event)
|
||||
{
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
LayerGradient::LayerGradient()
|
||||
{
|
||||
CCLayerGradient* layer1 = CCLayerGradient::layerWithColor(ccc4(255,0,0,255), ccc4(0,255,0,255), ccp(0.9f, 0.9f));
|
||||
addChild(layer1, 0, kTagLayer);
|
||||
|
||||
setIsTouchEnabled(true);
|
||||
|
||||
CCLabelTTF *label1 = CCLabelTTF::labelWithString("Compressed Interpolation: Enabled", "Marker Felt", 26);
|
||||
CCLabelTTF *label2 = CCLabelTTF::labelWithString("Compressed Interpolation: Disabled", "Marker Felt", 26);
|
||||
CCMenuItemLabel *item1 = CCMenuItemLabel::itemWithLabel(label1);
|
||||
CCMenuItemLabel *item2 = CCMenuItemLabel::itemWithLabel(label2);
|
||||
CCMenuItemToggle *item = CCMenuItemToggle::itemWithTarget(this, menu_selector(LayerGradient::toggleItem), item1, item2, NULL);
|
||||
|
||||
CCMenu *menu = CCMenu::menuWithItems(item, NULL);
|
||||
addChild(menu);
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
menu->setPosition(ccp(s.width / 2, 100));
|
||||
}
|
||||
|
||||
void LayerGradient::toggleItem(CCObject *sender)
|
||||
{
|
||||
CCLayerGradient *gradient = (CCLayerGradient*)getChildByTag(kTagLayer);
|
||||
gradient->setIsCompressedInterpolation(! gradient->getIsCompressedInterpolation());
|
||||
}
|
||||
|
||||
void LayerGradient::ccTouchesMoved(CCSet * touches, CCEvent *event)
|
||||
{
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
CCSetIterator it = touches->begin();
|
||||
CCTouch* touch = (CCTouch*)(*it);
|
||||
CCPoint start = touch->locationInView();
|
||||
start = CCDirector::sharedDirector()->convertToGL(start);
|
||||
|
||||
CCPoint diff = ccpSub( ccp(s.width/2,s.height/2), start);
|
||||
diff = ccpNormalize(diff);
|
||||
|
||||
CCLayerGradient *gradient = (CCLayerGradient*) getChildByTag(1);
|
||||
gradient->setVector(diff);
|
||||
}
|
||||
|
||||
std::string LayerGradient::title()
|
||||
{
|
||||
return "LayerGradient";
|
||||
CCTouch* touch = (CCTouch*)(*it);
|
||||
CCPoint start = touch->locationInView();
|
||||
start = CCDirector::sharedDirector()->convertToGL(start);
|
||||
|
||||
CCPoint diff = ccpSub( ccp(s.width/2,s.height/2), start);
|
||||
diff = ccpNormalize(diff);
|
||||
|
||||
CCLayerGradient *gradient = (CCLayerGradient*) getChildByTag(1);
|
||||
gradient->setVector(diff);
|
||||
}
|
||||
|
||||
std::string LayerGradient::title()
|
||||
{
|
||||
return "LayerGradient";
|
||||
}
|
||||
|
||||
string LayerGradient::subtitle()
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#include "MotionStreakTest.h"
|
||||
#include "../testResource.h"
|
||||
|
||||
#include "MotionStreakTest.h"
|
||||
#include "../testResource.h"
|
||||
|
||||
CCLayer* nextMotionAction();
|
||||
CCLayer* backMotionAction();
|
||||
CCLayer* restartMotionAction();
|
||||
|
||||
CCLayer* restartMotionAction();
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MotionStreakTest1
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
|
||||
void MotionStreakTest1::onEnter()
|
||||
{
|
||||
MotionStreakTest::onEnter();
|
||||
|
@ -55,23 +55,23 @@ void MotionStreakTest1::onEnter()
|
|||
// weak ref
|
||||
streak = m_streak;
|
||||
}
|
||||
|
||||
void MotionStreakTest1::onUpdate(ccTime delta)
|
||||
{
|
||||
m_streak->setPosition( m_target->convertToWorldSpace(CCPointZero) );
|
||||
}
|
||||
|
||||
|
||||
void MotionStreakTest1::onUpdate(ccTime delta)
|
||||
{
|
||||
m_streak->setPosition( m_target->convertToWorldSpace(CCPointZero) );
|
||||
}
|
||||
|
||||
std::string MotionStreakTest1::title()
|
||||
{
|
||||
return "MotionStreak test 1";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MotionStreakTest2
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
|
||||
void MotionStreakTest2::onEnter()
|
||||
{
|
||||
MotionStreakTest::onEnter();
|
||||
|
@ -89,7 +89,7 @@ void MotionStreakTest2::onEnter()
|
|||
// weak ref
|
||||
streak = m_streak;
|
||||
}
|
||||
|
||||
|
||||
void MotionStreakTest2::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
CCSetIterator it = touches->begin();
|
||||
|
@ -99,28 +99,28 @@ void MotionStreakTest2::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
|||
touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
|
||||
|
||||
m_streak->setPosition( touchLocation );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string MotionStreakTest2::title()
|
||||
{
|
||||
return "MotionStreak test";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MotionStreakTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
// enum
|
||||
// {
|
||||
// IDC_NEXT = 100,
|
||||
// IDC_BACK,
|
||||
// IDC_RESTART
|
||||
// };
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
|
||||
// enum
|
||||
// {
|
||||
// IDC_NEXT = 100,
|
||||
// IDC_BACK,
|
||||
// IDC_RESTART
|
||||
// };
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
#define MAX_LAYER 2
|
||||
|
||||
CCLayer* createMotionLayer(int nIndex)
|
||||
|
@ -164,17 +164,17 @@ CCLayer* restartMotionAction()
|
|||
pLayer->autorelease();
|
||||
|
||||
return pLayer;
|
||||
}
|
||||
|
||||
|
||||
MotionStreakTest::MotionStreakTest(void)
|
||||
{
|
||||
}
|
||||
|
||||
MotionStreakTest::~MotionStreakTest(void)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
MotionStreakTest::MotionStreakTest(void)
|
||||
{
|
||||
}
|
||||
|
||||
MotionStreakTest::~MotionStreakTest(void)
|
||||
{
|
||||
}
|
||||
|
||||
std::string MotionStreakTest::title()
|
||||
{
|
||||
return "No title";
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +1,9 @@
|
|||
#include "CCConfiguration.h"
|
||||
#include "RenderTextureTest.h"
|
||||
|
||||
// Test #1 by Jason Booth (slipster216)
|
||||
// Test #3 by David Deaco (ddeaco)
|
||||
|
||||
#include "CCConfiguration.h"
|
||||
#include "RenderTextureTest.h"
|
||||
|
||||
// Test #1 by Jason Booth (slipster216)
|
||||
// Test #3 by David Deaco (ddeaco)
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
#define MAX_LAYER 4
|
||||
|
@ -52,8 +52,8 @@ CCLayer* restartTestCase()
|
|||
pLayer->autorelease();
|
||||
|
||||
return pLayer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RenderTextureTestDemo::onEnter()
|
||||
{
|
||||
CCLayer::onEnter();
|
||||
|
@ -83,8 +83,8 @@ void RenderTextureTestDemo::onEnter()
|
|||
item3->setPosition( ccp( s.width/2 + 100,30) );
|
||||
|
||||
addChild(menu, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RenderTextureTestDemo::restartCallback(CCObject* pSender)
|
||||
{
|
||||
CCScene* s = new RenderTextureScene();
|
||||
|
@ -108,20 +108,20 @@ void RenderTextureTestDemo::backCallback(CCObject* pSender)
|
|||
s->addChild( backTestCase() );
|
||||
CCDirector::sharedDirector()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string RenderTextureTestDemo::title()
|
||||
{
|
||||
return "Render Texture Test";
|
||||
}
|
||||
|
||||
std::string RenderTextureTestDemo::subtitle()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
RenderTextureTest::RenderTextureTest()
|
||||
: m_brush(NULL)
|
||||
std::string RenderTextureTestDemo::subtitle()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
RenderTextureTest::RenderTextureTest()
|
||||
: m_brush(NULL)
|
||||
{
|
||||
if (CCConfiguration::sharedConfiguration()->getGlesVersion() < GLES_VER_2_0)
|
||||
{
|
||||
|
@ -134,10 +134,10 @@ RenderTextureTest::RenderTextureTest()
|
|||
// create a render texture, this is what we're going to draw into
|
||||
m_target = CCRenderTexture::renderTextureWithWidthAndHeight(s.width, s.height);
|
||||
|
||||
if (NULL == m_target)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (NULL == m_target)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_target->setPosition(ccp(s.width/2, s.height/2));
|
||||
|
||||
|
@ -152,20 +152,20 @@ RenderTextureTest::RenderTextureTest()
|
|||
ccBlendFunc bf = { GL_ONE, GL_ONE_MINUS_SRC_ALPHA };
|
||||
m_brush->setBlendFunc( bf);
|
||||
m_brush->setOpacity(20);
|
||||
setIsTouchEnabled(true);
|
||||
}
|
||||
|
||||
RenderTextureTest::~RenderTextureTest()
|
||||
{
|
||||
if (NULL != m_brush)
|
||||
{
|
||||
m_brush->release();
|
||||
m_brush = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTextureTest::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
setIsTouchEnabled(true);
|
||||
}
|
||||
|
||||
RenderTextureTest::~RenderTextureTest()
|
||||
{
|
||||
if (NULL != m_brush)
|
||||
{
|
||||
m_brush->release();
|
||||
m_brush = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTextureTest::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
CCSetIterator it = touches->begin();
|
||||
CCTouch* touch = (CCTouch*)(*it);
|
||||
CCPoint start = touch->locationInView();
|
||||
|
@ -197,12 +197,12 @@ void RenderTextureTest::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
|||
}
|
||||
// finish drawing and return context back to the screen
|
||||
m_target->end(false);
|
||||
}
|
||||
|
||||
void RenderTextureTest::ccTouchesEnded(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||
|
||||
}
|
||||
|
||||
void RenderTextureTest::ccTouchesEnded(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||
|
||||
CCSetIterator it;
|
||||
CCTouch* touch;
|
||||
|
||||
|
@ -219,357 +219,357 @@ void RenderTextureTest::ccTouchesEnded(CCSet* touches, CCEvent* event)
|
|||
|
||||
m_brush->setPosition(location);
|
||||
m_brush->setRotation( rand()%360 );
|
||||
}
|
||||
|
||||
m_target->begin();
|
||||
m_brush->visit();
|
||||
m_target->end(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Impelmentation of RenderTextureSave
|
||||
*/
|
||||
RenderTextureSave::RenderTextureSave()
|
||||
{
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
// create a render texture, this is what we are going to draw into
|
||||
m_pTarget = CCRenderTexture::renderTextureWithWidthAndHeight(s.width, s.height, kCCTexture2DPixelFormat_RGBA8888);
|
||||
m_pTarget->retain();
|
||||
m_pTarget->setPosition(ccp(s.width / 2, s.height / 2));
|
||||
|
||||
}
|
||||
|
||||
m_target->begin();
|
||||
m_brush->visit();
|
||||
m_target->end(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Impelmentation of RenderTextureSave
|
||||
*/
|
||||
RenderTextureSave::RenderTextureSave()
|
||||
{
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
// create a render texture, this is what we are going to draw into
|
||||
m_pTarget = CCRenderTexture::renderTextureWithWidthAndHeight(s.width, s.height, kCCTexture2DPixelFormat_RGBA8888);
|
||||
m_pTarget->retain();
|
||||
m_pTarget->setPosition(ccp(s.width / 2, s.height / 2));
|
||||
|
||||
// note that the render texture is a CCNode, and contains a sprite of its texture for convience,
|
||||
// so we can just parent it to the scene like any other CCNode
|
||||
this->addChild(m_pTarget, -1);
|
||||
|
||||
// create a brush image to draw into the texture with
|
||||
m_pBrush = CCSprite::spriteWithFile("Images/fire.png");
|
||||
m_pBrush->retain();
|
||||
m_pBrush->setColor(ccRED);
|
||||
m_pBrush->setOpacity(20);
|
||||
this->setIsTouchEnabled(true);
|
||||
|
||||
// Save Image menu
|
||||
CCMenuItemFont::setFontSize(16);
|
||||
CCMenuItem *item1 = CCMenuItemFont::itemWithString("Save Image", this, menu_selector(RenderTextureSave::saveImage));
|
||||
CCMenuItem *item2 = CCMenuItemFont::itemWithString("Clear", this, menu_selector(RenderTextureSave::clearImage));
|
||||
CCMenu *menu = CCMenu::menuWithItems(item1, item2, NULL);
|
||||
this->addChild(menu);
|
||||
menu->alignItemsVertically();
|
||||
menu->setPosition(ccp(s.width - 80, s.height - 30));
|
||||
}
|
||||
|
||||
string RenderTextureSave::title()
|
||||
{
|
||||
return "Touch the screen";
|
||||
}
|
||||
|
||||
string RenderTextureSave::subtitle()
|
||||
{
|
||||
return "Press 'Save Image' to create an snapshot of the render texture";
|
||||
}
|
||||
|
||||
void RenderTextureSave::clearImage(cocos2d::CCObject *pSender)
|
||||
{
|
||||
m_pTarget->clear(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1());
|
||||
}
|
||||
|
||||
void RenderTextureSave::saveImage(cocos2d::CCObject *pSender)
|
||||
{
|
||||
static int counter = 0;
|
||||
|
||||
char png[20];
|
||||
sprintf(png, "image-%d.png", counter);
|
||||
char jpg[20];
|
||||
sprintf(jpg, "image-%d.jpg", counter);
|
||||
|
||||
m_pTarget->saveToFile(png, kCCImageFormatPNG);
|
||||
m_pTarget->saveToFile(jpg, kCCImageFormatJPEG);
|
||||
|
||||
|
||||
CCImage *pImage = m_pTarget->newCCImage();
|
||||
|
||||
CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addUIImage(pImage, png);
|
||||
|
||||
CC_SAFE_DELETE(pImage);
|
||||
|
||||
CCSprite *sprite = CCSprite::spriteWithTexture(tex);
|
||||
|
||||
sprite->setScale(0.3f);
|
||||
addChild(sprite);
|
||||
sprite->setPosition(ccp(40, 40));
|
||||
sprite->setRotation(counter * 3);
|
||||
|
||||
CCLOG("Image saved %s and %s", png, jpg);
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
RenderTextureSave::~RenderTextureSave()
|
||||
{
|
||||
m_pBrush->release();
|
||||
m_pTarget->release();
|
||||
CCTextureCache::sharedTextureCache()->removeUnusedTextures();
|
||||
}
|
||||
|
||||
void RenderTextureSave::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
CCTouch *touch = (CCTouch *)touches->anyObject();
|
||||
CCPoint start = touch->locationInView();
|
||||
start = CCDirector::sharedDirector()->convertToGL(start);
|
||||
CCPoint end = touch->previousLocationInView();
|
||||
|
||||
// begin drawing to the render texture
|
||||
m_pTarget->begin();
|
||||
|
||||
// so we can just parent it to the scene like any other CCNode
|
||||
this->addChild(m_pTarget, -1);
|
||||
|
||||
// create a brush image to draw into the texture with
|
||||
m_pBrush = CCSprite::spriteWithFile("Images/fire.png");
|
||||
m_pBrush->retain();
|
||||
m_pBrush->setColor(ccRED);
|
||||
m_pBrush->setOpacity(20);
|
||||
this->setIsTouchEnabled(true);
|
||||
|
||||
// Save Image menu
|
||||
CCMenuItemFont::setFontSize(16);
|
||||
CCMenuItem *item1 = CCMenuItemFont::itemWithString("Save Image", this, menu_selector(RenderTextureSave::saveImage));
|
||||
CCMenuItem *item2 = CCMenuItemFont::itemWithString("Clear", this, menu_selector(RenderTextureSave::clearImage));
|
||||
CCMenu *menu = CCMenu::menuWithItems(item1, item2, NULL);
|
||||
this->addChild(menu);
|
||||
menu->alignItemsVertically();
|
||||
menu->setPosition(ccp(s.width - 80, s.height - 30));
|
||||
}
|
||||
|
||||
string RenderTextureSave::title()
|
||||
{
|
||||
return "Touch the screen";
|
||||
}
|
||||
|
||||
string RenderTextureSave::subtitle()
|
||||
{
|
||||
return "Press 'Save Image' to create an snapshot of the render texture";
|
||||
}
|
||||
|
||||
void RenderTextureSave::clearImage(cocos2d::CCObject *pSender)
|
||||
{
|
||||
m_pTarget->clear(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1());
|
||||
}
|
||||
|
||||
void RenderTextureSave::saveImage(cocos2d::CCObject *pSender)
|
||||
{
|
||||
static int counter = 0;
|
||||
|
||||
char png[20];
|
||||
sprintf(png, "image-%d.png", counter);
|
||||
char jpg[20];
|
||||
sprintf(jpg, "image-%d.jpg", counter);
|
||||
|
||||
m_pTarget->saveToFile(png, kCCImageFormatPNG);
|
||||
m_pTarget->saveToFile(jpg, kCCImageFormatJPEG);
|
||||
|
||||
|
||||
CCImage *pImage = m_pTarget->newCCImage();
|
||||
|
||||
CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addUIImage(pImage, png);
|
||||
|
||||
CC_SAFE_DELETE(pImage);
|
||||
|
||||
CCSprite *sprite = CCSprite::spriteWithTexture(tex);
|
||||
|
||||
sprite->setScale(0.3f);
|
||||
addChild(sprite);
|
||||
sprite->setPosition(ccp(40, 40));
|
||||
sprite->setRotation(counter * 3);
|
||||
|
||||
CCLOG("Image saved %s and %s", png, jpg);
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
RenderTextureSave::~RenderTextureSave()
|
||||
{
|
||||
m_pBrush->release();
|
||||
m_pTarget->release();
|
||||
CCTextureCache::sharedTextureCache()->removeUnusedTextures();
|
||||
}
|
||||
|
||||
void RenderTextureSave::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
CCTouch *touch = (CCTouch *)touches->anyObject();
|
||||
CCPoint start = touch->locationInView();
|
||||
start = CCDirector::sharedDirector()->convertToGL(start);
|
||||
CCPoint end = touch->previousLocationInView();
|
||||
|
||||
// begin drawing to the render texture
|
||||
m_pTarget->begin();
|
||||
|
||||
// for extra points, we'll draw this smoothly from the last position and vary the sprite's
|
||||
// scale/rotation/offset
|
||||
float distance = ccpDistance(start, end);
|
||||
if (distance > 1)
|
||||
{
|
||||
int d = (int)distance;
|
||||
for (int i = 0; i < d; i++)
|
||||
{
|
||||
float difx = end.x - start.x;
|
||||
float dify = end.y - start.y;
|
||||
float delta = (float)i / distance;
|
||||
m_pBrush->setPosition(ccp(start.x + (difx * delta), start.y + (dify * delta)));
|
||||
m_pBrush->setRotation(rand() % 360);
|
||||
float r = (float)(rand() % 50 / 50.f) + 0.25f;
|
||||
m_pBrush->setScale(r);
|
||||
/*m_pBrush->setColor(ccc3(CCRANDOM_0_1() * 127 + 128, 255, 255));*/
|
||||
// Use CCRANDOM_0_1() will cause error when loading libtests.so on android, I don't know why.
|
||||
m_pBrush->setColor(ccc3(rand() % 127 + 128, 255, 255));
|
||||
// Call visit to draw the brush, don't call draw..
|
||||
m_pBrush->visit();
|
||||
}
|
||||
}
|
||||
|
||||
// finish drawing and return context back to the screen
|
||||
m_pTarget->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Impelmentation of RenderTextureIssue937
|
||||
*/
|
||||
|
||||
RenderTextureIssue937::RenderTextureIssue937()
|
||||
{
|
||||
/*
|
||||
* 1 2
|
||||
* A: A1 A2
|
||||
*
|
||||
* B: B1 B2
|
||||
*
|
||||
* A1: premulti sprite
|
||||
* A2: premulti render
|
||||
*
|
||||
* B1: non-premulti sprite
|
||||
* B2: non-premulti render
|
||||
*/
|
||||
CCLayerColor *background = CCLayerColor::layerWithColor(ccc4(200,200,200,255));
|
||||
addChild(background);
|
||||
|
||||
CCSprite *spr_premulti = CCSprite::spriteWithFile("Images/fire.png");
|
||||
spr_premulti->setPosition(ccp(16,48));
|
||||
|
||||
CCSprite *spr_nonpremulti = CCSprite::spriteWithFile("Images/fire.png");
|
||||
spr_nonpremulti->setPosition(ccp(16,16));
|
||||
|
||||
|
||||
/* A2 & B2 setup */
|
||||
CCRenderTexture *rend = CCRenderTexture::renderTextureWithWidthAndHeight(32, 64, kCCTexture2DPixelFormat_RGBA4444);
|
||||
|
||||
if (NULL == rend)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// It's possible to modify the RenderTexture blending function by
|
||||
// [[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
||||
|
||||
rend->begin();
|
||||
spr_premulti->visit();
|
||||
spr_nonpremulti->visit();
|
||||
rend->end();
|
||||
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
/* A1: setup */
|
||||
spr_premulti->setPosition(ccp(s.width/2-16, s.height/2+16));
|
||||
/* B1: setup */
|
||||
spr_nonpremulti->setPosition(ccp(s.width/2-16, s.height/2-16));
|
||||
|
||||
rend->setPosition(ccp(s.width/2+16, s.height/2));
|
||||
|
||||
addChild(spr_nonpremulti);
|
||||
addChild(spr_premulti);
|
||||
addChild(rend);
|
||||
}
|
||||
|
||||
std::string RenderTextureIssue937::title()
|
||||
{
|
||||
return "Testing issue #937";
|
||||
}
|
||||
|
||||
std::string RenderTextureIssue937::subtitle()
|
||||
{
|
||||
return "All images should be equal...";
|
||||
}
|
||||
|
||||
void RenderTextureScene::runThisTest()
|
||||
{
|
||||
CCLayer* pLayer = nextTestCase();
|
||||
addChild(pLayer);
|
||||
|
||||
CCDirector::sharedDirector()->replaceScene(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Impelmentation of RenderTextureZbuffer
|
||||
*/
|
||||
|
||||
RenderTextureZbuffer::RenderTextureZbuffer()
|
||||
{
|
||||
this->setIsTouchEnabled(true);
|
||||
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
||||
CCLabelTTF *label = CCLabelTTF::labelWithString("vertexZ = 50", "Marker Felt", 64);
|
||||
label->setPosition(ccp(size.width / 2, size.height * 0.25f));
|
||||
this->addChild(label);
|
||||
|
||||
CCLabelTTF *label2 = CCLabelTTF::labelWithString("vertexZ = 0", "Marker Felt", 64);
|
||||
label2->setPosition(ccp(size.width / 2, size.height * 0.5f));
|
||||
this->addChild(label2);
|
||||
|
||||
CCLabelTTF *label3 = CCLabelTTF::labelWithString("vertexZ = -50", "Marker Felt", 64);
|
||||
label3->setPosition(ccp(size.width / 2, size.height * 0.75f));
|
||||
this->addChild(label3);
|
||||
|
||||
label->setVertexZ(50);
|
||||
label2->setVertexZ(0);
|
||||
label3->setVertexZ(-50);
|
||||
|
||||
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Images/bugs/circle.plist");
|
||||
mgr = CCSpriteBatchNode::batchNodeWithFile("Images/bugs/circle.png", 9);
|
||||
this->addChild(mgr);
|
||||
sp1 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp2 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp3 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp4 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp5 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp6 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp7 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp8 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp9 = CCSprite::spriteWithSpriteFrameName("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->setVertexZ(400);
|
||||
sp2->setVertexZ(300);
|
||||
sp3->setVertexZ(200);
|
||||
sp4->setVertexZ(100);
|
||||
sp5->setVertexZ(0);
|
||||
sp6->setVertexZ(-100);
|
||||
sp7->setVertexZ(-200);
|
||||
sp8->setVertexZ(-300);
|
||||
sp9->setVertexZ(-400);
|
||||
|
||||
sp9->setScale(2);
|
||||
sp9->setColor(ccYELLOW);
|
||||
}
|
||||
|
||||
string RenderTextureZbuffer::title()
|
||||
{
|
||||
return "Testing Z Buffer in Render Texture";
|
||||
}
|
||||
|
||||
string RenderTextureZbuffer::subtitle()
|
||||
{
|
||||
return "Touch screen. It should be green";
|
||||
}
|
||||
|
||||
void RenderTextureZbuffer::ccTouchesBegan(cocos2d::CCSet *touches, cocos2d::CCEvent *event)
|
||||
{
|
||||
CCSetIterator iter;
|
||||
CCTouch *touch;
|
||||
for (iter = touches->begin(); iter != touches->end(); ++iter)
|
||||
{
|
||||
touch = (CCTouch *)(*iter);
|
||||
CCPoint location = touch->locationInView();
|
||||
|
||||
location = CCDirector::sharedDirector()->convertToGL(location);
|
||||
sp1->setPosition(location);
|
||||
sp2->setPosition(location);
|
||||
sp3->setPosition(location);
|
||||
sp4->setPosition(location);
|
||||
sp5->setPosition(location);
|
||||
sp6->setPosition(location);
|
||||
sp7->setPosition(location);
|
||||
sp8->setPosition(location);
|
||||
sp9->setPosition(location);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTextureZbuffer::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
CCSetIterator iter;
|
||||
CCTouch *touch;
|
||||
for (iter = touches->begin(); iter != touches->end(); ++iter)
|
||||
{
|
||||
touch = (CCTouch *)(*iter);
|
||||
CCPoint location = touch->locationInView();
|
||||
|
||||
location = CCDirector::sharedDirector()->convertToGL(location);
|
||||
sp1->setPosition(location);
|
||||
sp2->setPosition(location);
|
||||
sp3->setPosition(location);
|
||||
sp4->setPosition(location);
|
||||
sp5->setPosition(location);
|
||||
sp6->setPosition(location);
|
||||
sp7->setPosition(location);
|
||||
sp8->setPosition(location);
|
||||
sp9->setPosition(location);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTextureZbuffer::ccTouchesEnded(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
this->renderScreenShot();
|
||||
}
|
||||
|
||||
void RenderTextureZbuffer::renderScreenShot()
|
||||
{
|
||||
CCRenderTexture *texture = CCRenderTexture::renderTextureWithWidthAndHeight(512, 512);
|
||||
if (NULL == texture)
|
||||
{
|
||||
return;
|
||||
}
|
||||
texture->setAnchorPoint(ccp(0, 0));
|
||||
texture->begin();
|
||||
|
||||
this->visit();
|
||||
|
||||
texture->end();
|
||||
|
||||
CCSprite *sprite = CCSprite::spriteWithTexture(texture->getSprite()->getTexture());
|
||||
|
||||
sprite->setPosition(ccp(256, 256));
|
||||
sprite->setOpacity(182);
|
||||
sprite->setFlipY(1);
|
||||
this->addChild(sprite, 999999);
|
||||
sprite->setColor(ccGREEN);
|
||||
|
||||
sprite->runAction(CCSequence::actions(CCFadeTo::actionWithDuration(2, 0),
|
||||
CCHide::action(),
|
||||
NULL));
|
||||
}
|
||||
|
||||
// scale/rotation/offset
|
||||
float distance = ccpDistance(start, end);
|
||||
if (distance > 1)
|
||||
{
|
||||
int d = (int)distance;
|
||||
for (int i = 0; i < d; i++)
|
||||
{
|
||||
float difx = end.x - start.x;
|
||||
float dify = end.y - start.y;
|
||||
float delta = (float)i / distance;
|
||||
m_pBrush->setPosition(ccp(start.x + (difx * delta), start.y + (dify * delta)));
|
||||
m_pBrush->setRotation(rand() % 360);
|
||||
float r = (float)(rand() % 50 / 50.f) + 0.25f;
|
||||
m_pBrush->setScale(r);
|
||||
/*m_pBrush->setColor(ccc3(CCRANDOM_0_1() * 127 + 128, 255, 255));*/
|
||||
// Use CCRANDOM_0_1() will cause error when loading libtests.so on android, I don't know why.
|
||||
m_pBrush->setColor(ccc3(rand() % 127 + 128, 255, 255));
|
||||
// Call visit to draw the brush, don't call draw..
|
||||
m_pBrush->visit();
|
||||
}
|
||||
}
|
||||
|
||||
// finish drawing and return context back to the screen
|
||||
m_pTarget->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Impelmentation of RenderTextureIssue937
|
||||
*/
|
||||
|
||||
RenderTextureIssue937::RenderTextureIssue937()
|
||||
{
|
||||
/*
|
||||
* 1 2
|
||||
* A: A1 A2
|
||||
*
|
||||
* B: B1 B2
|
||||
*
|
||||
* A1: premulti sprite
|
||||
* A2: premulti render
|
||||
*
|
||||
* B1: non-premulti sprite
|
||||
* B2: non-premulti render
|
||||
*/
|
||||
CCLayerColor *background = CCLayerColor::layerWithColor(ccc4(200,200,200,255));
|
||||
addChild(background);
|
||||
|
||||
CCSprite *spr_premulti = CCSprite::spriteWithFile("Images/fire.png");
|
||||
spr_premulti->setPosition(ccp(16,48));
|
||||
|
||||
CCSprite *spr_nonpremulti = CCSprite::spriteWithFile("Images/fire.png");
|
||||
spr_nonpremulti->setPosition(ccp(16,16));
|
||||
|
||||
|
||||
/* A2 & B2 setup */
|
||||
CCRenderTexture *rend = CCRenderTexture::renderTextureWithWidthAndHeight(32, 64, kCCTexture2DPixelFormat_RGBA4444);
|
||||
|
||||
if (NULL == rend)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// It's possible to modify the RenderTexture blending function by
|
||||
// [[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
||||
|
||||
rend->begin();
|
||||
spr_premulti->visit();
|
||||
spr_nonpremulti->visit();
|
||||
rend->end();
|
||||
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
/* A1: setup */
|
||||
spr_premulti->setPosition(ccp(s.width/2-16, s.height/2+16));
|
||||
/* B1: setup */
|
||||
spr_nonpremulti->setPosition(ccp(s.width/2-16, s.height/2-16));
|
||||
|
||||
rend->setPosition(ccp(s.width/2+16, s.height/2));
|
||||
|
||||
addChild(spr_nonpremulti);
|
||||
addChild(spr_premulti);
|
||||
addChild(rend);
|
||||
}
|
||||
|
||||
std::string RenderTextureIssue937::title()
|
||||
{
|
||||
return "Testing issue #937";
|
||||
}
|
||||
|
||||
std::string RenderTextureIssue937::subtitle()
|
||||
{
|
||||
return "All images should be equal...";
|
||||
}
|
||||
|
||||
void RenderTextureScene::runThisTest()
|
||||
{
|
||||
CCLayer* pLayer = nextTestCase();
|
||||
addChild(pLayer);
|
||||
|
||||
CCDirector::sharedDirector()->replaceScene(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Impelmentation of RenderTextureZbuffer
|
||||
*/
|
||||
|
||||
RenderTextureZbuffer::RenderTextureZbuffer()
|
||||
{
|
||||
this->setIsTouchEnabled(true);
|
||||
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
||||
CCLabelTTF *label = CCLabelTTF::labelWithString("vertexZ = 50", "Marker Felt", 64);
|
||||
label->setPosition(ccp(size.width / 2, size.height * 0.25f));
|
||||
this->addChild(label);
|
||||
|
||||
CCLabelTTF *label2 = CCLabelTTF::labelWithString("vertexZ = 0", "Marker Felt", 64);
|
||||
label2->setPosition(ccp(size.width / 2, size.height * 0.5f));
|
||||
this->addChild(label2);
|
||||
|
||||
CCLabelTTF *label3 = CCLabelTTF::labelWithString("vertexZ = -50", "Marker Felt", 64);
|
||||
label3->setPosition(ccp(size.width / 2, size.height * 0.75f));
|
||||
this->addChild(label3);
|
||||
|
||||
label->setVertexZ(50);
|
||||
label2->setVertexZ(0);
|
||||
label3->setVertexZ(-50);
|
||||
|
||||
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Images/bugs/circle.plist");
|
||||
mgr = CCSpriteBatchNode::batchNodeWithFile("Images/bugs/circle.png", 9);
|
||||
this->addChild(mgr);
|
||||
sp1 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp2 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp3 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp4 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp5 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp6 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp7 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp8 = CCSprite::spriteWithSpriteFrameName("circle.png");
|
||||
sp9 = CCSprite::spriteWithSpriteFrameName("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->setVertexZ(400);
|
||||
sp2->setVertexZ(300);
|
||||
sp3->setVertexZ(200);
|
||||
sp4->setVertexZ(100);
|
||||
sp5->setVertexZ(0);
|
||||
sp6->setVertexZ(-100);
|
||||
sp7->setVertexZ(-200);
|
||||
sp8->setVertexZ(-300);
|
||||
sp9->setVertexZ(-400);
|
||||
|
||||
sp9->setScale(2);
|
||||
sp9->setColor(ccYELLOW);
|
||||
}
|
||||
|
||||
string RenderTextureZbuffer::title()
|
||||
{
|
||||
return "Testing Z Buffer in Render Texture";
|
||||
}
|
||||
|
||||
string RenderTextureZbuffer::subtitle()
|
||||
{
|
||||
return "Touch screen. It should be green";
|
||||
}
|
||||
|
||||
void RenderTextureZbuffer::ccTouchesBegan(cocos2d::CCSet *touches, cocos2d::CCEvent *event)
|
||||
{
|
||||
CCSetIterator iter;
|
||||
CCTouch *touch;
|
||||
for (iter = touches->begin(); iter != touches->end(); ++iter)
|
||||
{
|
||||
touch = (CCTouch *)(*iter);
|
||||
CCPoint location = touch->locationInView();
|
||||
|
||||
location = CCDirector::sharedDirector()->convertToGL(location);
|
||||
sp1->setPosition(location);
|
||||
sp2->setPosition(location);
|
||||
sp3->setPosition(location);
|
||||
sp4->setPosition(location);
|
||||
sp5->setPosition(location);
|
||||
sp6->setPosition(location);
|
||||
sp7->setPosition(location);
|
||||
sp8->setPosition(location);
|
||||
sp9->setPosition(location);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTextureZbuffer::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
CCSetIterator iter;
|
||||
CCTouch *touch;
|
||||
for (iter = touches->begin(); iter != touches->end(); ++iter)
|
||||
{
|
||||
touch = (CCTouch *)(*iter);
|
||||
CCPoint location = touch->locationInView();
|
||||
|
||||
location = CCDirector::sharedDirector()->convertToGL(location);
|
||||
sp1->setPosition(location);
|
||||
sp2->setPosition(location);
|
||||
sp3->setPosition(location);
|
||||
sp4->setPosition(location);
|
||||
sp5->setPosition(location);
|
||||
sp6->setPosition(location);
|
||||
sp7->setPosition(location);
|
||||
sp8->setPosition(location);
|
||||
sp9->setPosition(location);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTextureZbuffer::ccTouchesEnded(CCSet* touches, CCEvent* event)
|
||||
{
|
||||
this->renderScreenShot();
|
||||
}
|
||||
|
||||
void RenderTextureZbuffer::renderScreenShot()
|
||||
{
|
||||
CCRenderTexture *texture = CCRenderTexture::renderTextureWithWidthAndHeight(512, 512);
|
||||
if (NULL == texture)
|
||||
{
|
||||
return;
|
||||
}
|
||||
texture->setAnchorPoint(ccp(0, 0));
|
||||
texture->begin();
|
||||
|
||||
this->visit();
|
||||
|
||||
texture->end();
|
||||
|
||||
CCSprite *sprite = CCSprite::spriteWithTexture(texture->getSprite()->getTexture());
|
||||
|
||||
sprite->setPosition(ccp(256, 256));
|
||||
sprite->setOpacity(182);
|
||||
sprite->setFlipY(1);
|
||||
this->addChild(sprite, 999999);
|
||||
sprite->setColor(ccGREEN);
|
||||
|
||||
sprite->runAction(CCSequence::actions(CCFadeTo::actionWithDuration(2, 0),
|
||||
CCHide::action(),
|
||||
NULL));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "RotateWorldTest.h"
|
||||
#include "../testResource.h"
|
||||
|
||||
#include "RotateWorldTest.h"
|
||||
#include "../testResource.h"
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// TestLayer
|
||||
|
@ -73,13 +73,13 @@ void SpriteLayer::onEnter()
|
|||
spriteSister1->runAction(CCRepeat::actionWithAction( CCSequence::actions(rot1, rot2, NULL), 5 ));
|
||||
spriteSister2->runAction(CCRepeat::actionWithAction( CCSequence::actions((CCFiniteTimeAction *)(rot2->copy()->autorelease()), (CCFiniteTimeAction *)(rot1->copy()->autorelease()), NULL), 5 ));
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// RotateWorldMainLayer
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
|
||||
void RotateWorldMainLayer::onEnter()
|
||||
{
|
||||
CCLayer::onEnter();
|
||||
|
|
|
@ -963,7 +963,7 @@ void TMXIsoVertexZ::repositionSprite(ccTime dt)
|
|||
// tile height is 64x32
|
||||
// map size: 30x30
|
||||
CCPoint p = m_tamara->getPosition();
|
||||
p = CC_POINT_POINTS_TO_PIXELS(p);
|
||||
p = CC_POINT_POINTS_TO_PIXELS(p);
|
||||
float newZ = -(p.y+32) /16;
|
||||
m_tamara->setVertexZ( newZ );
|
||||
}
|
||||
|
@ -1119,158 +1119,158 @@ std::string TMXOrthoMoveLayer::subtitle()
|
|||
// TMXTilePropertyTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
TMXTilePropertyTest::TMXTilePropertyTest()
|
||||
{
|
||||
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/ortho-tile-property.tmx");
|
||||
addChild(map ,0 ,kTagTileMap);
|
||||
|
||||
for(int i=1;i<=20;i++){
|
||||
CCLog("GID:%i, Properties:%p", i, map->propertiesForGID(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TMXTilePropertyTest::TMXTilePropertyTest()
|
||||
{
|
||||
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/ortho-tile-property.tmx");
|
||||
addChild(map ,0 ,kTagTileMap);
|
||||
|
||||
for(int i=1;i<=20;i++){
|
||||
CCLog("GID:%i, Properties:%p", i, map->propertiesForGID(i));
|
||||
}
|
||||
}
|
||||
|
||||
std::string TMXTilePropertyTest::title()
|
||||
{
|
||||
return "TMX Tile Property Test";
|
||||
}
|
||||
|
||||
std::string TMXTilePropertyTest::subtitle()
|
||||
{
|
||||
return "In the console you should see tile properties";
|
||||
}
|
||||
|
||||
{
|
||||
return "TMX Tile Property Test";
|
||||
}
|
||||
|
||||
std::string TMXTilePropertyTest::subtitle()
|
||||
{
|
||||
return "In the console you should see tile properties";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// TMXOrthoFlipTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
TMXOrthoFlipTest::TMXOrthoFlipTest()
|
||||
{
|
||||
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/ortho-rotation-test.tmx");
|
||||
addChild(map, 0, kTagTileMap);
|
||||
|
||||
CCSize s = map->getContentSize();
|
||||
CCLog("ContentSize: %f, %f", s.width,s.height);
|
||||
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(map->getChildren(), pObj)
|
||||
{
|
||||
CCSpriteBatchNode* child = (CCSpriteBatchNode*)pObj;
|
||||
child->getTexture()->setAntiAliasTexParameters();
|
||||
}
|
||||
|
||||
CCScaleBy* action = CCScaleBy::actionWithDuration(2, 0.5f);
|
||||
map->runAction(action);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
TMXOrthoFlipTest::TMXOrthoFlipTest()
|
||||
{
|
||||
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/ortho-rotation-test.tmx");
|
||||
addChild(map, 0, kTagTileMap);
|
||||
|
||||
CCSize s = map->getContentSize();
|
||||
CCLog("ContentSize: %f, %f", s.width,s.height);
|
||||
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(map->getChildren(), pObj)
|
||||
{
|
||||
CCSpriteBatchNode* child = (CCSpriteBatchNode*)pObj;
|
||||
child->getTexture()->setAntiAliasTexParameters();
|
||||
}
|
||||
|
||||
CCScaleBy* action = CCScaleBy::actionWithDuration(2, 0.5f);
|
||||
map->runAction(action);
|
||||
}
|
||||
|
||||
std::string TMXOrthoFlipTest::title()
|
||||
{
|
||||
return "TMX tile flip test";
|
||||
}
|
||||
|
||||
{
|
||||
return "TMX tile flip test";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// TMXOrthoFlipRunTimeTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
TMXOrthoFlipRunTimeTest::TMXOrthoFlipRunTimeTest()
|
||||
{
|
||||
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/ortho-rotation-test.tmx");
|
||||
addChild(map, 0, kTagTileMap);
|
||||
|
||||
CCSize s = map->getContentSize();
|
||||
CCLog("ContentSize: %f, %f", s.width,s.height);
|
||||
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(map->getChildren(), pObj)
|
||||
{
|
||||
CCSpriteBatchNode* child = (CCSpriteBatchNode*)pObj;
|
||||
child->getTexture()->setAntiAliasTexParameters();
|
||||
}
|
||||
|
||||
CCScaleBy* action = CCScaleBy::actionWithDuration(2, 0.5f);
|
||||
map->runAction(action);
|
||||
|
||||
schedule(schedule_selector(TMXOrthoFlipRunTimeTest::flipIt), 1.0f);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
TMXOrthoFlipRunTimeTest::TMXOrthoFlipRunTimeTest()
|
||||
{
|
||||
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/ortho-rotation-test.tmx");
|
||||
addChild(map, 0, kTagTileMap);
|
||||
|
||||
CCSize s = map->getContentSize();
|
||||
CCLog("ContentSize: %f, %f", s.width,s.height);
|
||||
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(map->getChildren(), pObj)
|
||||
{
|
||||
CCSpriteBatchNode* child = (CCSpriteBatchNode*)pObj;
|
||||
child->getTexture()->setAntiAliasTexParameters();
|
||||
}
|
||||
|
||||
CCScaleBy* action = CCScaleBy::actionWithDuration(2, 0.5f);
|
||||
map->runAction(action);
|
||||
|
||||
schedule(schedule_selector(TMXOrthoFlipRunTimeTest::flipIt), 1.0f);
|
||||
}
|
||||
|
||||
std::string TMXOrthoFlipRunTimeTest::title()
|
||||
{
|
||||
return "TMX tile flip run time test";
|
||||
}
|
||||
|
||||
std::string TMXOrthoFlipRunTimeTest::subtitle()
|
||||
{
|
||||
return "in 2 sec bottom left tiles will flip";
|
||||
}
|
||||
|
||||
void TMXOrthoFlipRunTimeTest::flipIt(ccTime dt)
|
||||
{
|
||||
CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
||||
CCTMXLayer *layer = map->layerNamed("Layer 0");
|
||||
|
||||
//blue diamond
|
||||
CCPoint tileCoord = ccp(1,10);
|
||||
int flags;
|
||||
unsigned int GID = layer->tileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
||||
// Vertical
|
||||
if( flags & kCCTMXTileVerticalFlag )
|
||||
flags &= ~kCCTMXTileVerticalFlag;
|
||||
else
|
||||
flags |= kCCTMXTileVerticalFlag;
|
||||
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
|
||||
|
||||
|
||||
tileCoord = ccp(1,8);
|
||||
GID = layer->tileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
||||
// Vertical
|
||||
if( flags & kCCTMXTileVerticalFlag )
|
||||
flags &= ~kCCTMXTileVerticalFlag;
|
||||
else
|
||||
flags |= kCCTMXTileVerticalFlag;
|
||||
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
|
||||
|
||||
|
||||
tileCoord = ccp(2,8);
|
||||
GID = layer->tileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
||||
// Horizontal
|
||||
if( flags & kCCTMXTileHorizontalFlag )
|
||||
flags &= ~kCCTMXTileHorizontalFlag;
|
||||
else
|
||||
flags |= kCCTMXTileHorizontalFlag;
|
||||
layer->setTileGID(GID, tileCoord, (ccTMXTileFlags)flags);
|
||||
}
|
||||
{
|
||||
return "TMX tile flip run time test";
|
||||
}
|
||||
|
||||
std::string TMXOrthoFlipRunTimeTest::subtitle()
|
||||
{
|
||||
return "in 2 sec bottom left tiles will flip";
|
||||
}
|
||||
|
||||
void TMXOrthoFlipRunTimeTest::flipIt(ccTime dt)
|
||||
{
|
||||
CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
||||
CCTMXLayer *layer = map->layerNamed("Layer 0");
|
||||
|
||||
//blue diamond
|
||||
CCPoint tileCoord = ccp(1,10);
|
||||
int flags;
|
||||
unsigned int GID = layer->tileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
||||
// Vertical
|
||||
if( flags & kCCTMXTileVerticalFlag )
|
||||
flags &= ~kCCTMXTileVerticalFlag;
|
||||
else
|
||||
flags |= kCCTMXTileVerticalFlag;
|
||||
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
|
||||
|
||||
|
||||
tileCoord = ccp(1,8);
|
||||
GID = layer->tileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
||||
// Vertical
|
||||
if( flags & kCCTMXTileVerticalFlag )
|
||||
flags &= ~kCCTMXTileVerticalFlag;
|
||||
else
|
||||
flags |= kCCTMXTileVerticalFlag;
|
||||
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
|
||||
|
||||
|
||||
tileCoord = ccp(2,8);
|
||||
GID = layer->tileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
||||
// Horizontal
|
||||
if( flags & kCCTMXTileHorizontalFlag )
|
||||
flags &= ~kCCTMXTileHorizontalFlag;
|
||||
else
|
||||
flags |= kCCTMXTileHorizontalFlag;
|
||||
layer->setTileGID(GID, tileCoord, (ccTMXTileFlags)flags);
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// TMXOrthoFromXMLTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//------------------------------------------------------------------
|
||||
|
||||
TMXOrthoFromXMLTest::TMXOrthoFromXMLTest()
|
||||
{
|
||||
string resources = "TileMaps"; // partial paths are OK as resource paths.
|
||||
string file = resources + "/orthogonal-test1.tmx";
|
||||
|
||||
char* str = CCString::stringWithContentsOfFile(CCFileUtils::fullPathFromRelativePath(file.c_str()));
|
||||
CCAssert(str != NULL, "Unable to open file");
|
||||
|
||||
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithXML(str ,resources.c_str());
|
||||
addChild(map, 0, kTagTileMap);
|
||||
|
||||
CCSize s = map->getContentSize();
|
||||
CCLog("ContentSize: %f, %f", s.width,s.height);
|
||||
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(map->getChildren(), pObj)
|
||||
{
|
||||
CCSpriteBatchNode* child = (CCSpriteBatchNode*)pObj;
|
||||
child->getTexture()->setAntiAliasTexParameters();
|
||||
}
|
||||
|
||||
CCScaleBy* action = CCScaleBy::actionWithDuration(2, 0.5f);
|
||||
string resources = "TileMaps"; // partial paths are OK as resource paths.
|
||||
string file = resources + "/orthogonal-test1.tmx";
|
||||
|
||||
char* str = CCString::stringWithContentsOfFile(CCFileUtils::fullPathFromRelativePath(file.c_str()));
|
||||
CCAssert(str != NULL, "Unable to open file");
|
||||
|
||||
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithXML(str ,resources.c_str());
|
||||
addChild(map, 0, kTagTileMap);
|
||||
|
||||
CCSize s = map->getContentSize();
|
||||
CCLog("ContentSize: %f, %f", s.width,s.height);
|
||||
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(map->getChildren(), pObj)
|
||||
{
|
||||
CCSpriteBatchNode* child = (CCSpriteBatchNode*)pObj;
|
||||
child->getTexture()->setAntiAliasTexParameters();
|
||||
}
|
||||
|
||||
CCScaleBy* action = CCScaleBy::actionWithDuration(2, 0.5f);
|
||||
map->runAction(action);
|
||||
}
|
||||
|
||||
|
@ -1381,8 +1381,8 @@ CCLayer* createTileMapLayer(int nIndex)
|
|||
case 17: return new TMXResizeTest();
|
||||
case 18: return new TMXIsoMoveLayer();
|
||||
case 19: return new TMXOrthoMoveLayer();
|
||||
case 20: return new TMXOrthoFlipTest();
|
||||
case 21: return new TMXOrthoFlipRunTimeTest();
|
||||
case 20: return new TMXOrthoFlipTest();
|
||||
case 21: return new TMXOrthoFlipRunTimeTest();
|
||||
case 22: return new TMXOrthoFromXMLTest();
|
||||
case 23: return new TileMapTest();
|
||||
case 24: return new TileMapEditTest();
|
||||
|
|
Loading…
Reference in New Issue