From 355e27dada744bf4e4864e973598f12fffc75608 Mon Sep 17 00:00:00 2001 From: minggo Date: Sun, 8 Apr 2012 14:16:29 +0800 Subject: [PATCH] merge commit 928a28e37d3469fcd41aff14cb136b1415f2fc86 --- cocos2dx/CCDirector.cpp | 2 +- cocos2dx/actions/CCActionInterval.cpp | 5 +- cocos2dx/include/CCTexture2D.h | 35 +- cocos2dx/include/ccConfig.h | 36 - cocos2dx/include/ccTypes.h | 690 ++--- .../CCLayer.cpp | 72 +- cocos2dx/platform/CCFileUtils.cpp | 62 +- cocos2dx/platform/CCFileUtils.h | 72 +- .../platform/android/CCEGLView_android.cpp | 5 + cocos2dx/platform/android/CCEGLView_android.h | 1 + cocos2dx/platform/bada/CCEGLView_bada.cpp | 5 + cocos2dx/platform/bada/CCEGLView_bada.h | 1 + cocos2dx/platform/ios/CCEGLView_ios.h | 1 + cocos2dx/platform/ios/CCEGLView_ios.mm | 5 + cocos2dx/platform/ios/CCFileUtils_ios.mm | 318 ++- cocos2dx/platform/linux/CCEGLView_linux.cpp | 5 + cocos2dx/platform/linux/CCEGLView_linux.h | 1 + .../marmalade/CCEGLView_marmalade.cpp | 5 + .../platform/marmalade/CCEGLView_marmalade.h | 1 + cocos2dx/platform/qnx/CCEGLView_qnx.cpp | 5 + cocos2dx/platform/qnx/CCEGLView_qnx.h | 1 + cocos2dx/platform/win32/CCEGLView_win32.cpp | 5 + cocos2dx/platform/win32/CCEGLView_win32.h | 1 + cocos2dx/textures/CCTexture2D.cpp | 23 +- cocos2dx/textures/CCTextureCache.cpp | 85 +- .../EffectsAdvancedTest.cpp | 262 +- tests/tests/LayerTest/LayerTest.cpp | 86 +- .../MotionStreakTest/MotionStreakTest.cpp | 82 +- tests/tests/ParticleTest/ParticleTest.cpp | 2262 ++++++++--------- .../RenderTextureTest/RenderTextureTest.cpp | 790 +++--- .../tests/RotateWorldTest/RotateWorldTest.cpp | 10 +- tests/tests/TileMapTest/TileMapTest.cpp | 274 +- 32 files changed, 2730 insertions(+), 2478 deletions(-) diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index d5ea09de0e..936b474e20 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -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; diff --git a/cocos2dx/actions/CCActionInterval.cpp b/cocos2dx/actions/CCActionInterval.cpp index 866a15dc02..8e2a8f7e59 100644 --- a/cocos2dx/actions/CCActionInterval.cpp +++ b/cocos2dx/actions/CCActionInterval.cpp @@ -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); } } diff --git a/cocos2dx/include/CCTexture2D.h b/cocos2dx/include/CCTexture2D.h index c364104e29..db191c3cf4 100755 --- a/cocos2dx/include/CCTexture2D.h +++ b/cocos2dx/include/CCTexture2D.h @@ -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 }; diff --git a/cocos2dx/include/ccConfig.h b/cocos2dx/include/ccConfig.h index 9af4d83ce0..8145c8a7a2 100755 --- a/cocos2dx/include/ccConfig.h +++ b/cocos2dx/include/ccConfig.h @@ -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 diff --git a/cocos2dx/include/ccTypes.h b/cocos2dx/include/ccTypes.h index f960ba98f6..46ad1f772c 100755 --- a/cocos2dx/include/ccTypes.h +++ b/cocos2dx/include/ccTypes.h @@ -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__ diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index 492f259f7b..92a94def16 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -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; iprogramForKey(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; iprogramForKey(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); diff --git a/cocos2dx/platform/CCFileUtils.cpp b/cocos2dx/platform/CCFileUtils.cpp index a4b80817a3..b38900eea0 100644 --- a/cocos2dx/platform/CCFileUtils.cpp +++ b/cocos2dx/platform/CCFileUtils.cpp @@ -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. ////////////////////////////////////////////////////////////////////////// diff --git a/cocos2dx/platform/CCFileUtils.h b/cocos2dx/platform/CCFileUtils.h index 265793d559..a3a3dfc766 100644 --- a/cocos2dx/platform/CCFileUtils.h +++ b/cocos2dx/platform/CCFileUtils.h @@ -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 diff --git a/cocos2dx/platform/android/CCEGLView_android.cpp b/cocos2dx/platform/android/CCEGLView_android.cpp index 5a1b629b00..59586342bf 100644 --- a/cocos2dx/platform/android/CCEGLView_android.cpp +++ b/cocos2dx/platform/android/CCEGLView_android.cpp @@ -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) diff --git a/cocos2dx/platform/android/CCEGLView_android.h b/cocos2dx/platform/android/CCEGLView_android.h index ed083620e2..31a3ae4dbe 100644 --- a/cocos2dx/platform/android/CCEGLView_android.h +++ b/cocos2dx/platform/android/CCEGLView_android.h @@ -40,6 +40,7 @@ public: CCSize getSize(); bool isOpenGLReady(); + bool isIpad(); /** * the width and height is the real size of phone */ diff --git a/cocos2dx/platform/bada/CCEGLView_bada.cpp b/cocos2dx/platform/bada/CCEGLView_bada.cpp index 54e73959d8..28e4890fe4 100644 --- a/cocos2dx/platform/bada/CCEGLView_bada.cpp +++ b/cocos2dx/platform/bada/CCEGLView_bada.cpp @@ -241,6 +241,11 @@ CCRect CCEGLView::getFrame() return rc; } +bool CCEGLView::isIpad() +{ + return false; +} + bool CCEGLView::isOpenGLReady() { return (NULL != m_pEGL); diff --git a/cocos2dx/platform/bada/CCEGLView_bada.h b/cocos2dx/platform/bada/CCEGLView_bada.h index 83d4d71101..15feb29aa3 100644 --- a/cocos2dx/platform/bada/CCEGLView_bada.h +++ b/cocos2dx/platform/bada/CCEGLView_bada.h @@ -55,6 +55,7 @@ public: CCRect getFrame(); CCSize getSize(); bool isOpenGLReady(); + bool isIpad(); void release(); void setTouchDelegate(EGLTouchDelegate * pDelegate); void swapBuffers(); diff --git a/cocos2dx/platform/ios/CCEGLView_ios.h b/cocos2dx/platform/ios/CCEGLView_ios.h index de96382fc1..397bc518b0 100644 --- a/cocos2dx/platform/ios/CCEGLView_ios.h +++ b/cocos2dx/platform/ios/CCEGLView_ios.h @@ -42,6 +42,7 @@ public: CCSize getSize(); bool isOpenGLReady(); bool canSetContentScaleFactor(); + bool isIpad(); void setContentScaleFactor(float contentScaleFactor); // keep compatible diff --git a/cocos2dx/platform/ios/CCEGLView_ios.mm b/cocos2dx/platform/ios/CCEGLView_ios.mm index 1d466ec0ba..2b76702e20 100644 --- a/cocos2dx/platform/ios/CCEGLView_ios.mm +++ b/cocos2dx/platform/ios/CCEGLView_ios.mm @@ -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; diff --git a/cocos2dx/platform/ios/CCFileUtils_ios.mm b/cocos2dx/platform/ios/CCFileUtils_ios.mm index b23e3135b0..7495d01210 100644 --- a/cocos2dx/platform/ios/CCFileUtils_ios.mm +++ b/cocos2dx/platform/ios/CCFileUtils_ios.mm @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ #import +#import #include #include @@ -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) diff --git a/cocos2dx/platform/linux/CCEGLView_linux.cpp b/cocos2dx/platform/linux/CCEGLView_linux.cpp index aaf5b9971b..28d7ab007d 100644 --- a/cocos2dx/platform/linux/CCEGLView_linux.cpp +++ b/cocos2dx/platform/linux/CCEGLView_linux.cpp @@ -278,6 +278,11 @@ bool CCEGLView::isOpenGLReady() return bIsInit; } +bool CCEGLView::isIpad() +{ + return false; +} + void CCEGLView::release() { /* Exits from GLFW */ diff --git a/cocos2dx/platform/linux/CCEGLView_linux.h b/cocos2dx/platform/linux/CCEGLView_linux.h index 1776371742..28133afcb7 100644 --- a/cocos2dx/platform/linux/CCEGLView_linux.h +++ b/cocos2dx/platform/linux/CCEGLView_linux.h @@ -38,6 +38,7 @@ public: CCSize getSize(); bool isOpenGLReady(); + bool isIpad(); void release(); void setTouchDelegate(EGLTouchDelegate * pDelegate); void swapBuffers(); diff --git a/cocos2dx/platform/marmalade/CCEGLView_marmalade.cpp b/cocos2dx/platform/marmalade/CCEGLView_marmalade.cpp index 425dbb5fc3..e917c88f0d 100644 --- a/cocos2dx/platform/marmalade/CCEGLView_marmalade.cpp +++ b/cocos2dx/platform/marmalade/CCEGLView_marmalade.cpp @@ -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"); diff --git a/cocos2dx/platform/marmalade/CCEGLView_marmalade.h b/cocos2dx/platform/marmalade/CCEGLView_marmalade.h index 990f855027..cd1828bb5b 100644 --- a/cocos2dx/platform/marmalade/CCEGLView_marmalade.h +++ b/cocos2dx/platform/marmalade/CCEGLView_marmalade.h @@ -45,6 +45,7 @@ public: CCSize getSize(); bool isOpenGLReady(); + bool isIpad(); /** * the width and height is the real size of phone */ diff --git a/cocos2dx/platform/qnx/CCEGLView_qnx.cpp b/cocos2dx/platform/qnx/CCEGLView_qnx.cpp index 8268c825e6..54088d1410 100644 --- a/cocos2dx/platform/qnx/CCEGLView_qnx.cpp +++ b/cocos2dx/platform/qnx/CCEGLView_qnx.cpp @@ -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) diff --git a/cocos2dx/platform/qnx/CCEGLView_qnx.h b/cocos2dx/platform/qnx/CCEGLView_qnx.h index e30a44fb4a..2624dada44 100644 --- a/cocos2dx/platform/qnx/CCEGLView_qnx.h +++ b/cocos2dx/platform/qnx/CCEGLView_qnx.h @@ -53,6 +53,7 @@ public: CCSize getSize(); bool isOpenGLReady(); + bool isIpad(); /** * the width and height is the real size of phone */ diff --git a/cocos2dx/platform/win32/CCEGLView_win32.cpp b/cocos2dx/platform/win32/CCEGLView_win32.cpp index 1281d089d1..caaa7be915 100644 --- a/cocos2dx/platform/win32/CCEGLView_win32.cpp +++ b/cocos2dx/platform/win32/CCEGLView_win32.cpp @@ -419,6 +419,11 @@ bool CCEGLView::isOpenGLReady() return (NULL != m_pEGL); } +bool CCEGLView::isIpad() +{ + return false; +} + void CCEGLView::release() { if (m_hWnd) diff --git a/cocos2dx/platform/win32/CCEGLView_win32.h b/cocos2dx/platform/win32/CCEGLView_win32.h index 9186e08adf..a6e71cba7f 100644 --- a/cocos2dx/platform/win32/CCEGLView_win32.h +++ b/cocos2dx/platform/win32/CCEGLView_win32.h @@ -47,6 +47,7 @@ public: CCSize getSize(); bool isOpenGLReady(); + bool isIpad(); void release(); void setTouchDelegate(EGLTouchDelegate * pDelegate); void swapBuffers(); diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index 42c9456f5a..71e3b4e829 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -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 } diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index d29cda00a5..7ffb8abdc3 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -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: { diff --git a/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp b/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp index 97bbae327a..37e399dec5 100644 --- a/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp +++ b/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp @@ -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); +} diff --git a/tests/tests/LayerTest/LayerTest.cpp b/tests/tests/LayerTest/LayerTest.cpp index cee7f868c0..f9b5c9c183 100644 --- a/tests/tests/LayerTest/LayerTest.cpp +++ b/tests/tests/LayerTest/LayerTest.cpp @@ -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() diff --git a/tests/tests/MotionStreakTest/MotionStreakTest.cpp b/tests/tests/MotionStreakTest/MotionStreakTest.cpp index f0f263b252..1e07f6965b 100644 --- a/tests/tests/MotionStreakTest/MotionStreakTest.cpp +++ b/tests/tests/MotionStreakTest/MotionStreakTest.cpp @@ -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"; diff --git a/tests/tests/ParticleTest/ParticleTest.cpp b/tests/tests/ParticleTest/ParticleTest.cpp index d3aa39d917..d64273e7a5 100644 --- a/tests/tests/ParticleTest/ParticleTest.cpp +++ b/tests/tests/ParticleTest/ParticleTest.cpp @@ -1,20 +1,20 @@ -#include "ParticleTest.h" -// #include "CCActionInterval.h" -// #include "CCMenu.h" -// #include "CCLabelTTF.h" -// #include "CCLabelAtlas.h" -// #include "touch_dispatcher/CCTouchDispatcher.h" -#include "../testResource.h" -/*#include "support/CCPointExtension.h"*/ - -enum { - kTagParticleCount = 1, -}; - +#include "ParticleTest.h" +// #include "CCActionInterval.h" +// #include "CCMenu.h" +// #include "CCLabelTTF.h" +// #include "CCLabelAtlas.h" +// #include "touch_dispatcher/CCTouchDispatcher.h" +#include "../testResource.h" +/*#include "support/CCPointExtension.h"*/ + +enum { + kTagParticleCount = 1, +}; + CCLayer* nextParticleAction(); CCLayer* backParticleAction(); -CCLayer* restartParticleAction(); - +CCLayer* restartParticleAction(); + //------------------------------------------------------------------ // // DemoFirework @@ -31,14 +31,14 @@ void DemoFirework::onEnter() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) ); setEmitterPosition(); -} - +} + std::string DemoFirework::title() { return "ParticleFireworks"; -} - - +} + + //------------------------------------------------------------------ // // DemoFire @@ -57,13 +57,13 @@ void DemoFire::onEnter() m_emitter->setPosition( CCPointMake(p.x, 100) ); setEmitterPosition(); -} - +} + std::string DemoFire::title() { return "ParticleFire"; -} - +} + //------------------------------------------------------------------ // // DemoSun @@ -79,14 +79,14 @@ void DemoSun::onEnter() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoSun::title() { return "ParticleSun"; -} - +} + //------------------------------------------------------------------ // // DemoGalaxy @@ -95,21 +95,21 @@ std::string DemoSun::title() void DemoGalaxy::onEnter() { ParticleDemo::onEnter(); - + m_emitter = CCParticleGalaxy::node(); m_emitter->retain(); m_background->addChild(m_emitter, 10); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoGalaxy::title() { return "ParticleGalaxy"; -} - +} + //------------------------------------------------------------------ // // DemoFlower @@ -118,20 +118,20 @@ std::string DemoGalaxy::title() void DemoFlower::onEnter() { ParticleDemo::onEnter(); - + m_emitter = CCParticleFlower::node(); m_emitter->retain(); m_background->addChild(m_emitter, 10); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoFlower::title() { return "ParticleFlower"; -} - +} + //------------------------------------------------------------------ // // DemoBigFlower @@ -140,7 +140,7 @@ std::string DemoFlower::title() void DemoBigFlower::onEnter() { ParticleDemo::onEnter(); - + m_emitter = new CCParticleSystemQuad(); m_emitter->initWithTotalParticles(50); //m_emitter->autorelease(); @@ -148,7 +148,7 @@ void DemoBigFlower::onEnter() m_background->addChild(m_emitter, 10); ////m_emitter->release(); // win32 : use this line or remove this line and use autorelease() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) ); - + m_emitter->setDuration(-1); // gravity @@ -209,13 +209,13 @@ void DemoBigFlower::onEnter() m_emitter->setIsBlendAdditive(true); setEmitterPosition(); -} - +} + std::string DemoBigFlower::title() { return "ParticleBigFlower"; -} - +} + //------------------------------------------------------------------ // // DemoRotFlower @@ -294,13 +294,13 @@ void DemoRotFlower::onEnter() m_emitter->setIsBlendAdditive(false); setEmitterPosition(); -} - +} + std::string DemoRotFlower::title() { return "ParticleRotFlower"; -} - +} + //------------------------------------------------------------------ // // DemoMeteor @@ -317,13 +317,13 @@ void DemoMeteor::onEnter() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); setEmitterPosition(); -} - +} + std::string DemoMeteor::title() { return "ParticleMeteor"; -} - +} + //------------------------------------------------------------------ // // DemoSpiral @@ -332,21 +332,21 @@ std::string DemoMeteor::title() void DemoSpiral::onEnter() { ParticleDemo::onEnter(); - + m_emitter = CCParticleSpiral::node(); m_emitter->retain(); m_background->addChild(m_emitter, 10); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoSpiral::title() { return "ParticleSpiral"; -} - +} + //------------------------------------------------------------------ // // DemoExplosion @@ -365,13 +365,13 @@ void DemoExplosion::onEnter() m_emitter->setIsAutoRemoveOnFinish(true); setEmitterPosition(); -} - +} + std::string DemoExplosion::title() { return "ParticleExplosion"; -} - +} + //------------------------------------------------------------------ // // DemoSmoke @@ -390,13 +390,13 @@ void DemoSmoke::onEnter() m_emitter->setPosition( CCPointMake( p.x, 100) ); setEmitterPosition(); -} - +} + std::string DemoSmoke::title() { return "ParticleSmoke"; -} - +} + //------------------------------------------------------------------ // // DemoSnow @@ -412,39 +412,39 @@ void DemoSnow::onEnter() CCPoint p = m_emitter->getPosition(); m_emitter->setPosition( CCPointMake( p.x, p.y-110) ); - m_emitter->setLife(3); - m_emitter->setLifeVar(1); - - // gravity - m_emitter->setGravity(CCPointMake(0,-10)); - - // speed of particles - m_emitter->setSpeed(130); - m_emitter->setSpeedVar(30); - - - ccColor4F startColor = m_emitter->getStartColor(); - startColor.r = 0.9f; - startColor.g = 0.9f; - startColor.b = 0.9f; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = m_emitter->getStartColorVar(); - startColorVar.b = 0.1f; - m_emitter->setStartColorVar(startColorVar); - - m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); + m_emitter->setLife(3); + m_emitter->setLifeVar(1); + + // gravity + m_emitter->setGravity(CCPointMake(0,-10)); + + // speed of particles + m_emitter->setSpeed(130); + m_emitter->setSpeedVar(30); + + + ccColor4F startColor = m_emitter->getStartColor(); + startColor.r = 0.9f; + startColor.g = 0.9f; + startColor.b = 0.9f; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = m_emitter->getStartColorVar(); + startColorVar.b = 0.1f; + m_emitter->setStartColorVar(startColorVar); + + m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_snow) ); setEmitterPosition(); -} - +} + std::string DemoSnow::title() { return "ParticleSnow"; -} - +} + //------------------------------------------------------------------ // // DemoRain @@ -453,7 +453,7 @@ std::string DemoSnow::title() void DemoRain::onEnter() { ParticleDemo::onEnter(); - + m_emitter = CCParticleRain::node(); m_emitter->retain(); m_background->addChild(m_emitter, 10); @@ -464,14 +464,14 @@ void DemoRain::onEnter() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoRain::title() { return "ParticleRain"; -} - +} + //------------------------------------------------------------------ // // DemoModernArt @@ -480,7 +480,7 @@ std::string DemoRain::title() void DemoModernArt::onEnter() { ParticleDemo::onEnter(); - + //FIXME: If use CCParticleSystemPoint, bada 1.0 device will crash. // Crash place: CCParticleSystemPoint.cpp Line 149, function: glDrawArrays(GL_POINTS, 0, m_uParticleIdx); // m_emitter = new CCParticleSystemPoint(); @@ -492,73 +492,73 @@ void DemoModernArt::onEnter() ////m_emitter->release(); CCSize s = CCDirector::sharedDirector()->getWinSize(); - - // duration - m_emitter->setDuration(-1); - - // gravity - m_emitter->setGravity(CCPointMake(0,0)); - - // angle - m_emitter->setAngle(0); - m_emitter->setAngleVar(360); - - // radial - m_emitter->setRadialAccel(70); - m_emitter->setRadialAccelVar(10); - - // tagential - m_emitter->setTangentialAccel(80); - m_emitter->setTangentialAccelVar(0); - - // speed of particles - m_emitter->setSpeed(50); - m_emitter->setSpeedVar(10); - - // emitter position - m_emitter->setPosition( CCPointMake( s.width/2, s.height/2) ); - m_emitter->setPosVar(CCPointZero); - - // life of particles - m_emitter->setLife(2.0f); - m_emitter->setLifeVar(0.3f); - - // emits per frame - m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); - - // color of particles - ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColorVar(startColorVar); - - ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColor(endColor); - - ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColorVar(endColorVar); - - // size, in pixels - m_emitter->setStartSize(1.0f); - m_emitter->setStartSizeVar(1.0f); - m_emitter->setEndSize(32.0f); - m_emitter->setEndSizeVar(8.0f); - + + // duration + m_emitter->setDuration(-1); + + // gravity + m_emitter->setGravity(CCPointMake(0,0)); + + // angle + m_emitter->setAngle(0); + m_emitter->setAngleVar(360); + + // radial + m_emitter->setRadialAccel(70); + m_emitter->setRadialAccelVar(10); + + // tagential + m_emitter->setTangentialAccel(80); + m_emitter->setTangentialAccelVar(0); + + // speed of particles + m_emitter->setSpeed(50); + m_emitter->setSpeedVar(10); + + // emitter position + m_emitter->setPosition( CCPointMake( s.width/2, s.height/2) ); + m_emitter->setPosVar(CCPointZero); + + // life of particles + m_emitter->setLife(2.0f); + m_emitter->setLifeVar(0.3f); + + // emits per frame + m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); + + // color of particles + ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColorVar(startColorVar); + + ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColor(endColor); + + ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColorVar(endColorVar); + + // size, in pixels + m_emitter->setStartSize(1.0f); + m_emitter->setStartSizeVar(1.0f); + m_emitter->setEndSize(32.0f); + m_emitter->setEndSizeVar(8.0f); + // texture m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); // additive m_emitter->setIsBlendAdditive(false); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoModernArt::title() { return "Varying size"; -} - +} + //------------------------------------------------------------------ // // DemoRing @@ -574,20 +574,20 @@ void DemoRing::onEnter() m_background->addChild(m_emitter, 10); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) ); - m_emitter->setLifeVar(0); - m_emitter->setLife(10); - m_emitter->setSpeed(100); - m_emitter->setSpeedVar(0); - m_emitter->setEmissionRate(10000); + m_emitter->setLifeVar(0); + m_emitter->setLife(10); + m_emitter->setSpeed(100); + m_emitter->setSpeedVar(0); + m_emitter->setEmissionRate(10000); setEmitterPosition(); -} - +} + std::string DemoRing::title() { return "Ring Demo"; -} - +} + //------------------------------------------------------------------ // // ParallaxParticle @@ -596,284 +596,284 @@ std::string DemoRing::title() void ParallaxParticle::onEnter() { ParticleDemo::onEnter(); - - m_background->getParent()->removeChild(m_background, true); - m_background = NULL; - - CCParallaxNode* p = CCParallaxNode::node(); - addChild(p, 5); - - CCSprite *p1 = CCSprite::spriteWithFile(s_back3); - CCSprite *p2 = CCSprite::spriteWithFile(s_back3); - - p->addChild( p1, 1, CCPointMake(0.5f,1), CCPointMake(0,250) ); - p->addChild(p2, 2, CCPointMake(1.5f,1), CCPointMake(0,50) ); - - m_emitter = CCParticleFlower::node(); - m_emitter->retain(); - m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - - p1->addChild(m_emitter, 10); - m_emitter->setPosition( CCPointMake(250,200) ); - - CCParticleSun* par = CCParticleSun::node(); - p2->addChild(par, 10); - par->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - - CCActionInterval* move = CCMoveBy::actionWithDuration(4, CCPointMake(300,0)); - CCActionInterval* move_back = move->reverse(); - CCFiniteTimeAction* seq = CCSequence::actions( move, move_back, NULL); - p->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq)); -} - + + m_background->getParent()->removeChild(m_background, true); + m_background = NULL; + + CCParallaxNode* p = CCParallaxNode::node(); + addChild(p, 5); + + CCSprite *p1 = CCSprite::spriteWithFile(s_back3); + CCSprite *p2 = CCSprite::spriteWithFile(s_back3); + + p->addChild( p1, 1, CCPointMake(0.5f,1), CCPointMake(0,250) ); + p->addChild(p2, 2, CCPointMake(1.5f,1), CCPointMake(0,50) ); + + m_emitter = CCParticleFlower::node(); + m_emitter->retain(); + m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); + + p1->addChild(m_emitter, 10); + m_emitter->setPosition( CCPointMake(250,200) ); + + CCParticleSun* par = CCParticleSun::node(); + p2->addChild(par, 10); + par->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); + + CCActionInterval* move = CCMoveBy::actionWithDuration(4, CCPointMake(300,0)); + CCActionInterval* move_back = move->reverse(); + CCFiniteTimeAction* seq = CCSequence::actions( move, move_back, NULL); + p->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq)); +} + std::string ParallaxParticle::title() { return "Parallax + Particles"; -} - +} + //------------------------------------------------------------------ // // RadiusMode1 // -//------------------------------------------------------------------ +//------------------------------------------------------------------ void RadiusMode1::onEnter() { ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = new CCParticleSystemQuad(); - m_emitter->initWithTotalParticles(200); - addChild(m_emitter, 10); - m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png")); - - // duration - m_emitter->setDuration(kCCParticleDurationInfinity); - - // radius mode - m_emitter->setEmitterMode(kCCParticleModeRadius); - - // radius mode: start and end radius in pixels - m_emitter->setStartRadius(0); - m_emitter->setStartRadiusVar(0); - m_emitter->setEndRadius(160); - m_emitter->setEndRadiusVar(0); - - // radius mode: degrees per second - m_emitter->setRotatePerSecond(180); - m_emitter->setRotatePerSecondVar(0); - - - // angle - m_emitter->setAngle(90); - m_emitter->setAngleVar(0); - - // emitter position - CCSize size = CCDirector::sharedDirector()->getWinSize(); - m_emitter->setPosition(ccp(size.width/2, size.height/2)); - m_emitter->setPosVar(CCPointZero); - - // life of particles - m_emitter->setLife(5); - m_emitter->setLifeVar(0); - - // spin of particles - m_emitter->setStartSpin(0); - m_emitter->setStartSpinVar(0); - m_emitter->setEndSpin(0); - m_emitter->setEndSpinVar(0); - - // color of particles - ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColorVar(startColorVar); - - ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColor(endColor); - - ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColorVar(endColorVar); - - // size, in pixels - m_emitter->setStartSize(32); - m_emitter->setStartSizeVar(0); - m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per second - m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); - + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = new CCParticleSystemQuad(); + m_emitter->initWithTotalParticles(200); + addChild(m_emitter, 10); + m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png")); + + // duration + m_emitter->setDuration(kCCParticleDurationInfinity); + + // radius mode + m_emitter->setEmitterMode(kCCParticleModeRadius); + + // radius mode: start and end radius in pixels + m_emitter->setStartRadius(0); + m_emitter->setStartRadiusVar(0); + m_emitter->setEndRadius(160); + m_emitter->setEndRadiusVar(0); + + // radius mode: degrees per second + m_emitter->setRotatePerSecond(180); + m_emitter->setRotatePerSecondVar(0); + + + // angle + m_emitter->setAngle(90); + m_emitter->setAngleVar(0); + + // emitter position + CCSize size = CCDirector::sharedDirector()->getWinSize(); + m_emitter->setPosition(ccp(size.width/2, size.height/2)); + m_emitter->setPosVar(CCPointZero); + + // life of particles + m_emitter->setLife(5); + m_emitter->setLifeVar(0); + + // spin of particles + m_emitter->setStartSpin(0); + m_emitter->setStartSpinVar(0); + m_emitter->setEndSpin(0); + m_emitter->setEndSpinVar(0); + + // color of particles + ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColorVar(startColorVar); + + ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColor(endColor); + + ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColorVar(endColorVar); + + // size, in pixels + m_emitter->setStartSize(32); + m_emitter->setStartSizeVar(0); + m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per second + m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); + // additive m_emitter->setIsBlendAdditive(false); } -std::string RadiusMode1::title() -{ - return "Radius Mode: Spiral"; -} - +std::string RadiusMode1::title() +{ + return "Radius Mode: Spiral"; +} + //------------------------------------------------------------------ // // RadiusMode2 // -//------------------------------------------------------------------ +//------------------------------------------------------------------ void RadiusMode2::onEnter() { ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = new CCParticleSystemQuad(); - m_emitter->initWithTotalParticles(200); - addChild(m_emitter, 10); - m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png")); - - // duration - m_emitter->setDuration(kCCParticleDurationInfinity); - - // radius mode - m_emitter->setEmitterMode(kCCParticleModeRadius); - - // radius mode: start and end radius in pixels - m_emitter->setStartRadius(100); - m_emitter->setStartRadiusVar(0); - m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); - m_emitter->setEndRadiusVar(0); - - // radius mode: degrees per second - m_emitter->setRotatePerSecond(45); - m_emitter->setRotatePerSecondVar(0); - - - // angle - m_emitter->setAngle(90); - m_emitter->setAngleVar(0); - - // emitter position - CCSize size = CCDirector::sharedDirector()->getWinSize(); - m_emitter->setPosition(ccp(size.width/2, size.height/2)); - m_emitter->setPosVar(CCPointZero); - - // life of particles - m_emitter->setLife(4); - m_emitter->setLifeVar(0); - - // spin of particles - m_emitter->setStartSpin(0); - m_emitter->setStartSpinVar(0); - m_emitter->setEndSpin(0); - m_emitter->setEndSpinVar(0); - - // color of particles - ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColorVar(startColorVar); - - ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColor(endColor); - - ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColorVar(endColorVar); - - // size, in pixels - m_emitter->setStartSize(32); - m_emitter->setStartSizeVar(0); - m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per second - m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); - + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = new CCParticleSystemQuad(); + m_emitter->initWithTotalParticles(200); + addChild(m_emitter, 10); + m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png")); + + // duration + m_emitter->setDuration(kCCParticleDurationInfinity); + + // radius mode + m_emitter->setEmitterMode(kCCParticleModeRadius); + + // radius mode: start and end radius in pixels + m_emitter->setStartRadius(100); + m_emitter->setStartRadiusVar(0); + m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); + m_emitter->setEndRadiusVar(0); + + // radius mode: degrees per second + m_emitter->setRotatePerSecond(45); + m_emitter->setRotatePerSecondVar(0); + + + // angle + m_emitter->setAngle(90); + m_emitter->setAngleVar(0); + + // emitter position + CCSize size = CCDirector::sharedDirector()->getWinSize(); + m_emitter->setPosition(ccp(size.width/2, size.height/2)); + m_emitter->setPosVar(CCPointZero); + + // life of particles + m_emitter->setLife(4); + m_emitter->setLifeVar(0); + + // spin of particles + m_emitter->setStartSpin(0); + m_emitter->setStartSpinVar(0); + m_emitter->setEndSpin(0); + m_emitter->setEndSpinVar(0); + + // color of particles + ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColorVar(startColorVar); + + ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColor(endColor); + + ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColorVar(endColorVar); + + // size, in pixels + m_emitter->setStartSize(32); + m_emitter->setStartSizeVar(0); + m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per second + m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); + // additive m_emitter->setIsBlendAdditive(false); } -std::string RadiusMode2::title() -{ - return "Radius Mode: Semi Circle"; -} - +std::string RadiusMode2::title() +{ + return "Radius Mode: Semi Circle"; +} + //------------------------------------------------------------------ // // Issue704 // -//------------------------------------------------------------------ +//------------------------------------------------------------------ void Issue704::onEnter() { ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = new CCParticleSystemQuad(); - m_emitter->initWithTotalParticles(100); - addChild(m_emitter, 10); - m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png")); - - // duration - m_emitter->setDuration(kCCParticleDurationInfinity); - - // radius mode - m_emitter->setEmitterMode(kCCParticleModeRadius); - - // radius mode: start and end radius in pixels - m_emitter->setStartRadius(50); - m_emitter->setStartRadiusVar(0); - m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); - m_emitter->setEndRadiusVar(0); - - // radius mode: degrees per second - m_emitter->setRotatePerSecond(0); - m_emitter->setRotatePerSecondVar(0); - - - // angle - m_emitter->setAngle(90); - m_emitter->setAngleVar(0); - - // emitter position - CCSize size = CCDirector::sharedDirector()->getWinSize(); - m_emitter->setPosition(ccp(size.width/2, size.height/2)); - m_emitter->setPosVar(CCPointZero); - - // life of particles - m_emitter->setLife(5); - m_emitter->setLifeVar(0); - - // spin of particles - m_emitter->setStartSpin(0); - m_emitter->setStartSpinVar(0); - m_emitter->setEndSpin(0); - m_emitter->setEndSpinVar(0); - - // color of particles - ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColorVar(startColorVar); - - ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColor(endColor); - - ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColorVar(endColorVar); - - // size, in pixels - m_emitter->setStartSize(16); - m_emitter->setStartSizeVar(0); - m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per second - m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); - + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = new CCParticleSystemQuad(); + m_emitter->initWithTotalParticles(100); + addChild(m_emitter, 10); + m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png")); + + // duration + m_emitter->setDuration(kCCParticleDurationInfinity); + + // radius mode + m_emitter->setEmitterMode(kCCParticleModeRadius); + + // radius mode: start and end radius in pixels + m_emitter->setStartRadius(50); + m_emitter->setStartRadiusVar(0); + m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); + m_emitter->setEndRadiusVar(0); + + // radius mode: degrees per second + m_emitter->setRotatePerSecond(0); + m_emitter->setRotatePerSecondVar(0); + + + // angle + m_emitter->setAngle(90); + m_emitter->setAngleVar(0); + + // emitter position + CCSize size = CCDirector::sharedDirector()->getWinSize(); + m_emitter->setPosition(ccp(size.width/2, size.height/2)); + m_emitter->setPosVar(CCPointZero); + + // life of particles + m_emitter->setLife(5); + m_emitter->setLifeVar(0); + + // spin of particles + m_emitter->setStartSpin(0); + m_emitter->setStartSpinVar(0); + m_emitter->setEndSpin(0); + m_emitter->setEndSpinVar(0); + + // color of particles + ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColorVar(startColorVar); + + ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColor(endColor); + + ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColorVar(endColorVar); + + // size, in pixels + m_emitter->setStartSize(16); + m_emitter->setStartSizeVar(0); + m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per second + m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); + // additive m_emitter->setIsBlendAdditive(false); @@ -881,84 +881,84 @@ void Issue704::onEnter() m_emitter->runAction(CCRepeatForever::actionWithAction(rot)); } -std::string Issue704::title() -{ - return "Issue 704. Free + Rot"; -} - -std::string Issue704::subtitle() -{ - return "Emitted particles should not rotate"; -} - +std::string Issue704::title() +{ + return "Issue 704. Free + Rot"; +} + +std::string Issue704::subtitle() +{ + return "Emitted particles should not rotate"; +} + //------------------------------------------------------------------ // // Issue870 // -//------------------------------------------------------------------ -void Issue870::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCParticleSystemQuad *system = new CCParticleSystemQuad(); - system->initWithFile("Images/SpinningPeas.plist"); - system->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"), CCRectMake(0,0,32,32)); - addChild(system, 10); - m_emitter = system; - - m_nIndex = 0; - schedule(schedule_selector(Issue870::updateQuads), 2.0f); -} - -void Issue870::updateQuads(ccTime dt) -{ - m_nIndex = (m_nIndex + 1) % 4; - CCRect rect = CCRectMake(m_nIndex * 32, 0, 32, 32); - CCParticleSystemQuad* system = (CCParticleSystemQuad*)m_emitter; - system->setTextureWithRect(m_emitter->getTexture(), rect); -} - -std::string Issue870::title() -{ - return "Issue 870. SubRect"; -} - -std::string Issue870::subtitle() -{ - return "Every 2 seconds the particle should change"; -} - +//------------------------------------------------------------------ +void Issue870::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCParticleSystemQuad *system = new CCParticleSystemQuad(); + system->initWithFile("Images/SpinningPeas.plist"); + system->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"), CCRectMake(0,0,32,32)); + addChild(system, 10); + m_emitter = system; + + m_nIndex = 0; + schedule(schedule_selector(Issue870::updateQuads), 2.0f); +} + +void Issue870::updateQuads(ccTime dt) +{ + m_nIndex = (m_nIndex + 1) % 4; + CCRect rect = CCRectMake(m_nIndex * 32, 0, 32, 32); + CCParticleSystemQuad* system = (CCParticleSystemQuad*)m_emitter; + system->setTextureWithRect(m_emitter->getTexture(), rect); +} + +std::string Issue870::title() +{ + return "Issue 870. SubRect"; +} + +std::string Issue870::subtitle() +{ + return "Every 2 seconds the particle should change"; +} + //------------------------------------------------------------------ // // DemoParticleFromFile // -//------------------------------------------------------------------ -void DemoParticleFromFile::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = new CCParticleSystemQuad(); - std::string filename = "Images/" + m_title + ".plist"; - m_emitter->initWithFile(filename.c_str()); - addChild(m_emitter, 10); - - setEmitterPosition(); -} - +//------------------------------------------------------------------ +void DemoParticleFromFile::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = new CCParticleSystemQuad(); + std::string filename = "Images/" + m_title + ".plist"; + m_emitter->initWithFile(filename.c_str()); + addChild(m_emitter, 10); + + setEmitterPosition(); +} + //------------------------------------------------------------------ // // ParticleDemo // //------------------------------------------------------------------ - + enum { IDC_NEXT = 100, @@ -966,9 +966,9 @@ enum IDC_RESTART, IDC_TOGGLE }; - -static int sceneIdx = -1; - + +static int sceneIdx = -1; + #define MAX_LAYER 41 CCLayer* createParticleLayer(int nIndex) @@ -994,17 +994,17 @@ CCLayer* createParticleLayer(int nIndex) case 16: return new DemoModernArt(); case 17: return new DemoRing(); case 18: return new ParallaxParticle(); - case 19: return new DemoParticleFromFile("BoilingFoam"); - case 20: return new DemoParticleFromFile("BurstPipe"); - case 21: return new DemoParticleFromFile("Comet"); - case 22: return new DemoParticleFromFile("debian"); - case 23: return new DemoParticleFromFile("ExplodingRing"); - case 24: return new DemoParticleFromFile("LavaFlow"); - case 25: return new DemoParticleFromFile("SpinningPeas"); - case 26: return new DemoParticleFromFile("SpookyPeas"); + case 19: return new DemoParticleFromFile("BoilingFoam"); + case 20: return new DemoParticleFromFile("BurstPipe"); + case 21: return new DemoParticleFromFile("Comet"); + case 22: return new DemoParticleFromFile("debian"); + case 23: return new DemoParticleFromFile("ExplodingRing"); + case 24: return new DemoParticleFromFile("LavaFlow"); + case 25: return new DemoParticleFromFile("SpinningPeas"); + case 26: return new DemoParticleFromFile("SpookyPeas"); case 27: return new DemoParticleFromFile("Upsidedown"); - case 28: return new DemoParticleFromFile("Flower"); - case 29: return new DemoParticleFromFile("Spiral"); + case 28: return new DemoParticleFromFile("Flower"); + case 29: return new DemoParticleFromFile("Spiral"); case 30: return new DemoParticleFromFile("Galaxy"); case 31: return new DemoParticleFromFile("Phoenix"); case 32: return new RadiusMode1(); @@ -1055,11 +1055,11 @@ CCLayer* restartParticleAction() pLayer->autorelease(); return pLayer; -} - - -ParticleDemo::ParticleDemo(void) -{ +} + + +ParticleDemo::ParticleDemo(void) +{ initWithColor( ccc4(127,127,127,255) ); m_emitter = NULL; @@ -1098,8 +1098,8 @@ ParticleDemo::ParticleDemo(void) addChild( menu, 100 ); CCLabelAtlas* labelAtlas = CCLabelAtlas::labelWithString("0000", "fonts/fps_images.png", 16, 24, '.'); - addChild(labelAtlas, 100, kTagParticleCount); - labelAtlas->setPosition( CCPointMake(s.width-66,50) ); + addChild(labelAtlas, 100, kTagParticleCount); + labelAtlas->setPosition( CCPointMake(s.width-66,50) ); // moving background m_background = CCSprite::spriteWithFile(s_back3); @@ -1113,21 +1113,21 @@ ParticleDemo::ParticleDemo(void) scheduleUpdate(); -} - -ParticleDemo::~ParticleDemo(void) -{ - CC_SAFE_RELEASE(m_emitter); -} - -void ParticleDemo::onEnter(void) -{ - CCLayer::onEnter(); - - CCLabelTTF* pLabel = (CCLabelTTF*)(this->getChildByTag(1000)); - pLabel->setString(title().c_str()); -} - +} + +ParticleDemo::~ParticleDemo(void) +{ + CC_SAFE_RELEASE(m_emitter); +} + +void ParticleDemo::onEnter(void) +{ + CCLayer::onEnter(); + + CCLabelTTF* pLabel = (CCLabelTTF*)(this->getChildByTag(1000)); + pLabel->setString(title().c_str()); +} + std::string ParticleDemo::title() { return "No title"; @@ -1170,11 +1170,11 @@ void ParticleDemo::update(ccTime dt) { if (m_emitter) { - CCLabelAtlas* atlas = (CCLabelAtlas*)getChildByTag(kTagParticleCount); - char str[5] = {0}; - sprintf(str, "%04d", m_emitter->getParticleCount()); - atlas->setString(str); - } + CCLabelAtlas* atlas = (CCLabelAtlas*)getChildByTag(kTagParticleCount); + char str[5] = {0}; + sprintf(str, "%04d", m_emitter->getParticleCount()); + atlas->setString(str); + } } void ParticleDemo::toggleCallback(CCObject* pSender) @@ -1213,7 +1213,7 @@ void ParticleDemo::backCallback(CCObject* pSender) CCDirector::sharedDirector()->replaceScene(s); s->release(); } - + void ParticleDemo::setEmitterPosition() { CCSize s = CCDirector::sharedDirector()->getWinSize(); @@ -1221,643 +1221,643 @@ void ParticleDemo::setEmitterPosition() { m_emitter->setPosition( CCPointMake(s.width / 2, s.height / 2) ); } -} - -// ParticleBatchHybrid - -void ParticleBatchHybrid::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); - m_emitter->retain(); - CCParticleBatchNode *batch = CCParticleBatchNode::batchNodeWithTexture(m_emitter->getTexture()); - - batch->addChild(m_emitter); - - addChild(batch, 10); - - schedule(schedule_selector(ParticleBatchHybrid::switchRender), 2.0f); - - CCNode *node = CCNode::node(); - addChild(node); - - m_pParent1 = batch; - m_pParent2 = node; -} - -void ParticleBatchHybrid::switchRender(ccTime dt) -{ - bool usingBatch = ( m_emitter->getBatchNode() != NULL ); - m_emitter->removeFromParentAndCleanup(false); - - CCNode *newParent = (usingBatch ? m_pParent2 : m_pParent1 ); - newParent->addChild(m_emitter); - - CCLog("Particle: Using new parent: %s", usingBatch ? "CCNode" : "CCParticleBatchNode"); -} - +} + +// ParticleBatchHybrid + +void ParticleBatchHybrid::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); + m_emitter->retain(); + CCParticleBatchNode *batch = CCParticleBatchNode::batchNodeWithTexture(m_emitter->getTexture()); + + batch->addChild(m_emitter); + + addChild(batch, 10); + + schedule(schedule_selector(ParticleBatchHybrid::switchRender), 2.0f); + + CCNode *node = CCNode::node(); + addChild(node); + + m_pParent1 = batch; + m_pParent2 = node; +} + +void ParticleBatchHybrid::switchRender(ccTime dt) +{ + bool usingBatch = ( m_emitter->getBatchNode() != NULL ); + m_emitter->removeFromParentAndCleanup(false); + + CCNode *newParent = (usingBatch ? m_pParent2 : m_pParent1 ); + newParent->addChild(m_emitter); + + CCLog("Particle: Using new parent: %s", usingBatch ? "CCNode" : "CCParticleBatchNode"); +} + std::string ParticleBatchHybrid::title() { return "Paticle Batch"; } -std::string ParticleBatchHybrid::subtitle() -{ - return "Hybrid: batched and non batched every 2 seconds"; -} - -// ParticleBatchMultipleEmitters - -void ParticleBatchMultipleEmitters::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); - emitter1->setStartColor(ccc4f(1,0,0,1)); - CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); - emitter2->setStartColor(ccc4f(0,1,0,1)); - CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); - emitter3->setStartColor(ccc4f(0,0,1,1)); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - emitter1->setPosition(ccp( s.width/1.25f, s.height/1.25f)); - emitter2->setPosition(ccp( s.width/2, s.height/2)); - emitter3->setPosition(ccp( s.width/4, s.height/4)); - - CCParticleBatchNode *batch = CCParticleBatchNode::batchNodeWithTexture(emitter1->getTexture()); - - batch->addChild(emitter1, 0); - batch->addChild(emitter2, 0); - batch->addChild(emitter3, 0); - - addChild(batch, 10); -} - +std::string ParticleBatchHybrid::subtitle() +{ + return "Hybrid: batched and non batched every 2 seconds"; +} + +// ParticleBatchMultipleEmitters + +void ParticleBatchMultipleEmitters::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); + emitter1->setStartColor(ccc4f(1,0,0,1)); + CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); + emitter2->setStartColor(ccc4f(0,1,0,1)); + CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); + emitter3->setStartColor(ccc4f(0,0,1,1)); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + emitter1->setPosition(ccp( s.width/1.25f, s.height/1.25f)); + emitter2->setPosition(ccp( s.width/2, s.height/2)); + emitter3->setPosition(ccp( s.width/4, s.height/4)); + + CCParticleBatchNode *batch = CCParticleBatchNode::batchNodeWithTexture(emitter1->getTexture()); + + batch->addChild(emitter1, 0); + batch->addChild(emitter2, 0); + batch->addChild(emitter3, 0); + + addChild(batch, 10); +} + std::string ParticleBatchMultipleEmitters::title() { return "Paticle Batch"; } -std::string ParticleBatchMultipleEmitters::subtitle() -{ - return "Multiple emitters. One Batch"; -} - -// ParticleReorder - -void ParticleReorder::onEnter() -{ - ParticleDemo::onEnter(); - - m_nOrder = 0; - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCParticleSystem *ignore = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); - CCNode *parent1 = CCNode::node(); - CCNode *parent2 = CCParticleBatchNode::batchNodeWithTexture(ignore->getTexture()); - - for( unsigned int i=0; i<2;i++) { - CCNode *parent = ( i==0 ? parent1 : parent2 ); - - CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); - emitter1->setStartColor(ccc4f(1,0,0,1)); - emitter1->setIsBlendAdditive(false); - CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); - emitter2->setStartColor(ccc4f(0,1,0,1)); - emitter2->setIsBlendAdditive(false); - CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); - emitter3->setStartColor(ccc4f(0,0,1,1)); - emitter3->setIsBlendAdditive(false); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - int neg = (i==0 ? 1 : -1 ); - - emitter1->setPosition(ccp( s.width/2-30, s.height/2+60*neg)); - emitter2->setPosition(ccp( s.width/2, s.height/2+60*neg)); - emitter3->setPosition(ccp( s.width/2+30, s.height/2+60*neg)); - - parent->addChild(emitter1, 0, 1); - parent->addChild(emitter2, 0, 2); - parent->addChild(emitter3, 0, 3); - - addChild(parent, 10, 1000+i); - } - - schedule(schedule_selector(ParticleReorder::reorderParticles), 1.0f); -} - -std::string ParticleReorder::title() -{ - return "Reordering particles"; -} - -std::string ParticleReorder::subtitle() -{ - return "Reordering particles with and without batches batches"; -} - -void ParticleReorder::reorderParticles(ccTime dt) -{ - for( int i=0; i<2;i++) { - CCNode *parent = getChildByTag(1000+i); - - CCNode *child1 = parent->getChildByTag(1); - CCNode *child2 = parent->getChildByTag(2); - CCNode *child3 = parent->getChildByTag(3); - - if( m_nOrder % 3 == 0 ) { - parent->reorderChild(child1, 1); - parent->reorderChild(child2, 2); - parent->reorderChild(child3, 3); - - } else if (m_nOrder % 3 == 1 ) { - parent->reorderChild(child1, 3); - parent->reorderChild(child2, 1); - parent->reorderChild(child3, 2); - - } else if (m_nOrder % 3 == 2 ) { - parent->reorderChild(child1, 2); - parent->reorderChild(child2, 3); - parent->reorderChild(child3, 1); - } - } - - m_nOrder++; -} - -class RainbowEffect : public CCParticleSystemQuad -{ -public: - bool init(); - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - virtual void update(ccTime dt); -}; - -bool RainbowEffect::init() -{ - return initWithTotalParticles(150); -} - -bool RainbowEffect::initWithTotalParticles(unsigned int numberOfParticles) -{ - if( CCParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) - { - // additive - setIsBlendAdditive(false); - - // duration - setDuration(kCCParticleDurationInfinity); - - // Gravity Mode - setEmitterMode(kCCParticleModeGravity); - - // Gravity Mode: gravity - setGravity(ccp(0,0)); - - // Gravity mode: radial acceleration - setRadialAccel(0); - setRadialAccelVar(0); - - // Gravity mode: speed of particles - setSpeed(120); - setSpeedVar(0); - - - // angle - setAngle(180); - setAngleVar(0); - - // emitter position - CCSize winSize = CCDirector::sharedDirector()->getWinSize(); - setPosition(ccp(winSize.width/2, winSize.height/2)); - setPosVar(CCPointZero); - - // life of particles - setLife(0.5f); - setLifeVar(0); - - // size, in pixels - setStartSize(25.0f); - setStartSizeVar(0); - setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per seconds - setEmissionRate(getTotalParticles()/getLife()); - - // color of particles - setStartColor(ccc4FFromccc4B(ccc4(50, 50, 50, 50))); - setEndColor(ccc4FFromccc4B(ccc4(0, 0, 0, 0))); - - m_tStartColorVar.r = 0.0f; - m_tStartColorVar.g = 0.0f; - m_tStartColorVar.b = 0.0f; - m_tStartColorVar.a = 0.0f; - m_tEndColorVar.r = 0.0f; - m_tEndColorVar.g = 0.0f; - m_tEndColorVar.b = 0.0f; - m_tEndColorVar.a = 0.0f; - - setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png")); - return true; - } - - return false; -} - -void RainbowEffect::update(ccTime dt) -{ - m_fEmitCounter = 0; - CCParticleSystemQuad::update(dt); -} - - -void Issue1201::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - RainbowEffect *particle = new RainbowEffect(); - particle->initWithTotalParticles(50); - - addChild(particle); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - particle->setPosition(ccp(s.width/2, s.height/2)); - - m_emitter = particle; -} - -std::string Issue1201::title() -{ - return "Issue 1201. Unfinished"; -} - -std::string Issue1201::subtitle() -{ - return "Unfinished test. Ignore it"; -} - -void MultipleParticleSystems::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"); - - for (int i = 0; i<5; i++) { - CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/SpinningPeas.plist"); - - particleSystem->setPosition(ccp(i*50 ,i*50)); - - particleSystem->setPositionType(kCCPositionTypeGrouped); - addChild(particleSystem); - } - - m_emitter = NULL; - -} - +std::string ParticleBatchMultipleEmitters::subtitle() +{ + return "Multiple emitters. One Batch"; +} + +// ParticleReorder + +void ParticleReorder::onEnter() +{ + ParticleDemo::onEnter(); + + m_nOrder = 0; + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCParticleSystem *ignore = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); + CCNode *parent1 = CCNode::node(); + CCNode *parent2 = CCParticleBatchNode::batchNodeWithTexture(ignore->getTexture()); + + for( unsigned int i=0; i<2;i++) { + CCNode *parent = ( i==0 ? parent1 : parent2 ); + + CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); + emitter1->setStartColor(ccc4f(1,0,0,1)); + emitter1->setIsBlendAdditive(false); + CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); + emitter2->setStartColor(ccc4f(0,1,0,1)); + emitter2->setIsBlendAdditive(false); + CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); + emitter3->setStartColor(ccc4f(0,0,1,1)); + emitter3->setIsBlendAdditive(false); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + int neg = (i==0 ? 1 : -1 ); + + emitter1->setPosition(ccp( s.width/2-30, s.height/2+60*neg)); + emitter2->setPosition(ccp( s.width/2, s.height/2+60*neg)); + emitter3->setPosition(ccp( s.width/2+30, s.height/2+60*neg)); + + parent->addChild(emitter1, 0, 1); + parent->addChild(emitter2, 0, 2); + parent->addChild(emitter3, 0, 3); + + addChild(parent, 10, 1000+i); + } + + schedule(schedule_selector(ParticleReorder::reorderParticles), 1.0f); +} + +std::string ParticleReorder::title() +{ + return "Reordering particles"; +} + +std::string ParticleReorder::subtitle() +{ + return "Reordering particles with and without batches batches"; +} + +void ParticleReorder::reorderParticles(ccTime dt) +{ + for( int i=0; i<2;i++) { + CCNode *parent = getChildByTag(1000+i); + + CCNode *child1 = parent->getChildByTag(1); + CCNode *child2 = parent->getChildByTag(2); + CCNode *child3 = parent->getChildByTag(3); + + if( m_nOrder % 3 == 0 ) { + parent->reorderChild(child1, 1); + parent->reorderChild(child2, 2); + parent->reorderChild(child3, 3); + + } else if (m_nOrder % 3 == 1 ) { + parent->reorderChild(child1, 3); + parent->reorderChild(child2, 1); + parent->reorderChild(child3, 2); + + } else if (m_nOrder % 3 == 2 ) { + parent->reorderChild(child1, 2); + parent->reorderChild(child2, 3); + parent->reorderChild(child3, 1); + } + } + + m_nOrder++; +} + +class RainbowEffect : public CCParticleSystemQuad +{ +public: + bool init(); + virtual bool initWithTotalParticles(unsigned int numberOfParticles); + virtual void update(ccTime dt); +}; + +bool RainbowEffect::init() +{ + return initWithTotalParticles(150); +} + +bool RainbowEffect::initWithTotalParticles(unsigned int numberOfParticles) +{ + if( CCParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) + { + // additive + setIsBlendAdditive(false); + + // duration + setDuration(kCCParticleDurationInfinity); + + // Gravity Mode + setEmitterMode(kCCParticleModeGravity); + + // Gravity Mode: gravity + setGravity(ccp(0,0)); + + // Gravity mode: radial acceleration + setRadialAccel(0); + setRadialAccelVar(0); + + // Gravity mode: speed of particles + setSpeed(120); + setSpeedVar(0); + + + // angle + setAngle(180); + setAngleVar(0); + + // emitter position + CCSize winSize = CCDirector::sharedDirector()->getWinSize(); + setPosition(ccp(winSize.width/2, winSize.height/2)); + setPosVar(CCPointZero); + + // life of particles + setLife(0.5f); + setLifeVar(0); + + // size, in pixels + setStartSize(25.0f); + setStartSizeVar(0); + setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per seconds + setEmissionRate(getTotalParticles()/getLife()); + + // color of particles + setStartColor(ccc4FFromccc4B(ccc4(50, 50, 50, 50))); + setEndColor(ccc4FFromccc4B(ccc4(0, 0, 0, 0))); + + m_tStartColorVar.r = 0.0f; + m_tStartColorVar.g = 0.0f; + m_tStartColorVar.b = 0.0f; + m_tStartColorVar.a = 0.0f; + m_tEndColorVar.r = 0.0f; + m_tEndColorVar.g = 0.0f; + m_tEndColorVar.b = 0.0f; + m_tEndColorVar.a = 0.0f; + + setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png")); + return true; + } + + return false; +} + +void RainbowEffect::update(ccTime dt) +{ + m_fEmitCounter = 0; + CCParticleSystemQuad::update(dt); +} + + +void Issue1201::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + RainbowEffect *particle = new RainbowEffect(); + particle->initWithTotalParticles(50); + + addChild(particle); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + particle->setPosition(ccp(s.width/2, s.height/2)); + + m_emitter = particle; +} + +std::string Issue1201::title() +{ + return "Issue 1201. Unfinished"; +} + +std::string Issue1201::subtitle() +{ + return "Unfinished test. Ignore it"; +} + +void MultipleParticleSystems::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"); + + for (int i = 0; i<5; i++) { + CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/SpinningPeas.plist"); + + particleSystem->setPosition(ccp(i*50 ,i*50)); + + particleSystem->setPositionType(kCCPositionTypeGrouped); + addChild(particleSystem); + } + + m_emitter = NULL; + +} + std::string MultipleParticleSystems::title() { return "Multiple particle systems"; } -std::string MultipleParticleSystems::subtitle() -{ - return "v1.1 test: FPS should be lower than next test"; -} - -void MultipleParticleSystems::update(ccTime dt) -{ - CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); - - unsigned int count = 0; - - CCObject* pObj = NULL; - CCARRAY_FOREACH(m_pChildren, pObj) - { - CCParticleSystem* item = dynamic_cast(pObj); - if (item != NULL) - { - count += item->getParticleCount(); - } - } - char str[100] = {0}; - sprintf(str, "%4d", count); - atlas->setString(str); -} - -// MultipleParticleSystemsBatched - -void MultipleParticleSystemsBatched::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCParticleBatchNode *batchNode = new CCParticleBatchNode(); - batchNode->initWithTexture(NULL, 3000); - - addChild(batchNode, 1, 2); - - for (int i = 0; i<5; i++) { - - CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/SpinningPeas.plist"); - - particleSystem->setPositionType(kCCPositionTypeGrouped); - particleSystem->setPosition(ccp(i*50 ,i*50)); - - batchNode->setTexture(particleSystem->getTexture()); - batchNode->addChild(particleSystem); - } - - batchNode->release(); - - m_emitter = NULL; -} - -void MultipleParticleSystemsBatched::update(ccTime dt) -{ - CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); - - unsigned count = 0; - - CCNode* batchNode = getChildByTag(2); - CCObject* pObj = NULL; - CCARRAY_FOREACH(batchNode->getChildren(), pObj) - { - CCParticleSystem* item = dynamic_cast(pObj); - if (item != NULL) - { - count += item->getParticleCount(); - } - } - char str[50] = {0}; - sprintf(str, "%4d", count); - atlas->setString(str); -} - +std::string MultipleParticleSystems::subtitle() +{ + return "v1.1 test: FPS should be lower than next test"; +} + +void MultipleParticleSystems::update(ccTime dt) +{ + CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); + + unsigned int count = 0; + + CCObject* pObj = NULL; + CCARRAY_FOREACH(m_pChildren, pObj) + { + CCParticleSystem* item = dynamic_cast(pObj); + if (item != NULL) + { + count += item->getParticleCount(); + } + } + char str[100] = {0}; + sprintf(str, "%4d", count); + atlas->setString(str); +} + +// MultipleParticleSystemsBatched + +void MultipleParticleSystemsBatched::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCParticleBatchNode *batchNode = new CCParticleBatchNode(); + batchNode->initWithTexture(NULL, 3000); + + addChild(batchNode, 1, 2); + + for (int i = 0; i<5; i++) { + + CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/SpinningPeas.plist"); + + particleSystem->setPositionType(kCCPositionTypeGrouped); + particleSystem->setPosition(ccp(i*50 ,i*50)); + + batchNode->setTexture(particleSystem->getTexture()); + batchNode->addChild(particleSystem); + } + + batchNode->release(); + + m_emitter = NULL; +} + +void MultipleParticleSystemsBatched::update(ccTime dt) +{ + CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); + + unsigned count = 0; + + CCNode* batchNode = getChildByTag(2); + CCObject* pObj = NULL; + CCARRAY_FOREACH(batchNode->getChildren(), pObj) + { + CCParticleSystem* item = dynamic_cast(pObj); + if (item != NULL) + { + count += item->getParticleCount(); + } + } + char str[50] = {0}; + sprintf(str, "%4d", count); + atlas->setString(str); +} + std::string MultipleParticleSystemsBatched::title() { return "Multiple particle systems batched"; } -std::string MultipleParticleSystemsBatched::subtitle() -{ - return "v1.1 test: should perform better than previous test"; -} - -// AddAndDeleteParticleSystems - -void AddAndDeleteParticleSystems::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - //adds the texture inside the plist to the texture cache - m_pBatchNode = CCParticleBatchNode::batchNodeWithTexture(NULL, 16000); - - addChild(m_pBatchNode, 1, 2); - - for (int i = 0; i<6; i++) { - - CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/Spiral.plist"); - m_pBatchNode->setTexture(particleSystem->getTexture()); - - particleSystem->setPositionType(kCCPositionTypeGrouped); - particleSystem->setTotalParticles(200); - - particleSystem->setPosition(ccp(i*15 +100,i*15+100)); - - unsigned int randZ = rand() % 100; - m_pBatchNode->addChild(particleSystem, randZ, -1); - - } - - schedule(schedule_selector(AddAndDeleteParticleSystems::removeSystem), 0.5f); - m_emitter = NULL; - -} - -void AddAndDeleteParticleSystems::removeSystem(ccTime dt) -{ - int nChildrenCount = m_pBatchNode->getChildren()->count(); - if (nChildrenCount > 0) - { - CCLOG("remove random system"); - unsigned int uRand = rand() % (nChildrenCount - 1); - m_pBatchNode->removeChild((CCNode*)m_pBatchNode->getChildren()->objectAtIndex(uRand), true); - - CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/Spiral.plist"); - //add new - - particleSystem->setPositionType(kCCPositionTypeGrouped); - particleSystem->setTotalParticles(200); - - particleSystem->setPosition(ccp(rand() % 300 ,rand() % 400)); - - CCLOG("add a new system"); - unsigned int randZ = rand() % 100; - m_pBatchNode->addChild(particleSystem, randZ, -1); - } -} - -void AddAndDeleteParticleSystems::update(ccTime dt) -{ - CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); - - unsigned int count = 0; - - CCNode* batchNode = getChildByTag(2); - CCObject* pObj = NULL; - CCARRAY_FOREACH(batchNode->getChildren(), pObj) - { - CCParticleSystem* item = dynamic_cast(pObj); - if (item != NULL) - { - count += item->getParticleCount(); - } - } - char str[100] = {0}; - sprintf(str, "%4d", count); - atlas->setString(str); -} - +std::string MultipleParticleSystemsBatched::subtitle() +{ + return "v1.1 test: should perform better than previous test"; +} + +// AddAndDeleteParticleSystems + +void AddAndDeleteParticleSystems::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + //adds the texture inside the plist to the texture cache + m_pBatchNode = CCParticleBatchNode::batchNodeWithTexture(NULL, 16000); + + addChild(m_pBatchNode, 1, 2); + + for (int i = 0; i<6; i++) { + + CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/Spiral.plist"); + m_pBatchNode->setTexture(particleSystem->getTexture()); + + particleSystem->setPositionType(kCCPositionTypeGrouped); + particleSystem->setTotalParticles(200); + + particleSystem->setPosition(ccp(i*15 +100,i*15+100)); + + unsigned int randZ = rand() % 100; + m_pBatchNode->addChild(particleSystem, randZ, -1); + + } + + schedule(schedule_selector(AddAndDeleteParticleSystems::removeSystem), 0.5f); + m_emitter = NULL; + +} + +void AddAndDeleteParticleSystems::removeSystem(ccTime dt) +{ + int nChildrenCount = m_pBatchNode->getChildren()->count(); + if (nChildrenCount > 0) + { + CCLOG("remove random system"); + unsigned int uRand = rand() % (nChildrenCount - 1); + m_pBatchNode->removeChild((CCNode*)m_pBatchNode->getChildren()->objectAtIndex(uRand), true); + + CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/Spiral.plist"); + //add new + + particleSystem->setPositionType(kCCPositionTypeGrouped); + particleSystem->setTotalParticles(200); + + particleSystem->setPosition(ccp(rand() % 300 ,rand() % 400)); + + CCLOG("add a new system"); + unsigned int randZ = rand() % 100; + m_pBatchNode->addChild(particleSystem, randZ, -1); + } +} + +void AddAndDeleteParticleSystems::update(ccTime dt) +{ + CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); + + unsigned int count = 0; + + CCNode* batchNode = getChildByTag(2); + CCObject* pObj = NULL; + CCARRAY_FOREACH(batchNode->getChildren(), pObj) + { + CCParticleSystem* item = dynamic_cast(pObj); + if (item != NULL) + { + count += item->getParticleCount(); + } + } + char str[100] = {0}; + sprintf(str, "%4d", count); + atlas->setString(str); +} + std::string AddAndDeleteParticleSystems::title() { return "Add and remove Particle System"; } -std::string AddAndDeleteParticleSystems::subtitle() -{ - return "v1.1 test: every 2 sec 1 system disappear, 1 appears"; -} - -// ReorderParticleSystems - -void ReorderParticleSystems::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background ,true); - m_background = NULL; - - m_pBatchNode = CCParticleBatchNode::batchNodeWithFile("Images/stars-grayscale.png" ,3000); - - addChild(m_pBatchNode, 1, 2); - - - for (int i = 0; i<3; i++) { - - CCParticleSystemQuad* particleSystem = new CCParticleSystemQuad(); - particleSystem->initWithTotalParticles(200); - particleSystem->setTexture(m_pBatchNode->getTexture()); - - // duration - particleSystem->setDuration(kCCParticleDurationInfinity); - - // radius mode - particleSystem->setEmitterMode(kCCParticleModeRadius); - - // radius mode: 100 pixels from center - particleSystem->setStartRadius(100); - particleSystem->setStartRadiusVar(0); - particleSystem->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); - particleSystem->setEndRadiusVar(0); // not used when start == end - - // radius mode: degrees per second - // 45 * 4 seconds of life = 180 degrees - particleSystem->setRotatePerSecond(45); - particleSystem->setRotatePerSecondVar(0); - - - // angle - particleSystem->setAngle(90); - particleSystem->setAngleVar(0); - - // emitter position - particleSystem->setPosVar(CCPointZero); - - // life of particles - particleSystem->setLife(4); - particleSystem->setLifeVar(0); - - // spin of particles - particleSystem->setStartSpin(0); - particleSystem->setStartSpinVar(0); - particleSystem->setEndSpin(0); - particleSystem->setEndSpinVar(0); - - // color of particles - float color[3] = {0,0,0}; - color[i] = 1; - ccColor4F startColor = {color[0], color[1], color[2], 1.0f}; - particleSystem->setStartColor(startColor); - - ccColor4F startColorVar = {0, 0, 0, 0}; - particleSystem->setStartColorVar(startColorVar); - - ccColor4F endColor = startColor; - particleSystem->setEndColor(endColor); - - ccColor4F endColorVar = startColorVar; - particleSystem->setEndColorVar(endColorVar); - - // size, in pixels - particleSystem->setStartSize(32); - particleSystem->setStartSizeVar(0); - particleSystem->setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per second - particleSystem->setEmissionRate(particleSystem->getTotalParticles()/particleSystem->getLife()); - - // additive - - particleSystem->setPosition(ccp(i*10+120 ,200)); - - - m_pBatchNode->addChild(particleSystem); - particleSystem->setPositionType(kCCPositionTypeFree); - - particleSystem->release(); - - //[pBNode addChild:particleSystem z:10 tag:0); - - } - - schedule(schedule_selector(ReorderParticleSystems::reorderSystem), 2.0f); - m_emitter = NULL; - -} - -void ReorderParticleSystems::reorderSystem(ccTime time) -{ - CCParticleSystem* system = (CCParticleSystem*)m_pBatchNode->getChildren()->objectAtIndex(1); - m_pBatchNode->reorderChild(system, system->getZOrder() - 1); -} - - -void ReorderParticleSystems::update(ccTime dt) -{ - CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); - - unsigned int count = 0; - - CCNode* batchNode = getChildByTag(2); - CCObject* pObj = NULL; - CCARRAY_FOREACH(batchNode->getChildren(), pObj) - { - CCParticleSystem* item = dynamic_cast(pObj); - if (item != NULL) - { - count += item->getParticleCount(); - } - } - char str[100] = {0}; - sprintf(str, "%4d", count); - atlas->setString(str); -} - +std::string AddAndDeleteParticleSystems::subtitle() +{ + return "v1.1 test: every 2 sec 1 system disappear, 1 appears"; +} + +// ReorderParticleSystems + +void ReorderParticleSystems::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background ,true); + m_background = NULL; + + m_pBatchNode = CCParticleBatchNode::batchNodeWithFile("Images/stars-grayscale.png" ,3000); + + addChild(m_pBatchNode, 1, 2); + + + for (int i = 0; i<3; i++) { + + CCParticleSystemQuad* particleSystem = new CCParticleSystemQuad(); + particleSystem->initWithTotalParticles(200); + particleSystem->setTexture(m_pBatchNode->getTexture()); + + // duration + particleSystem->setDuration(kCCParticleDurationInfinity); + + // radius mode + particleSystem->setEmitterMode(kCCParticleModeRadius); + + // radius mode: 100 pixels from center + particleSystem->setStartRadius(100); + particleSystem->setStartRadiusVar(0); + particleSystem->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); + particleSystem->setEndRadiusVar(0); // not used when start == end + + // radius mode: degrees per second + // 45 * 4 seconds of life = 180 degrees + particleSystem->setRotatePerSecond(45); + particleSystem->setRotatePerSecondVar(0); + + + // angle + particleSystem->setAngle(90); + particleSystem->setAngleVar(0); + + // emitter position + particleSystem->setPosVar(CCPointZero); + + // life of particles + particleSystem->setLife(4); + particleSystem->setLifeVar(0); + + // spin of particles + particleSystem->setStartSpin(0); + particleSystem->setStartSpinVar(0); + particleSystem->setEndSpin(0); + particleSystem->setEndSpinVar(0); + + // color of particles + float color[3] = {0,0,0}; + color[i] = 1; + ccColor4F startColor = {color[0], color[1], color[2], 1.0f}; + particleSystem->setStartColor(startColor); + + ccColor4F startColorVar = {0, 0, 0, 0}; + particleSystem->setStartColorVar(startColorVar); + + ccColor4F endColor = startColor; + particleSystem->setEndColor(endColor); + + ccColor4F endColorVar = startColorVar; + particleSystem->setEndColorVar(endColorVar); + + // size, in pixels + particleSystem->setStartSize(32); + particleSystem->setStartSizeVar(0); + particleSystem->setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per second + particleSystem->setEmissionRate(particleSystem->getTotalParticles()/particleSystem->getLife()); + + // additive + + particleSystem->setPosition(ccp(i*10+120 ,200)); + + + m_pBatchNode->addChild(particleSystem); + particleSystem->setPositionType(kCCPositionTypeFree); + + particleSystem->release(); + + //[pBNode addChild:particleSystem z:10 tag:0); + + } + + schedule(schedule_selector(ReorderParticleSystems::reorderSystem), 2.0f); + m_emitter = NULL; + +} + +void ReorderParticleSystems::reorderSystem(ccTime time) +{ + CCParticleSystem* system = (CCParticleSystem*)m_pBatchNode->getChildren()->objectAtIndex(1); + m_pBatchNode->reorderChild(system, system->getZOrder() - 1); +} + + +void ReorderParticleSystems::update(ccTime dt) +{ + CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); + + unsigned int count = 0; + + CCNode* batchNode = getChildByTag(2); + CCObject* pObj = NULL; + CCARRAY_FOREACH(batchNode->getChildren(), pObj) + { + CCParticleSystem* item = dynamic_cast(pObj); + if (item != NULL) + { + count += item->getParticleCount(); + } + } + char str[100] = {0}; + sprintf(str, "%4d", count); + atlas->setString(str); +} + std::string ReorderParticleSystems::title() { return "reorder systems"; } -std::string ReorderParticleSystems::subtitle() -{ - return "changes every 2 seconds"; -} - - -void ParticleTestScene::runThisTest() -{ - addChild(nextParticleAction()); - - CCDirector::sharedDirector()->replaceScene(this); -} +std::string ReorderParticleSystems::subtitle() +{ + return "changes every 2 seconds"; +} + + +void ParticleTestScene::runThisTest() +{ + addChild(nextParticleAction()); + + CCDirector::sharedDirector()->replaceScene(this); +} diff --git a/tests/tests/RenderTextureTest/RenderTextureTest.cpp b/tests/tests/RenderTextureTest/RenderTextureTest.cpp index c92a0eba9e..da495a622e 100644 --- a/tests/tests/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/tests/RenderTextureTest/RenderTextureTest.cpp @@ -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)); +} + diff --git a/tests/tests/RotateWorldTest/RotateWorldTest.cpp b/tests/tests/RotateWorldTest/RotateWorldTest.cpp index 3d861a4648..0748575e96 100644 --- a/tests/tests/RotateWorldTest/RotateWorldTest.cpp +++ b/tests/tests/RotateWorldTest/RotateWorldTest.cpp @@ -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(); diff --git a/tests/tests/TileMapTest/TileMapTest.cpp b/tests/tests/TileMapTest/TileMapTest.cpp index 4d9c8aeb47..23b1cc1491 100644 --- a/tests/tests/TileMapTest/TileMapTest.cpp +++ b/tests/tests/TileMapTest/TileMapTest.cpp @@ -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();