2014-05-04 14:37:55 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2012 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "SpriteTest.h"
|
|
|
|
|
2016-10-27 09:45:40 +08:00
|
|
|
#include <cmath>
|
2014-05-04 14:37:55 +08:00
|
|
|
#include <algorithm>
|
2016-10-27 09:45:40 +08:00
|
|
|
|
2014-05-04 14:37:55 +08:00
|
|
|
#include "../testResource.h"
|
2015-12-04 10:43:39 +08:00
|
|
|
#include "editor-support/cocostudio/CocosStudioExtension.h"
|
2014-05-04 14:37:55 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2014-05-04 14:37:55 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
kTagTileMap = 1,
|
|
|
|
kTagSpriteBatchNode = 1,
|
|
|
|
kTagNode = 2,
|
|
|
|
kTagAnimation1 = 1,
|
|
|
|
kTagSpriteLeft,
|
|
|
|
kTagSpriteRight,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kTagSprite1,
|
|
|
|
kTagSprite2,
|
|
|
|
kTagSprite3,
|
|
|
|
kTagSprite4,
|
|
|
|
kTagSprite5,
|
|
|
|
kTagSprite6,
|
|
|
|
kTagSprite7,
|
|
|
|
kTagSprite8,
|
|
|
|
};
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
SpriteTests::SpriteTests()
|
|
|
|
{
|
2015-09-29 22:50:14 +08:00
|
|
|
ADD_TEST_CASE(Sprite1);
|
2016-07-25 17:31:54 +08:00
|
|
|
ADD_TEST_CASE(Sprite1ETC1Alpha);
|
2015-09-29 22:50:14 +08:00
|
|
|
ADD_TEST_CASE(SpriteBatchNode1);
|
|
|
|
ADD_TEST_CASE(SpriteAnchorPoint);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeAnchorPoint);
|
2015-12-14 23:17:41 +08:00
|
|
|
ADD_TEST_CASE(SpriteAnchorPointFromFile);
|
2015-09-29 22:50:14 +08:00
|
|
|
ADD_TEST_CASE(SpriteOffsetAnchorRotation);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorRotation);
|
|
|
|
ADD_TEST_CASE(SpriteOffsetAnchorScale);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorScale);
|
|
|
|
ADD_TEST_CASE(SpriteOffsetAnchorSkew);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorSkew);
|
|
|
|
ADD_TEST_CASE(SpriteOffsetAnchorRotationalSkew);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorRotationalSkew);
|
|
|
|
ADD_TEST_CASE(SpriteOffsetAnchorSkewScale);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorSkewScale);
|
|
|
|
ADD_TEST_CASE(SpriteOffsetAnchorRotationalSkewScale);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorRotationalSkewScale);
|
|
|
|
ADD_TEST_CASE(SpriteSkewNegativeScaleChildren);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeSkewNegativeScaleChildren);
|
|
|
|
ADD_TEST_CASE(SpriteRotationalSkewNegativeScaleChildren);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeRotationalSkewNegativeScaleChildren);
|
|
|
|
ADD_TEST_CASE(SpriteOffsetAnchorFlip);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorFlip);
|
|
|
|
ADD_TEST_CASE(SpriteChildrenChildren);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeChildrenChildren);
|
|
|
|
ADD_TEST_CASE(SpriteChildrenAnchorPoint);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeChildrenAnchorPoint);
|
|
|
|
ADD_TEST_CASE(SpriteColorOpacity);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeColorOpacity);
|
|
|
|
ADD_TEST_CASE(SpriteZOrder);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeZOrder);
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
// ADD_TEST_CASE(SpriteZVertex); // TODO shouldn't call OpenGL API directly
|
|
|
|
// ADD_TEST_CASE(SpriteBatchNodeZVertex);
|
2015-09-29 22:50:14 +08:00
|
|
|
ADD_TEST_CASE(SpriteAliased);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeAliased);
|
|
|
|
ADD_TEST_CASE(SpriteNewTexture);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeNewTexture);
|
|
|
|
ADD_TEST_CASE(SpriteFlip);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeFlip);
|
|
|
|
ADD_TEST_CASE(SpriteAnimationSplit);
|
|
|
|
ADD_TEST_CASE(SpriteFrameTest);
|
|
|
|
ADD_TEST_CASE(SpriteFrameAliasNameTest);
|
2015-09-29 21:44:13 +08:00
|
|
|
ADD_TEST_CASE(SpriteFramesFromFileContent);
|
|
|
|
ADD_TEST_CASE(SpritePolygonFromFileContent);
|
2015-09-29 22:50:14 +08:00
|
|
|
ADD_TEST_CASE(SpriteBatchNodeReorder);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeReorderIssue744);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeReorderIssue766);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeReorderIssue767);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeReorderSameIndex);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeReorderOneChild);
|
|
|
|
ADD_TEST_CASE(NodeSort);
|
|
|
|
ADD_TEST_CASE(Sprite6);
|
|
|
|
ADD_TEST_CASE(SpriteHybrid);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeChildren);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeChildrenZ);
|
|
|
|
ADD_TEST_CASE(SpriteChildrenVisibility);
|
|
|
|
ADD_TEST_CASE(SpriteChildrenVisibilityIssue665);
|
|
|
|
ADD_TEST_CASE(SpriteBatchNodeChildrenScale);
|
|
|
|
ADD_TEST_CASE(SpriteNilTexture);
|
|
|
|
ADD_TEST_CASE(SpriteSubclass);
|
|
|
|
ADD_TEST_CASE(SpriteBatchBug1217);
|
|
|
|
ADD_TEST_CASE(AnimationCacheTest);
|
|
|
|
ADD_TEST_CASE(AnimationCacheFile);
|
|
|
|
ADD_TEST_CASE(SpriteCullTest1);
|
|
|
|
ADD_TEST_CASE(SpriteCullTest2);
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(Sprite3DRotationTest);
|
2016-10-27 09:45:40 +08:00
|
|
|
ADD_TEST_CASE(SpriteGetSpriteFrameTest);
|
|
|
|
ADD_TEST_CASE(SpriteSlice9Test1);
|
|
|
|
ADD_TEST_CASE(SpriteSlice9Test2);
|
|
|
|
ADD_TEST_CASE(SpriteSlice9Test3);
|
|
|
|
ADD_TEST_CASE(SpriteSlice9Test4);
|
|
|
|
ADD_TEST_CASE(SpriteSlice9Test5);
|
|
|
|
ADD_TEST_CASE(SpriteSlice9Test6);
|
|
|
|
ADD_TEST_CASE(SpriteSlice9Test7);
|
|
|
|
ADD_TEST_CASE(SpriteSlice9Test8);
|
|
|
|
ADD_TEST_CASE(SpriteSlice9Test9);
|
2016-10-30 08:52:33 +08:00
|
|
|
ADD_TEST_CASE(SpriteSlice9Test10);
|
2017-01-10 15:28:47 +08:00
|
|
|
ADD_TEST_CASE(Issue17119);
|
2014-05-04 14:37:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Sprite1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
Sprite1::Sprite1()
|
|
|
|
{
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(Sprite1::onTouchesEnded, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Sprite1::addNewSpriteWithCoords(Vec2 p)
|
2014-05-04 14:37:55 +08:00
|
|
|
{
|
|
|
|
int idx = (int)(CCRANDOM_0_1() * 1400.0f / 100.0f);
|
|
|
|
int x = (idx%5) * 85;
|
|
|
|
int y = (idx/5) * 121;
|
|
|
|
|
|
|
|
|
|
|
|
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(x,y,85,121) );
|
|
|
|
addChild( sprite );
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( p.x, p.y) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
ActionInterval* action;
|
|
|
|
float random = CCRANDOM_0_1();
|
|
|
|
|
|
|
|
if( random < 0.20 )
|
|
|
|
action = ScaleBy::create(3, 2);
|
|
|
|
else if(random < 0.40)
|
|
|
|
action = RotateBy::create(3, 360);
|
|
|
|
else if( random < 0.60)
|
|
|
|
action = Blink::create(1, 3);
|
|
|
|
else if( random < 0.8 )
|
|
|
|
action = TintBy::create(2, 0, -255, -255);
|
|
|
|
else
|
|
|
|
action = FadeOut::create(2);
|
|
|
|
auto action_back = action->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create( action, action_back, nullptr );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite->runAction( RepeatForever::create(seq) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite1::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
|
|
|
{
|
|
|
|
for (auto touch: touches)
|
|
|
|
{
|
|
|
|
auto location = touch->getLocation();
|
|
|
|
|
|
|
|
addNewSpriteWithCoords( location );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Sprite1::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Sprite1::subtitle() const
|
|
|
|
{
|
|
|
|
return "Tap screen to add more sprites";
|
|
|
|
}
|
|
|
|
|
2016-07-25 17:31:54 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Sprite1ETC1Alpha
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
Sprite1ETC1Alpha::Sprite1ETC1Alpha()
|
|
|
|
{
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(Sprite1ETC1Alpha::onTouchesEnded, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sprite1ETC1Alpha::init()
|
|
|
|
{
|
|
|
|
if (!SpriteTestDemo::init())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_background = Sprite::create("Images/background2.png");
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
_background->setPosition(Vec2(s.width / 2, s.height / 2));
|
|
|
|
this->addChild(_background);
|
|
|
|
|
|
|
|
addNewSpriteWithCoords(Vec2(s.width / 2, s.height / 2));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite1ETC1Alpha::addNewSpriteWithCoords(Vec2 p)
|
|
|
|
{
|
2016-09-30 09:42:21 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossini_dance_08.png");
|
|
|
|
Texture2D *etcTexture = _director->getTextureCache()->addImage("Images/etc1-alpha.pkm");
|
|
|
|
sprite->setTexture(etcTexture);
|
|
|
|
|
2016-07-25 17:31:54 +08:00
|
|
|
_background->addChild(sprite);
|
|
|
|
|
|
|
|
sprite->setPosition(Vec2(p.x, p.y));
|
|
|
|
|
|
|
|
ActionInterval* action;
|
|
|
|
float random = CCRANDOM_0_1();
|
|
|
|
|
|
|
|
if (random < 0.20)
|
|
|
|
action = ScaleBy::create(3, 2);
|
|
|
|
else if (random < 0.40)
|
|
|
|
action = RotateBy::create(3, 360);
|
|
|
|
else if (random < 0.60)
|
|
|
|
action = Blink::create(1, 3);
|
|
|
|
else if (random < 0.8)
|
|
|
|
action = TintBy::create(2, 0, -255, -255);
|
|
|
|
else
|
|
|
|
action = FadeOut::create(2);
|
|
|
|
auto action_back = action->reverse();
|
|
|
|
auto seq = Sequence::create(action, action_back, nullptr);
|
|
|
|
|
|
|
|
sprite->runAction(RepeatForever::create(seq));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite1ETC1Alpha::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
|
|
|
{
|
|
|
|
for (auto touch : touches)
|
|
|
|
{
|
|
|
|
auto location = touch->getLocation();
|
|
|
|
|
|
|
|
addNewSpriteWithCoords(location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Sprite1ETC1Alpha::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite ETC1 Alpha support";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Sprite1ETC1Alpha::subtitle() const
|
|
|
|
{
|
|
|
|
return "Tap screen to add more sprites";
|
|
|
|
}
|
|
|
|
|
2014-05-04 14:37:55 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNode1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNode1::SpriteBatchNode1()
|
|
|
|
{
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(SpriteBatchNode1::onTouchesEnded, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
|
|
|
auto BatchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);
|
|
|
|
addChild(BatchNode, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void SpriteBatchNode1::addNewSpriteWithCoords(Vec2 p)
|
2014-05-04 14:37:55 +08:00
|
|
|
{
|
|
|
|
auto BatchNode = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
|
|
|
|
|
|
|
|
int idx = CCRANDOM_0_1() * 1400 / 100;
|
|
|
|
int x = (idx%5) * 85;
|
|
|
|
int y = (idx/5) * 121;
|
|
|
|
|
|
|
|
|
|
|
|
auto sprite = Sprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121));
|
|
|
|
BatchNode->addChild(sprite);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( p.x, p.y) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
ActionInterval* action;
|
|
|
|
float random = CCRANDOM_0_1();
|
|
|
|
|
|
|
|
if( random < 0.20 )
|
|
|
|
action = ScaleBy::create(3, 2);
|
|
|
|
else if(random < 0.40)
|
|
|
|
action = RotateBy::create(3, 360);
|
|
|
|
else if( random < 0.60)
|
|
|
|
action = Blink::create(1, 3);
|
|
|
|
else if( random < 0.8 )
|
|
|
|
action = TintBy::create(2, 0, -255, -255);
|
|
|
|
else
|
|
|
|
action = FadeOut::create(2);
|
|
|
|
|
|
|
|
auto action_back = action->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(action, action_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite->runAction( RepeatForever::create(seq));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNode1::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
|
|
|
{
|
|
|
|
for (auto &touch: touches)
|
|
|
|
{
|
|
|
|
auto location = touch->getLocation();
|
|
|
|
|
|
|
|
addNewSpriteWithCoords( location );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNode1::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNode1::subtitle() const
|
|
|
|
{
|
|
|
|
return "SpriteBatchNode: Tap screen to add more sprites";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteColorOpacity
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteColorOpacity::SpriteColorOpacity()
|
|
|
|
{
|
|
|
|
auto sprite1 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*0, 121*1, 85, 121));
|
|
|
|
auto sprite2 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*1, 121*1, 85, 121));
|
|
|
|
auto sprite3 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*2, 121*1, 85, 121));
|
|
|
|
auto sprite4 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*3, 121*1, 85, 121));
|
|
|
|
|
|
|
|
auto sprite5 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*0, 121*1, 85, 121));
|
|
|
|
auto sprite6 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*1, 121*1, 85, 121));
|
|
|
|
auto sprite7 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*2, 121*1, 85, 121));
|
|
|
|
auto sprite8 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*3, 121*1, 85, 121));
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( (s.width/5)*1, (s.height/3)*1) );
|
|
|
|
sprite2->setPosition( Vec2( (s.width/5)*2, (s.height/3)*1) );
|
|
|
|
sprite3->setPosition( Vec2( (s.width/5)*3, (s.height/3)*1) );
|
|
|
|
sprite4->setPosition( Vec2( (s.width/5)*4, (s.height/3)*1) );
|
|
|
|
sprite5->setPosition( Vec2( (s.width/5)*1, (s.height/3)*2) );
|
|
|
|
sprite6->setPosition( Vec2( (s.width/5)*2, (s.height/3)*2) );
|
|
|
|
sprite7->setPosition( Vec2( (s.width/5)*3, (s.height/3)*2) );
|
|
|
|
sprite8->setPosition( Vec2( (s.width/5)*4, (s.height/3)*2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto action = FadeIn::create(2);
|
|
|
|
auto action_back = action->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto fade = RepeatForever::create( Sequence::create( action, action_back, nullptr) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto tintred = TintBy::create(2, 0, -255, -255);
|
|
|
|
auto tintred_back = tintred->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto red = RepeatForever::create( Sequence::create( tintred, tintred_back, nullptr) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto tintgreen = TintBy::create(2, -255, 0, -255);
|
|
|
|
auto tintgreen_back = tintgreen->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto green = RepeatForever::create( Sequence::create( tintgreen, tintgreen_back, nullptr) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto tintblue = TintBy::create(2, -255, -255, 0);
|
|
|
|
auto tintblue_back = tintblue->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto blue = RepeatForever::create( Sequence::create( tintblue, tintblue_back, nullptr) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite5->runAction(red);
|
|
|
|
sprite6->runAction(green);
|
|
|
|
sprite7->runAction(blue);
|
|
|
|
sprite8->runAction(fade);
|
|
|
|
|
|
|
|
// late add: test dirtyColor and dirtyPosition
|
|
|
|
addChild(sprite1, 0, kTagSprite1);
|
|
|
|
addChild(sprite2, 0, kTagSprite2);
|
|
|
|
addChild(sprite3, 0, kTagSprite3);
|
|
|
|
addChild(sprite4, 0, kTagSprite4);
|
|
|
|
addChild(sprite5, 0, kTagSprite5);
|
|
|
|
addChild(sprite6, 0, kTagSprite6);
|
|
|
|
addChild(sprite7, 0, kTagSprite7);
|
|
|
|
addChild(sprite8, 0, kTagSprite8);
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule( CC_CALLBACK_1(SpriteColorOpacity::removeAndAddSprite, this), 2, "remove_add_key" );
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// this function test if remove and add works as expected:
|
|
|
|
// color array and vertex array should be reindexed
|
|
|
|
void SpriteColorOpacity::removeAndAddSprite(float dt)
|
|
|
|
{
|
|
|
|
auto sprite = static_cast<Sprite*>( getChildByTag(kTagSprite5) );
|
|
|
|
sprite->retain();
|
|
|
|
|
|
|
|
removeChild(sprite, false);
|
|
|
|
addChild(sprite, 0, kTagSprite5);
|
|
|
|
|
|
|
|
sprite->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteColorOpacity::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteColorOpacity::subtitle() const
|
|
|
|
{
|
|
|
|
return "Color & Opacity";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeColorOpacity
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeColorOpacity::SpriteBatchNodeColorOpacity()
|
|
|
|
{
|
|
|
|
// small capacity. Testing resizing.
|
|
|
|
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
|
|
|
|
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
auto sprite1 = Sprite::createWithTexture(batch->getTexture(), Rect(85*0, 121*1, 85, 121));
|
|
|
|
auto sprite2 = Sprite::createWithTexture(batch->getTexture(), Rect(85*1, 121*1, 85, 121));
|
|
|
|
auto sprite3 = Sprite::createWithTexture(batch->getTexture(), Rect(85*2, 121*1, 85, 121));
|
|
|
|
auto sprite4 = Sprite::createWithTexture(batch->getTexture(), Rect(85*3, 121*1, 85, 121));
|
|
|
|
|
|
|
|
auto sprite5 = Sprite::createWithTexture(batch->getTexture(), Rect(85*0, 121*1, 85, 121));
|
|
|
|
auto sprite6 = Sprite::createWithTexture(batch->getTexture(), Rect(85*1, 121*1, 85, 121));
|
|
|
|
auto sprite7 = Sprite::createWithTexture(batch->getTexture(), Rect(85*2, 121*1, 85, 121));
|
|
|
|
auto sprite8 = Sprite::createWithTexture(batch->getTexture(), Rect(85*3, 121*1, 85, 121));
|
|
|
|
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( (s.width/5)*1, (s.height/3)*1) );
|
|
|
|
sprite2->setPosition( Vec2( (s.width/5)*2, (s.height/3)*1) );
|
|
|
|
sprite3->setPosition( Vec2( (s.width/5)*3, (s.height/3)*1) );
|
|
|
|
sprite4->setPosition( Vec2( (s.width/5)*4, (s.height/3)*1) );
|
|
|
|
sprite5->setPosition( Vec2( (s.width/5)*1, (s.height/3)*2) );
|
|
|
|
sprite6->setPosition( Vec2( (s.width/5)*2, (s.height/3)*2) );
|
|
|
|
sprite7->setPosition( Vec2( (s.width/5)*3, (s.height/3)*2) );
|
|
|
|
sprite8->setPosition( Vec2( (s.width/5)*4, (s.height/3)*2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto action = FadeIn::create(2);
|
|
|
|
auto action_back = action->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto fade = RepeatForever::create( Sequence::create( action, action_back,nullptr) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto tintred = TintBy::create(2, 0, -255, -255);
|
|
|
|
auto tintred_back = tintred->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto red = RepeatForever::create( Sequence::create( tintred, tintred_back,nullptr) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto tintgreen = TintBy::create(2, -255, 0, -255);
|
|
|
|
auto tintgreen_back = tintgreen->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto green = RepeatForever::create( Sequence::create( tintgreen, tintgreen_back,nullptr) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto tintblue = TintBy::create(2, -255, -255, 0);
|
|
|
|
auto tintblue_back = tintblue->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto blue = RepeatForever::create( Sequence::create( tintblue, tintblue_back,nullptr) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
sprite5->runAction(red);
|
|
|
|
sprite6->runAction(green);
|
|
|
|
sprite7->runAction(blue);
|
|
|
|
sprite8->runAction(fade);
|
|
|
|
|
|
|
|
// late add: test dirtyColor and dirtyPosition
|
|
|
|
batch->addChild(sprite1, 0, kTagSprite1);
|
|
|
|
batch->addChild(sprite2, 0, kTagSprite2);
|
|
|
|
batch->addChild(sprite3, 0, kTagSprite3);
|
|
|
|
batch->addChild(sprite4, 0, kTagSprite4);
|
|
|
|
batch->addChild(sprite5, 0, kTagSprite5);
|
|
|
|
batch->addChild(sprite6, 0, kTagSprite6);
|
|
|
|
batch->addChild(sprite7, 0, kTagSprite7);
|
|
|
|
batch->addChild(sprite8, 0, kTagSprite8);
|
|
|
|
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule( CC_CALLBACK_1(SpriteBatchNodeColorOpacity::removeAndAddSprite, this), 2, "remove_add_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// this function test if remove and add works as expected:
|
|
|
|
// color array and vertex array should be reindexed
|
|
|
|
void SpriteBatchNodeColorOpacity::removeAndAddSprite(float dt)
|
|
|
|
{
|
|
|
|
auto batch= static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
|
|
|
|
auto sprite = static_cast<Sprite*>( batch->getChildByTag(kTagSprite5) );
|
|
|
|
|
|
|
|
sprite->retain();
|
|
|
|
|
|
|
|
batch->removeChild(sprite, false);
|
|
|
|
batch->addChild(sprite, 0, kTagSprite5);
|
|
|
|
|
|
|
|
sprite->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeColorOpacity::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeColorOpacity::subtitle() const
|
|
|
|
{
|
|
|
|
return "Color & Opacity";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteZOrder
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteZOrder::SpriteZOrder()
|
|
|
|
{
|
|
|
|
_dir = 1;
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
float step = s.width/11;
|
|
|
|
for(int i=0;i<5;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*0, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( (i+1)*step, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(sprite, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=5;i<10;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*1, 121*0, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( (i+1)*step, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(sprite, 14-i);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*3, 121*0, 85, 121));
|
|
|
|
addChild(sprite, -1, kTagSprite1);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2(s.width/2, s.height/2 - 20) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->setScaleX( 6 );
|
|
|
|
sprite->setColor(Color3B::RED);
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule( CC_CALLBACK_1(SpriteZOrder::reorderSprite, this), 1, "reorder_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteZOrder::reorderSprite(float dt)
|
|
|
|
{
|
|
|
|
auto sprite = static_cast<Sprite*>( getChildByTag(kTagSprite1) );
|
|
|
|
|
|
|
|
int z = sprite->getLocalZOrder();
|
|
|
|
|
|
|
|
if( z < -1 )
|
|
|
|
_dir = 1;
|
|
|
|
if( z > 10 )
|
|
|
|
_dir = -1;
|
|
|
|
|
|
|
|
z += _dir * 3;
|
|
|
|
|
|
|
|
reorderChild(sprite, z);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteZOrder::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteZOrder::subtitle() const
|
|
|
|
{
|
|
|
|
return "Z order";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeZOrder
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeZOrder::SpriteBatchNodeZOrder()
|
|
|
|
{
|
|
|
|
_dir = 1;
|
|
|
|
|
|
|
|
// small capacity. Testing resizing.
|
|
|
|
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
|
|
|
|
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
float step = s.width/11;
|
|
|
|
for(int i=0;i<5;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85*0, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( (i+1)*step, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
batch->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=5;i<10;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85*1, 121*0, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( (i+1)*step, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
batch->addChild(sprite, 14-i);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85*3, 121*0, 85, 121));
|
|
|
|
batch->addChild(sprite, -1, kTagSprite1);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2(s.width/2, s.height/2 - 20) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->setScaleX( 6 );
|
|
|
|
sprite->setColor(Color3B::RED);
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule( CC_CALLBACK_1(SpriteBatchNodeZOrder::reorderSprite, this), 1, "reorder_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeZOrder::reorderSprite(float dt)
|
|
|
|
{
|
|
|
|
auto batch= static_cast<SpriteBatchNode*>( getChildByTag( kTagSpriteBatchNode ));
|
|
|
|
auto sprite = static_cast<Sprite*>(batch->getChildByTag(kTagSprite1));
|
|
|
|
|
|
|
|
int z = sprite->getLocalZOrder();
|
|
|
|
|
|
|
|
if( z < -1 )
|
|
|
|
_dir = 1;
|
|
|
|
if( z > 10 )
|
|
|
|
_dir = -1;
|
|
|
|
|
|
|
|
z += _dir * 3;
|
|
|
|
|
|
|
|
batch->reorderChild(sprite, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeZOrder::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeZOrder::subtitle() const
|
|
|
|
{
|
|
|
|
return "Z order";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeReorder
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeReorder::SpriteBatchNodeReorder()
|
|
|
|
{
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
Vector<Sprite*> a;
|
2014-05-04 14:37:55 +08:00
|
|
|
auto asmtest = SpriteBatchNode::create("animations/ghosts.png");
|
|
|
|
|
|
|
|
for(int i=0; i<10; i++)
|
|
|
|
{
|
2019-09-24 11:31:35 +08:00
|
|
|
auto s1 = Sprite::createWithTexture(asmtest->getTexture(), Rect(0.0f, 0.0f, 50.0f, 50.0f));
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
a.pushBack(s1);
|
2014-05-04 14:37:55 +08:00
|
|
|
asmtest->addChild(s1, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0; i<10; i++)
|
|
|
|
{
|
|
|
|
if(i!=5)
|
|
|
|
{
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
asmtest->reorderChild( static_cast<Node*>(a.at(i)), 9 );
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t CC_UNUSED prev = -1;
|
|
|
|
|
|
|
|
auto& children = asmtest->getChildren();
|
|
|
|
|
|
|
|
for(const auto &obj : children) {
|
|
|
|
auto child = static_cast<Sprite*>(obj);
|
|
|
|
|
|
|
|
ssize_t currentIndex = child->getAtlasIndex();
|
|
|
|
CCASSERT( prev == currentIndex-1, "Child order failed");
|
|
|
|
////----CCLOG("children %x - atlasIndex:%d", child, currentIndex);
|
|
|
|
prev = currentIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = -1;
|
|
|
|
auto& descendants = asmtest->getDescendants();
|
|
|
|
for(const auto &sprite : descendants) {
|
|
|
|
ssize_t currentIndex = sprite->getAtlasIndex();
|
|
|
|
CCASSERT( prev == currentIndex-1, "Child order failed");
|
|
|
|
////----CCLOG("descendant %x - atlasIndex:%d", child, currentIndex);
|
|
|
|
prev = currentIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorder::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorder::subtitle() const
|
|
|
|
{
|
|
|
|
return "reorder #1. Should not crash";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeReorderIssue744
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeReorderIssue744::SpriteBatchNodeReorderIssue744()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
|
|
// Testing issue #744
|
|
|
|
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=744
|
|
|
|
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 15);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
auto sprite = Sprite::createWithTexture(batch->getTexture(),Rect(0, 0, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2(s.width/2, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
batch->addChild(sprite, 3);
|
|
|
|
batch->reorderChild(sprite, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorderIssue744::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorderIssue744::subtitle() const
|
|
|
|
{
|
|
|
|
return "reorder issue #744. Should not crash";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeReorderIssue766
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
Sprite* SpriteBatchNodeReorderIssue766::makeSpriteZ(int aZ)
|
|
|
|
{
|
2015-08-10 17:07:46 +08:00
|
|
|
Rect rcw(128,0,64,64);
|
|
|
|
rcw = CC_RECT_PIXELS_TO_POINTS(rcw);
|
|
|
|
auto sprite = Sprite::createWithTexture(batchNode->getTexture(), rcw);
|
|
|
|
sprite->setScale(CC_CONTENT_SCALE_FACTOR());
|
2014-05-04 14:37:55 +08:00
|
|
|
batchNode->addChild(sprite, aZ+1, 0);
|
|
|
|
|
|
|
|
//children
|
2015-08-10 17:07:46 +08:00
|
|
|
Rect rc1(0,0,64,64);
|
|
|
|
rc1 = CC_RECT_PIXELS_TO_POINTS(rc1);
|
|
|
|
auto spriteShadow = Sprite::createWithTexture(batchNode->getTexture(), rc1);
|
2014-05-04 14:37:55 +08:00
|
|
|
spriteShadow->setOpacity(128);
|
2015-08-10 17:07:46 +08:00
|
|
|
sprite->setScale(CC_CONTENT_SCALE_FACTOR());
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->addChild(spriteShadow, aZ, 3);
|
|
|
|
|
2015-08-10 17:07:46 +08:00
|
|
|
Rect rc2(64,0,64,64);
|
|
|
|
rc2 = CC_RECT_PIXELS_TO_POINTS(rc2);
|
|
|
|
auto spriteTop = Sprite::createWithTexture(batchNode->getTexture(), rc2);
|
|
|
|
sprite->setScale(CC_CONTENT_SCALE_FACTOR());
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->addChild(spriteTop, aZ+2, 3);
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeReorderIssue766::reorderSprite(float dt)
|
|
|
|
{
|
2014-10-04 08:11:39 +08:00
|
|
|
unschedule("issue_766_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
batchNode->reorderChild(sprite1, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// on "init" you need to initialize your instance
|
|
|
|
SpriteBatchNodeReorderIssue766::SpriteBatchNodeReorderIssue766()
|
|
|
|
{
|
|
|
|
batchNode = SpriteBatchNode::create("Images/piece.png", 15);
|
|
|
|
addChild(batchNode, 1, 0);
|
|
|
|
|
|
|
|
sprite1 = makeSpriteZ(2);
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite1->setPosition(Vec2(200.0f,160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = makeSpriteZ(3);
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(264.0f,160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = makeSpriteZ(4);
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(328.0f,160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule(CC_CALLBACK_1(SpriteBatchNodeReorderIssue766::reorderSprite, this), 2, "issue_766_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorderIssue766::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorderIssue766::subtitle() const
|
|
|
|
{
|
|
|
|
return "reorder issue #766. In 2 seconds 1 sprite will be reordered";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeReorderIssue767
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteBatchNodeReorderIssue767::SpriteBatchNodeReorderIssue767()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist", "animations/ghosts.png");
|
|
|
|
Node *aParent;
|
|
|
|
Sprite *l1, *l2a, *l2b, *l3a1, *l3a2, *l3b1, *l3b2;
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteBatchNode: 3 levels of children
|
|
|
|
//
|
|
|
|
aParent = SpriteBatchNode::create("animations/ghosts.png");
|
|
|
|
addChild(aParent, 0, kTagSprite1);
|
|
|
|
|
|
|
|
// parent
|
|
|
|
l1 = Sprite::createWithSpriteFrameName("father.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l1->setPosition(Vec2( s.width/2, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
aParent->addChild(l1, 0, kTagSprite2);
|
|
|
|
auto l1Size = l1->getContentSize();
|
|
|
|
|
|
|
|
// child left
|
|
|
|
l2a = Sprite::createWithSpriteFrameName("sister1.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l2a->setPosition(Vec2( -25 + l1Size.width/2, 0 + l1Size.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l1->addChild(l2a, -1, kTagSpriteLeft);
|
|
|
|
auto l2aSize = l2a->getContentSize();
|
|
|
|
|
|
|
|
|
|
|
|
// child right
|
|
|
|
l2b = Sprite::createWithSpriteFrameName("sister2.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l2b->setPosition(Vec2( +25 + l1Size.width/2, 0 + l1Size.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l1->addChild(l2b, 1, kTagSpriteRight);
|
|
|
|
auto l2bSize = l2a->getContentSize();
|
|
|
|
|
|
|
|
|
|
|
|
// child left bottom
|
|
|
|
l3a1 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3a1->setScale(0.65f);
|
2014-05-15 01:07:09 +08:00
|
|
|
l3a1->setPosition(Vec2(0+l2aSize.width/2,-50+l2aSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->addChild(l3a1, -1);
|
|
|
|
|
|
|
|
// child left top
|
|
|
|
l3a2 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3a2->setScale(0.65f);
|
2014-05-15 01:07:09 +08:00
|
|
|
l3a2->setPosition(Vec2(0+l2aSize.width/2,+50+l2aSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->addChild(l3a2, 1);
|
|
|
|
|
|
|
|
// child right bottom
|
|
|
|
l3b1 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3b1->setScale(0.65f);
|
2014-05-15 01:07:09 +08:00
|
|
|
l3b1->setPosition(Vec2(0+l2bSize.width/2,-50+l2bSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->addChild(l3b1, -1);
|
|
|
|
|
|
|
|
// child right top
|
|
|
|
l3b2 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3b2->setScale(0.65f);
|
2014-05-15 01:07:09 +08:00
|
|
|
l3b2->setPosition(Vec2(0+l2bSize.width/2,+50+l2bSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->addChild(l3b2, 1);
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule(CC_CALLBACK_1(SpriteBatchNodeReorderIssue767::reorderSprites, this), 1, "issue_767_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorderIssue767::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorderIssue767::subtitle() const
|
|
|
|
{
|
|
|
|
return "reorder issue #767. Should not crash";
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeReorderIssue767::reorderSprites(float dt)
|
|
|
|
{
|
|
|
|
auto spritebatch = static_cast<SpriteBatchNode*>( getChildByTag(kTagSprite1) );
|
|
|
|
auto father = static_cast<Sprite*>( spritebatch->getChildByTag(kTagSprite2) );
|
|
|
|
auto left = static_cast<Sprite*>( father->getChildByTag(kTagSpriteLeft) );
|
|
|
|
auto right = static_cast<Sprite*>( father->getChildByTag(kTagSpriteRight) );
|
|
|
|
|
|
|
|
int newZLeft = 1;
|
|
|
|
|
|
|
|
if( left->getLocalZOrder() == 1 )
|
|
|
|
newZLeft = -1;
|
|
|
|
|
|
|
|
father->reorderChild(left, newZLeft);
|
|
|
|
father->reorderChild(right, -newZLeft);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteZVertex
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SpriteZVertex::onEnter()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onEnter();
|
|
|
|
|
|
|
|
Director::getInstance()->setProjection(Director::Projection::_3D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteZVertex::onExit()
|
|
|
|
{
|
|
|
|
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteZVertex::SpriteZVertex()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// This test tests z-order
|
|
|
|
// If you are going to use it is better to use a 3D projection
|
|
|
|
//
|
|
|
|
// WARNING:
|
2017-02-10 10:35:52 +08:00
|
|
|
// The developer is responsible for ordering its sprites according to its Z if the sprite has
|
2014-05-04 14:37:55 +08:00
|
|
|
// transparent parts.
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Configure shader to mimic glAlphaTest
|
|
|
|
//
|
2019-02-19 16:06:17 +08:00
|
|
|
// auto alphaTestShader = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
|
|
|
|
// GLint alphaValueLocation = glGetUniformLocation(alphaTestShader->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
|
|
|
|
//
|
|
|
|
// // set alpha test value
|
|
|
|
// // NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
|
|
|
|
// if (getGLProgram())
|
|
|
|
// {
|
|
|
|
// getGLProgram()->setUniformLocationWith1f(alphaValueLocation, 0.0f);
|
|
|
|
// }
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
_dir = 1;
|
|
|
|
_time = 0;
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
float step = s.width/12;
|
|
|
|
|
|
|
|
auto node = Node::create();
|
|
|
|
// camera uses the center of the image as the pivoting point
|
|
|
|
node->setContentSize( Size(s.width,s.height) );
|
2014-05-15 01:07:09 +08:00
|
|
|
node->setAnchorPoint( Vec2::ANCHOR_MIDDLE);
|
|
|
|
node->setPosition( Vec2(s.width/2, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
addChild(node, 0);
|
|
|
|
|
|
|
|
for(int i=0;i<5;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*0, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2((i+1)*step, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->setPositionZ( 10 + i*40 );
|
2019-02-19 16:06:17 +08:00
|
|
|
// sprite->setGLProgram(alphaTestShader);
|
2014-05-04 14:37:55 +08:00
|
|
|
node->addChild(sprite, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=5;i<11;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*1, 121*0, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( (i+1)*step, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->setPositionZ( 10 + (10-i)*40 );
|
2019-02-19 16:06:17 +08:00
|
|
|
// sprite->setGLProgram(alphaTestShader);
|
2014-05-04 14:37:55 +08:00
|
|
|
node->addChild(sprite, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
node->runAction( OrbitCamera::create(10, 1, 0, 0, 360, 0, 0) );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteZVertex::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteZVertex::subtitle() const
|
|
|
|
{
|
|
|
|
return "openGL Z vertex";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeZVertex
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SpriteBatchNodeZVertex::onEnter()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onEnter();
|
|
|
|
|
|
|
|
Director::getInstance()->setProjection(Director::Projection::_3D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeZVertex::onExit()
|
|
|
|
{
|
|
|
|
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteBatchNodeZVertex::SpriteBatchNodeZVertex()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// This test tests z-order
|
|
|
|
// If you are going to use it is better to use a 3D projection
|
|
|
|
//
|
|
|
|
// WARNING:
|
2017-02-10 10:35:52 +08:00
|
|
|
// The developer is responsible for ordering its sprites according to its Z if the sprite has
|
2014-05-04 14:37:55 +08:00
|
|
|
// transparent parts.
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Configure shader to mimic glAlphaTest
|
|
|
|
//
|
2019-02-19 16:06:17 +08:00
|
|
|
// auto alphaTestShader = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
|
|
|
|
// GLint alphaValueLocation = glGetUniformLocation(alphaTestShader->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// set alpha test value
|
|
|
|
// NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
|
2019-02-19 16:06:17 +08:00
|
|
|
// if (getGLProgram())
|
|
|
|
// {
|
|
|
|
// getGLProgram()->setUniformLocationWith1f(alphaValueLocation, 0.0f);
|
|
|
|
// }
|
|
|
|
|
2014-05-04 14:37:55 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
float step = s.width/12;
|
|
|
|
|
|
|
|
// small capacity. Testing resizing.
|
|
|
|
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
|
|
|
|
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
|
|
|
|
// camera uses the center of the image as the pivoting point
|
|
|
|
batch->setContentSize( Size(s.width,s.height));
|
2014-05-15 01:07:09 +08:00
|
|
|
batch->setAnchorPoint( Vec2::ANCHOR_MIDDLE);
|
|
|
|
batch->setPosition( Vec2(s.width/2, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
2019-02-19 16:06:17 +08:00
|
|
|
// batch->setGLProgram(alphaTestShader);
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
for(int i=0;i<5;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85*0, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( (i+1)*step, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->setPositionZ( 10 + i*40 );
|
|
|
|
batch->addChild(sprite, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=5;i<11;i++) {
|
|
|
|
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85*1, 121*0, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( (i+1)*step, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->setPositionZ( 10 + (10-i)*40 );
|
|
|
|
batch->addChild(sprite, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
batch->runAction(OrbitCamera::create(10, 1, 0, 0, 360, 0, 0) );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeZVertex::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeZVertex::subtitle() const
|
|
|
|
{
|
|
|
|
return "openGL Z vertex";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteAnchorPoint
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteAnchorPoint::SpriteAnchorPoint()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
|
|
auto rotate = RotateBy::create(10, 360);
|
|
|
|
auto action = RepeatForever::create(rotate);
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*i, 121*1, 85, 121) );
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( s.width/4*(i+1), s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_BOTTOM_LEFT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
|
|
|
|
sprite->runAction( action->clone() );
|
|
|
|
addChild(sprite, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteAnchorPoint::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteAnchorPoint::subtitle() const
|
|
|
|
{
|
|
|
|
return "anchor point";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeAnchorPoint
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteBatchNodeAnchorPoint::SpriteBatchNodeAnchorPoint()
|
|
|
|
{
|
|
|
|
// small capacity. Testing resizing.
|
|
|
|
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
|
|
|
|
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
|
|
auto rotate = RotateBy::create(10, 360);
|
|
|
|
auto action = RepeatForever::create(rotate);
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85*i, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( s.width/4*(i+1), s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
addChild(point, 1);
|
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_BOTTOM_LEFT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
|
|
|
|
sprite->runAction( action->clone() );
|
|
|
|
batch->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeAnchorPoint::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeAnchorPoint::subtitle() const
|
|
|
|
{
|
|
|
|
return "anchor point";
|
|
|
|
}
|
|
|
|
|
2015-12-14 23:17:41 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteAnchorPointFromFile
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SpriteAnchorPointFromFile::onEnter()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onEnter();
|
|
|
|
auto screen = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto rotate = RotateBy::create(10, 360);
|
|
|
|
auto action = RepeatForever::create(rotate);
|
|
|
|
char str[100] = {0};
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_anchors.plist");
|
|
|
|
|
|
|
|
Sprite *sprite;
|
|
|
|
for(int i=0;i<10;i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png", i+1);
|
|
|
|
sprite = Sprite::createWithSpriteFrameName(str);
|
|
|
|
|
|
|
|
sprite->setPosition(Vec2(screen.width/6*(i%5+1), screen.height*2/3 - screen.height*(i/5)/3));
|
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.1f );
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
sprite->runAction( action->clone() );
|
|
|
|
addChild(sprite, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(5);
|
|
|
|
for(int i = 9; i < 14; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png", i+1);
|
|
|
|
animFrames.pushBack(cache->getSpriteFrameByName(str));
|
|
|
|
}
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteAnchorPointFromFile::onExit()
|
|
|
|
{
|
|
|
|
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("animations/grossini_anchors.plist");
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteAnchorPointFromFile::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteFrame";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteAnchorPointFromFile::subtitle() const
|
|
|
|
{
|
|
|
|
return "anchor point";
|
|
|
|
}
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Sprite6
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
Sprite6::Sprite6()
|
|
|
|
{
|
|
|
|
// small capacity. Testing resizing
|
|
|
|
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
|
|
|
|
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
2016-04-25 19:43:42 +08:00
|
|
|
batch->setIgnoreAnchorPointForPosition( true );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
batch->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
|
2014-05-04 14:37:55 +08:00
|
|
|
batch->setContentSize( Size(s.width, s.height) );
|
|
|
|
|
|
|
|
|
|
|
|
// SpriteBatchNode actions
|
|
|
|
auto rotate = RotateBy::create(5, 360);
|
|
|
|
auto action = RepeatForever::create(rotate);
|
|
|
|
|
|
|
|
// SpriteBatchNode actions
|
|
|
|
auto rotate_back = rotate->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto rotate_seq = Sequence::create(rotate, rotate_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
auto rotate_forever = RepeatForever::create(rotate_seq);
|
|
|
|
|
|
|
|
auto scale = ScaleBy::create(5, 1.5f);
|
|
|
|
auto scale_back = scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto scale_seq = Sequence::create( scale, scale_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
auto scale_forever = RepeatForever::create(scale_seq);
|
|
|
|
|
|
|
|
float step = s.width/4;
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85*i, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( (i+1)*step, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite->runAction( action->clone());
|
|
|
|
batch->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
batch->runAction(scale_forever);
|
|
|
|
batch->runAction(rotate_forever);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Sprite6::title() const
|
|
|
|
{
|
|
|
|
return "SpriteBatchNode transformation";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteFlip
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteFlip::SpriteFlip()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto sprite1 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*1, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( s.width/2 - 100, s.height/2 ) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(sprite1, 0, kTagSprite1);
|
|
|
|
|
|
|
|
auto sprite2 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*1, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition( Vec2( s.width/2 + 100, s.height/2 ) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(sprite2, 0, kTagSprite2);
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule( CC_CALLBACK_1(SpriteFlip::flipSprites,this), 1, "sprite_flip_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteFlip::flipSprites(float dt)
|
|
|
|
{
|
|
|
|
auto sprite1 = static_cast<Sprite*>(getChildByTag(kTagSprite1));
|
|
|
|
auto sprite2 = static_cast<Sprite*>(getChildByTag(kTagSprite2));
|
|
|
|
|
|
|
|
bool x = sprite1->isFlippedX();
|
|
|
|
bool y = sprite2->isFlippedY();
|
|
|
|
|
2016-10-27 09:45:40 +08:00
|
|
|
CCLOG("Pre: %g", sprite1->getContentSize().height);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite1->setFlippedX(!x);
|
|
|
|
sprite2->setFlippedY(!y);
|
2016-10-27 09:45:40 +08:00
|
|
|
CCLOG("Post: %g", sprite1->getContentSize().height);
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteFlip::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteFlip::subtitle() const
|
|
|
|
{
|
|
|
|
return "Flip X & Y";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeFlip
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteBatchNodeFlip::SpriteBatchNodeFlip()
|
|
|
|
{
|
|
|
|
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 10);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto sprite1 = Sprite::createWithTexture(batch->getTexture(), Rect(85*1, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( s.width/2 - 100, s.height/2 ) );
|
2014-05-04 14:37:55 +08:00
|
|
|
batch->addChild(sprite1, 0, kTagSprite1);
|
|
|
|
|
|
|
|
auto sprite2 = Sprite::createWithTexture(batch->getTexture(), Rect(85*1, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition( Vec2( s.width/2 + 100, s.height/2 ) );
|
2014-05-04 14:37:55 +08:00
|
|
|
batch->addChild(sprite2, 0, kTagSprite2);
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule(CC_CALLBACK_1(SpriteBatchNodeFlip::flipSprites, this), 1, "flip_sprites_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeFlip::flipSprites(float dt)
|
|
|
|
{
|
|
|
|
auto batch= static_cast<SpriteBatchNode*>(getChildByTag( kTagSpriteBatchNode ));
|
|
|
|
auto sprite1 = static_cast<Sprite*>(batch->getChildByTag(kTagSprite1));
|
|
|
|
auto sprite2 = static_cast<Sprite*>(batch->getChildByTag(kTagSprite2));
|
|
|
|
|
|
|
|
bool x = sprite1->isFlippedX();
|
|
|
|
bool y = sprite2->isFlippedY();
|
|
|
|
|
2016-10-27 09:45:40 +08:00
|
|
|
CCLOG("Pre: %g", sprite1->getContentSize().height);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite1->setFlippedX(!x);
|
|
|
|
sprite2->setFlippedY(!y);
|
2016-10-27 09:45:40 +08:00
|
|
|
CCLOG("Post: %g", sprite1->getContentSize().height);
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeFlip::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeFlip::subtitle() const
|
|
|
|
{
|
|
|
|
return "Flip X & Y";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteAliased
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteAliased::SpriteAliased()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto sprite1 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*1, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( s.width/2 - 100, s.height/2 ) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(sprite1, 0, kTagSprite1);
|
|
|
|
|
|
|
|
auto sprite2 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85*1, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition( Vec2( s.width/2 + 100, s.height/2 ) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(sprite2, 0, kTagSprite2);
|
|
|
|
|
|
|
|
auto scale = ScaleBy::create(2, 5);
|
|
|
|
auto scale_back = scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create( scale, scale_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
auto repeat = RepeatForever::create(seq);
|
|
|
|
|
|
|
|
auto repeat2 = repeat->clone();
|
|
|
|
|
|
|
|
sprite1->runAction(repeat);
|
|
|
|
sprite2->runAction(repeat2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteAliased::onEnter()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onEnter();
|
|
|
|
|
|
|
|
//
|
|
|
|
// IMPORTANT:
|
|
|
|
// This change will affect every sprite that uses the same texture
|
|
|
|
// So sprite1 and sprite2 will be affected by this change
|
|
|
|
//
|
|
|
|
auto sprite = static_cast<Sprite*>( getChildByTag(kTagSprite1) );
|
|
|
|
sprite->getTexture()->setAliasTexParameters();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteAliased::onExit()
|
|
|
|
{
|
|
|
|
// restore the tex parameter to AntiAliased.
|
|
|
|
auto sprite = static_cast<Sprite*>( getChildByTag(kTagSprite1) );
|
|
|
|
sprite->getTexture()->setAntiAliasTexParameters();
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteAliased::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteAliased::subtitle() const
|
|
|
|
{
|
|
|
|
return "AliasTexParameters()";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeAliased
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeAliased::SpriteBatchNodeAliased()
|
|
|
|
{
|
|
|
|
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 10);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto sprite1 = Sprite::createWithTexture(batch->getTexture(), Rect(85*1, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( s.width/2 - 100, s.height/2 ) );
|
2014-05-04 14:37:55 +08:00
|
|
|
batch->addChild(sprite1, 0, kTagSprite1);
|
|
|
|
|
|
|
|
auto sprite2 = Sprite::createWithTexture(batch->getTexture(), Rect(85*1, 121*1, 85, 121));
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition( Vec2( s.width/2 + 100, s.height/2 ) );
|
2014-05-04 14:37:55 +08:00
|
|
|
batch->addChild(sprite2, 0, kTagSprite2);
|
|
|
|
|
|
|
|
auto scale = ScaleBy::create(2, 5);
|
|
|
|
auto scale_back = scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create( scale, scale_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
auto repeat = RepeatForever::create(seq);
|
|
|
|
|
|
|
|
auto repeat2 = repeat->clone();
|
|
|
|
|
|
|
|
sprite1->runAction(repeat);
|
|
|
|
sprite2->runAction(repeat2);
|
|
|
|
|
|
|
|
}
|
|
|
|
void SpriteBatchNodeAliased::onEnter()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onEnter();
|
|
|
|
auto batch = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
|
|
|
|
batch->getTexture()->setAliasTexParameters();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeAliased::onExit()
|
|
|
|
{
|
|
|
|
// restore the tex parameter to AntiAliased.
|
|
|
|
auto batch = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
|
|
|
|
batch->getTexture()->setAntiAliasTexParameters();
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeAliased::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeAliased::subtitle() const
|
|
|
|
{
|
|
|
|
return "AliasTexParameters()";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteNewTexture
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteNewTexture::SpriteNewTexture()
|
|
|
|
{
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(SpriteNewTexture::onTouchesEnded, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
|
|
|
auto node = Node::create();
|
|
|
|
addChild(node, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
_texture1 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas.png");
|
|
|
|
_texture1->retain();
|
|
|
|
_texture2 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas-mono.png");
|
|
|
|
_texture2->retain();
|
|
|
|
|
|
|
|
_usingTexture1 = true;
|
|
|
|
|
|
|
|
for(int i=0;i<30;i++)
|
|
|
|
addNewSprite();
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteNewTexture::~SpriteNewTexture()
|
|
|
|
{
|
|
|
|
_texture1->release();
|
|
|
|
_texture2->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteNewTexture::addNewSprite()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
auto p = Vec2( CCRANDOM_0_1() * s.width, CCRANDOM_0_1() * s.height);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
int idx = CCRANDOM_0_1() * 1400 / 100;
|
|
|
|
int x = (idx%5) * 85;
|
|
|
|
int y = (idx/5) * 121;
|
|
|
|
|
|
|
|
|
|
|
|
auto node = getChildByTag( kTagSpriteBatchNode );
|
|
|
|
auto sprite = Sprite::createWithTexture(_texture1, Rect(x,y,85,121));
|
|
|
|
node->addChild(sprite);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( p.x, p.y) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
ActionInterval* action;
|
|
|
|
float random = CCRANDOM_0_1();
|
|
|
|
|
|
|
|
if( random < 0.20 )
|
|
|
|
action = ScaleBy::create(3, 2);
|
|
|
|
else if(random < 0.40)
|
|
|
|
action = RotateBy::create(3, 360);
|
|
|
|
else if( random < 0.60)
|
|
|
|
action = Blink::create(1, 3);
|
|
|
|
else if( random < 0.8 )
|
|
|
|
action = TintBy::create(2, 0, -255, -255);
|
|
|
|
else
|
|
|
|
action = FadeOut::create(2);
|
|
|
|
|
|
|
|
auto action_back = action->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(action, action_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite->runAction( RepeatForever::create(seq) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteNewTexture::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
|
|
|
{
|
|
|
|
|
|
|
|
auto node = getChildByTag( kTagSpriteBatchNode );
|
|
|
|
|
|
|
|
auto& children = node->getChildren();
|
|
|
|
Sprite* sprite;
|
|
|
|
|
|
|
|
if( _usingTexture1 ) //--> win32 : Let's it make just simple sentence
|
|
|
|
{
|
|
|
|
for(const auto &obj : children) {
|
|
|
|
sprite = static_cast<Sprite*>( obj );
|
|
|
|
sprite->setTexture(_texture2);
|
|
|
|
}
|
|
|
|
|
|
|
|
_usingTexture1 = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(const auto &obj : children) {
|
|
|
|
sprite = static_cast<Sprite*>( obj );
|
|
|
|
sprite->setTexture(_texture1);
|
|
|
|
}
|
|
|
|
|
|
|
|
_usingTexture1 = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteNewTexture::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteNewTexture::subtitle() const
|
|
|
|
{
|
|
|
|
return "setTexture() (tap / touch the screen)";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeNewTexture
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeNewTexture::SpriteBatchNodeNewTexture()
|
|
|
|
{
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(SpriteBatchNodeNewTexture::onTouchesEnded, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
|
|
|
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
_texture1 = batch->getTexture(); _texture1->retain();
|
|
|
|
_texture2 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas-mono.png");
|
|
|
|
_texture2->retain();
|
|
|
|
|
|
|
|
for(int i=0;i<30;i++)
|
|
|
|
addNewSprite();
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteBatchNodeNewTexture::~SpriteBatchNodeNewTexture()
|
|
|
|
{
|
|
|
|
_texture1->release();
|
|
|
|
_texture2->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeNewTexture::addNewSprite()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
auto p = Vec2( CCRANDOM_0_1() * s.width, CCRANDOM_0_1() * s.height);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto batch = static_cast<SpriteBatchNode*>( getChildByTag( kTagSpriteBatchNode ) );
|
|
|
|
|
|
|
|
int idx = CCRANDOM_0_1() * 1400 / 100;
|
|
|
|
int x = (idx%5) * 85;
|
|
|
|
int y = (idx/5) * 121;
|
|
|
|
|
|
|
|
|
|
|
|
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(x,y,85,121));
|
|
|
|
batch->addChild(sprite);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( p.x, p.y) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
ActionInterval* action;
|
|
|
|
float random = CCRANDOM_0_1();
|
|
|
|
|
|
|
|
if( random < 0.20 )
|
|
|
|
action = ScaleBy::create(3, 2);
|
|
|
|
else if(random < 0.40)
|
|
|
|
action = RotateBy::create(3, 360);
|
|
|
|
else if( random < 0.60)
|
|
|
|
action = Blink::create(1, 3);
|
|
|
|
else if( random < 0.8 )
|
|
|
|
action = TintBy::create(2, 0, -255, -255);
|
|
|
|
else
|
|
|
|
action = FadeOut::create(2);
|
|
|
|
auto action_back = action->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(action, action_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite->runAction( RepeatForever::create(seq) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeNewTexture::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
|
|
|
{
|
|
|
|
auto batch = static_cast<SpriteBatchNode*>( getChildByTag( kTagSpriteBatchNode) );
|
|
|
|
|
|
|
|
if( batch->getTexture() == _texture1 )
|
|
|
|
batch->setTexture(_texture2);
|
|
|
|
else
|
|
|
|
batch->setTexture(_texture1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeNewTexture::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeNewTexture::subtitle() const
|
|
|
|
{
|
|
|
|
return "setTexture() (tap / touch the screen)";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteFrameTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SpriteFrameTest::onEnter()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onEnter();
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
// IMPORTANT:
|
|
|
|
// The sprite frames will be cached AND RETAINED, and they won't be released unless you call
|
|
|
|
// SpriteFrameCache::getInstance()->removeUnusedSpriteFrames);
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_blue.plist", "animations/grossini_blue.png");
|
|
|
|
|
|
|
|
//
|
|
|
|
// Animation using Sprite BatchNode
|
|
|
|
//
|
|
|
|
_sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
_sprite1->setPosition( Vec2( s.width/2-80, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
spritebatch->addChild(_sprite1);
|
|
|
|
addChild(spritebatch);
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(15);
|
|
|
|
|
|
|
|
char str[100] = {0};
|
|
|
|
for(int i = 1; i < 15; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png", i);
|
|
|
|
auto frame = cache->getSpriteFrameByName( str );
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
_sprite1->runAction( RepeatForever::create( Animate::create(animation) ) );
|
|
|
|
|
|
|
|
// to test issue #732, uncomment the following line
|
|
|
|
_sprite1->setFlippedX(false);
|
|
|
|
_sprite1->setFlippedY(false);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Animation using standard Sprite
|
|
|
|
//
|
|
|
|
_sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
_sprite2->setPosition( Vec2( s.width/2 + 80, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(_sprite2);
|
|
|
|
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> moreFrames(20);
|
|
|
|
for(int i = 1; i < 15; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_gray_%02d.png",i);
|
|
|
|
auto frame = cache->getSpriteFrameByName(str);
|
|
|
|
moreFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for( int i = 1; i < 5; i++) {
|
|
|
|
sprintf(str, "grossini_blue_%02d.png",i);
|
|
|
|
auto frame = cache->getSpriteFrameByName(str);
|
|
|
|
moreFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// append frames from another batch
|
|
|
|
moreFrames.pushBack(animFrames);
|
|
|
|
auto animMixed = Animation::createWithSpriteFrames(moreFrames, 0.3f);
|
|
|
|
|
|
|
|
|
|
|
|
_sprite2->runAction(RepeatForever::create( Animate::create(animMixed) ) );
|
|
|
|
|
|
|
|
|
|
|
|
// to test issue #732, uncomment the following line
|
|
|
|
_sprite2->setFlippedX(false);
|
|
|
|
_sprite2->setFlippedY(false);
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule(CC_CALLBACK_1(SpriteFrameTest::startIn05Secs, this), 0.5f, "in_05_secs_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
_counter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteFrameTest::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_blue.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteFrameTest::title() const
|
|
|
|
{
|
|
|
|
return "Sprite vs. SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteFrameTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "Animation. Testing issue #792";
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteFrameTest::startIn05Secs(float dt)
|
|
|
|
{
|
2014-10-04 08:11:39 +08:00
|
|
|
unschedule("in_05_secs_key");
|
|
|
|
schedule(CC_CALLBACK_1(SpriteFrameTest::flipSprites, this), 1.0f, "flip_sprites_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteFrameTest::flipSprites(float dt)
|
|
|
|
{
|
|
|
|
_counter++;
|
|
|
|
|
|
|
|
bool fx = false;
|
|
|
|
bool fy = false;
|
|
|
|
int i = _counter % 4;
|
|
|
|
|
|
|
|
switch ( i ) {
|
|
|
|
case 0:
|
|
|
|
fx = false;
|
|
|
|
fy = false;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fx = true;
|
|
|
|
fy = false;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
fx = false;
|
|
|
|
fy = true;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
fx = true;
|
|
|
|
fy = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_sprite1->setFlippedX(fx);
|
|
|
|
_sprite1->setFlippedY(fy);
|
|
|
|
_sprite2->setFlippedX(fx);
|
|
|
|
_sprite2->setFlippedY(fy);
|
|
|
|
//NSLog(@"flipX:%d, flipY:%d", fx, fy);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteFrameAliasNameTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SpriteFrameAliasNameTest::onEnter()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onEnter();
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
// IMPORTANT:
|
|
|
|
// The sprite frames will be cached AND RETAINED, and they won't be released unless you call
|
|
|
|
// SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
|
|
|
|
//
|
|
|
|
// SpriteFrameCache is a cache of SpriteFrames
|
|
|
|
// SpriteFrames each contain a texture id and a rect (frame).
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini-aliases.plist", "animations/grossini-aliases.png");
|
|
|
|
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
// A SpriteBatchNode can reference one and only one texture (one .png file)
|
2017-02-10 10:35:52 +08:00
|
|
|
// Sprites that are contained in that texture can be instantiated as Sprites and then added to the SpriteBatchNode
|
2014-05-04 14:37:55 +08:00
|
|
|
// All Sprites added to a SpriteBatchNode are drawn in one OpenGL ES draw call
|
|
|
|
// If the Sprites are not added to a SpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient
|
|
|
|
//
|
|
|
|
// When you animate a sprite, Animation changes the frame of the sprite using setDisplayFrame: (this is why the animation must be in the same texture)
|
|
|
|
// When setDisplayFrame: is used in the Animation it changes the frame to one specified by the SpriteFrames that were added to the animation,
|
|
|
|
// but texture id is still the same and so the sprite is still a child of the SpriteBatchNode,
|
|
|
|
// and therefore all the animation sprites are also drawn as part of the SpriteBatchNode
|
|
|
|
//
|
|
|
|
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width * 0.5f, s.height * 0.5f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto spriteBatch = SpriteBatchNode::create("animations/grossini-aliases.png");
|
|
|
|
spriteBatch->addChild(sprite);
|
|
|
|
addChild(spriteBatch);
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(15);
|
|
|
|
char str[100] = {0};
|
|
|
|
for(int i = 1; i < 15; i++)
|
|
|
|
{
|
|
|
|
// Obtain frames by alias name
|
|
|
|
sprintf(str, "dance_%02d", i);
|
|
|
|
auto frame = cache->getSpriteFrameByName(str);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
// 14 frames * 1sec = 14 seconds
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
2015-12-03 14:21:00 +08:00
|
|
|
|
|
|
|
cache->reloadTexture("animations/grossini-aliases.plist");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteFrameAliasNameTest::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("animations/grossini-aliases.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteFrameAliasNameTest::title() const
|
|
|
|
{
|
|
|
|
return "SpriteFrame Alias Name";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteFrameAliasNameTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "SpriteFrames are obtained using the alias name";
|
|
|
|
}
|
|
|
|
|
2014-08-01 14:39:45 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteFramesFromFileContent
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SpriteFramesFromFileContent::onEnter()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onEnter();
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
2016-01-15 00:54:42 +08:00
|
|
|
std::string plist_content = FileUtils::getInstance()->getStringFromFile(sheetName() + ".plist");
|
|
|
|
Data image_content = FileUtils::getInstance()->getDataFromFile(sheetName() + ".png");
|
2014-08-01 14:39:45 +08:00
|
|
|
|
2016-01-15 00:54:42 +08:00
|
|
|
Image* image = new (std::nothrow) Image();
|
|
|
|
image->initWithImageData((const uint8_t*)image_content.getBytes(), image_content.getSize());
|
2014-08-28 07:31:57 +08:00
|
|
|
Texture2D* texture = new (std::nothrow) Texture2D();
|
2016-01-15 00:54:42 +08:00
|
|
|
texture->initWithImage(image);
|
2014-08-01 14:39:45 +08:00
|
|
|
texture->autorelease();
|
2016-01-15 00:54:42 +08:00
|
|
|
|
|
|
|
CC_SAFE_RELEASE(image);
|
2014-08-01 14:39:45 +08:00
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFileContent(plist_content, texture);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Animation using Sprite BatchNode
|
|
|
|
//
|
|
|
|
Sprite * sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2017-01-10 15:28:47 +08:00
|
|
|
sprite->setPosition( Vec2( s.width/2, s.height/2) );
|
2014-08-01 14:39:45 +08:00
|
|
|
addChild(sprite);
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(15);
|
|
|
|
|
|
|
|
char str[100] = {0};
|
|
|
|
for(int i = 1; i < 15; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png", i);
|
|
|
|
auto frame = cache->getSpriteFrameByName( str );
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction( RepeatForever::create( Animate::create(animation) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteFramesFromFileContent::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
|
2016-01-15 00:54:42 +08:00
|
|
|
std::string plist_content = FileUtils::getInstance()->getStringFromFile("animations/grossini.plist");
|
2014-08-01 14:39:45 +08:00
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->removeSpriteFramesFromFileContent(plist_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteFramesFromFileContent::title() const
|
|
|
|
{
|
|
|
|
return "SpriteFrameCache load form file content";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteFramesFromFileContent::subtitle() const
|
|
|
|
{
|
|
|
|
return "SpriteFrameCache load from plist file content";
|
|
|
|
}
|
|
|
|
|
2015-09-29 21:44:13 +08:00
|
|
|
std::string SpriteFramesFromFileContent::sheetName() const
|
|
|
|
{
|
|
|
|
return "animations/grossini";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpritePolygonFromFileContent
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::string SpritePolygonFromFileContent::subtitle() const
|
|
|
|
{
|
|
|
|
return "SpriteFrameCache load polygon info from plist file";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpritePolygonFromFileContent::sheetName() const
|
|
|
|
{
|
|
|
|
return "animations/grossini_polygon";
|
|
|
|
}
|
|
|
|
|
2014-05-04 14:37:55 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteOffsetAnchorRotation
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2015-12-15 21:14:09 +08:00
|
|
|
void SpriteOffsetAnchorRotation::onEnter()
|
2014-05-04 14:37:55 +08:00
|
|
|
{
|
2015-12-15 21:14:09 +08:00
|
|
|
SpriteTestDemo::onEnter();
|
|
|
|
|
2014-05-04 14:37:55 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2( s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
addChild(point, 1);
|
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_BOTTOM_LEFT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char str[100] = {0};
|
|
|
|
for(int i = 0; i < 14; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png",(i+1));
|
|
|
|
auto frame = cache->getSpriteFrameByName(str);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create( Animate::create(animation) ) );
|
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(10, 360) ) );
|
|
|
|
|
|
|
|
addChild(sprite, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SpriteOffsetAnchorRotation::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorRotation::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorRotation::subtitle() const
|
|
|
|
{
|
|
|
|
return "offset + anchor + rotation";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeOffsetAnchorRotation
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeOffsetAnchorRotation::SpriteBatchNodeOffsetAnchorRotation()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
addChild(spritebatch);
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite BatchNode
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
addChild(point, 200);
|
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_BOTTOM_LEFT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char str[100] = {0};
|
|
|
|
for(int k = 0; k < 14; k++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png",(k+1));
|
|
|
|
auto frame = cache->getSpriteFrameByName(str);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create( Animate::create(animation) ));
|
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(10, 360) ));
|
|
|
|
|
|
|
|
spritebatch->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SpriteBatchNodeOffsetAnchorRotation::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorRotation::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorRotation::subtitle() const
|
|
|
|
{
|
|
|
|
return "offset + anchor + rotation";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteOffsetAnchorScale
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
SpriteOffsetAnchorScale::SpriteOffsetAnchorScale()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite BatchNode
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( s.width/4*(i+1), s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
addChild(point, 1);
|
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_BOTTOM_LEFT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char str[100] = {0};
|
|
|
|
for(int i = 0; i < 14; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png",(i+1));
|
|
|
|
auto frame = cache->getSpriteFrameByName(str);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create( Animate::create(animation) ));
|
|
|
|
|
|
|
|
auto scale = ScaleBy::create(2, 2);
|
|
|
|
auto scale_back = scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_scale));
|
|
|
|
|
|
|
|
addChild(sprite, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteOffsetAnchorScale::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorScale::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorScale::subtitle() const
|
|
|
|
{
|
|
|
|
return "offset + anchor + scale";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeOffsetAnchorScale
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteBatchNodeOffsetAnchorScale::SpriteBatchNodeOffsetAnchorScale()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto spritesheet = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
addChild(spritesheet);
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite BatchNode
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( s.width/4*(i+1), s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
addChild(point, 200);
|
|
|
|
|
|
|
|
switch(i) {
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_BOTTOM_LEFT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint( Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition( sprite->getPosition() );
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char str[100] = {0};
|
|
|
|
for(int k = 0; k < 14; k++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png",(k+1));
|
|
|
|
auto frame = cache->getSpriteFrameByName(str);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create( Animate::create(animation) ) );
|
|
|
|
|
|
|
|
auto scale = ScaleBy::create(2, 2);
|
|
|
|
auto scale_back = scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_scale) );
|
|
|
|
|
|
|
|
spritesheet->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeOffsetAnchorScale::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorScale::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorScale::subtitle() const
|
|
|
|
{
|
|
|
|
return "offset + anchor + scale";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteAnimationSplit
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteAnimationSplit::SpriteAnimationSplit()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto texture = Director::getInstance()->getTextureCache()->addImage("animations/dragon_animation.png");
|
|
|
|
|
|
|
|
// manually add frames to the frame cache
|
|
|
|
auto frame0 = SpriteFrame::createWithTexture(texture, Rect(132*0, 132*0, 132, 132));
|
|
|
|
auto frame1 = SpriteFrame::createWithTexture(texture, Rect(132*1, 132*0, 132, 132));
|
|
|
|
auto frame2 = SpriteFrame::createWithTexture(texture, Rect(132*2, 132*0, 132, 132));
|
|
|
|
auto frame3 = SpriteFrame::createWithTexture(texture, Rect(132*3, 132*0, 132, 132));
|
|
|
|
auto frame4 = SpriteFrame::createWithTexture(texture, Rect(132*0, 132*1, 132, 132));
|
|
|
|
auto frame5 = SpriteFrame::createWithTexture(texture, Rect(132*1, 132*1, 132, 132));
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Animation using Sprite BatchNode
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrame(frame0);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2( s.width/2-80, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(sprite);
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(6);
|
|
|
|
animFrames.pushBack(frame0);
|
|
|
|
animFrames.pushBack(frame1);
|
|
|
|
animFrames.pushBack(frame2);
|
|
|
|
animFrames.pushBack(frame3);
|
|
|
|
animFrames.pushBack(frame4);
|
|
|
|
animFrames.pushBack(frame5);
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
|
|
|
|
auto animate = Animate::create(animation);
|
|
|
|
auto seq = Sequence::create(animate,
|
|
|
|
FlipX::create(true),
|
|
|
|
animate->clone(),
|
|
|
|
FlipX::create(false),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite->runAction(RepeatForever::create( seq ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteAnimationSplit::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteAnimationSplit::title() const
|
|
|
|
{
|
|
|
|
return "Sprite: Animation + flip";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteHybrid
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteHybrid::SpriteHybrid()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
// parents
|
|
|
|
auto parent1 = Node::create();
|
|
|
|
auto parent2 = SpriteBatchNode::create("animations/grossini.png", 50);
|
|
|
|
|
|
|
|
addChild(parent1, 0, kTagNode);
|
|
|
|
addChild(parent2, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
|
|
|
|
// IMPORTANT:
|
|
|
|
// The sprite frames will be cached AND RETAINED, and they won't be released unless you call
|
|
|
|
// SpriteFrameCache::getInstance()->removeUnusedSpriteFrames);
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
|
|
|
|
// create 250 sprites
|
|
|
|
// only show 80% of them
|
|
|
|
for(int i = 0; i < 250; i++)
|
|
|
|
{
|
|
|
|
int spriteIdx = CCRANDOM_0_1() * 14;
|
|
|
|
char str[25] = {0};
|
|
|
|
sprintf(str, "grossini_dance_%02d.png", (spriteIdx+1));
|
|
|
|
auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str);
|
|
|
|
auto sprite = Sprite::createWithSpriteFrame(frame);
|
|
|
|
parent1->addChild(sprite, i, i);
|
|
|
|
|
|
|
|
float x=-1000;
|
|
|
|
float y=-1000;
|
|
|
|
if( CCRANDOM_0_1() < 0.2f )
|
|
|
|
{
|
|
|
|
x = CCRANDOM_0_1() * s.width;
|
|
|
|
y = CCRANDOM_0_1() * s.height;
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2(x,y) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto action = RotateBy::create(4, 360);
|
|
|
|
sprite->runAction( RepeatForever::create(action) );
|
|
|
|
}
|
|
|
|
|
|
|
|
_usingSpriteBatchNode = false;
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule(CC_CALLBACK_1(SpriteHybrid::reparentSprite, this), 2, "reparent_sprite_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteHybrid::reparentSprite(float dt)
|
|
|
|
{
|
|
|
|
auto p1 = getChildByTag(kTagNode);
|
|
|
|
auto p2 = getChildByTag( kTagSpriteBatchNode );
|
|
|
|
|
|
|
|
Vector<Node*> retArray(250);
|
|
|
|
|
|
|
|
if( _usingSpriteBatchNode )
|
2014-11-17 01:29:05 +08:00
|
|
|
std::swap(p1, p2);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
////----CCLOG("New parent is: %x", p2);
|
|
|
|
|
|
|
|
auto& p1Children = p1->getChildren();
|
|
|
|
for(const auto &node : p1Children) {
|
|
|
|
retArray.pushBack(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
p1->removeAllChildrenWithCleanup(false);
|
|
|
|
|
|
|
|
for(const auto &node : retArray) {
|
|
|
|
p2->addChild(node, i, i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
_usingSpriteBatchNode = ! _usingSpriteBatchNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteHybrid::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteHybrid::title() const
|
|
|
|
{
|
|
|
|
return "HybridSprite* sprite Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeChildren
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeChildren::SpriteBatchNodeChildren()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
// parents
|
|
|
|
auto batch = SpriteBatchNode::create("animations/grossini.png", 50);
|
|
|
|
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
auto sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2( s.width/3, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(50.0f,50.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-50.0f,-50.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
batch->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2);
|
|
|
|
sprite1->addChild(sprite3);
|
|
|
|
|
|
|
|
// BEGIN NEW CODE
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char str[100] = {0};
|
|
|
|
for(int i = 1; i < 15; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png",i);
|
|
|
|
auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
|
|
|
|
sprite1->runAction(RepeatForever::create( Animate::create(animation) ) );
|
|
|
|
// END NEW CODE
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
auto action = MoveBy::create(2, Vec2(200.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
auto action_back = action->reverse();
|
2019-09-24 11:31:35 +08:00
|
|
|
auto action_rot = RotateBy::create(2.0f, 360.0f);
|
|
|
|
auto action_s = ScaleBy::create(2.0f, 2.0f);
|
2014-05-04 14:37:55 +08:00
|
|
|
auto action_s_back = action_s->reverse();
|
|
|
|
|
|
|
|
auto seq2 = action_rot->reverse();
|
|
|
|
sprite2->runAction( RepeatForever::create(seq2) );
|
|
|
|
|
|
|
|
sprite1->runAction( RepeatForever::create(action_rot));
|
2014-07-10 00:45:27 +08:00
|
|
|
sprite1->runAction( RepeatForever::create(Sequence::create(action, action_back,nullptr)) );
|
|
|
|
sprite1->runAction( RepeatForever::create(Sequence::create(action_s, action_s_back,nullptr)) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeChildren::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeChildren::title() const
|
|
|
|
{
|
|
|
|
return "SpriteBatchNode Grand Children";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeChildrenZ
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteBatchNodeChildrenZ::SpriteBatchNodeChildrenZ()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
// parents
|
|
|
|
SpriteBatchNode* batch;
|
|
|
|
Sprite* sprite1, *sprite2, *sprite3;
|
|
|
|
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
// test 1
|
|
|
|
batch = SpriteBatchNode::create("animations/grossini.png", 50);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2( s.width/3, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
batch->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, 2);
|
|
|
|
sprite1->addChild(sprite3, -2);
|
|
|
|
|
|
|
|
// test 2
|
|
|
|
batch = SpriteBatchNode::create("animations/grossini.png", 50);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2( 2*s.width/3, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
batch->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, 2);
|
|
|
|
|
|
|
|
// test 3
|
|
|
|
batch = SpriteBatchNode::create("animations/grossini.png", 50);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2( s.width/2 - 90, s.height/4));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition(Vec2( s.width/2 - 60,s.height/4));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite3->setPosition(Vec2( s.width/2 - 30, s.height/4));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
batch->addChild(sprite1, 10);
|
|
|
|
batch->addChild(sprite2, -10);
|
|
|
|
batch->addChild(sprite3, -5);
|
|
|
|
|
|
|
|
// test 4
|
|
|
|
batch = SpriteBatchNode::create("animations/grossini.png", 50);
|
|
|
|
addChild(batch, 0, kTagSpriteBatchNode);
|
|
|
|
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2( s.width/2 +30, s.height/4));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition(Vec2( s.width/2 +60,s.height/4));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite3->setPosition(Vec2( s.width/2 +90, s.height/4));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
batch->addChild(sprite1, -10);
|
|
|
|
batch->addChild(sprite2, -5);
|
|
|
|
batch->addChild(sprite3, -2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeChildrenZ::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeChildrenZ::title() const
|
|
|
|
{
|
|
|
|
return "SpriteBatchNode Children Z";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteChildrenVisibility
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteChildrenVisibility::SpriteChildrenVisibility()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
Node *aParent;
|
|
|
|
Sprite* sprite1, *sprite2, *sprite3;
|
|
|
|
//
|
|
|
|
// SpriteBatchNode
|
|
|
|
//
|
|
|
|
// parents
|
|
|
|
aParent = SpriteBatchNode::create("animations/grossini.png", 50);
|
2014-05-15 01:07:09 +08:00
|
|
|
aParent->setPosition( Vec2(s.width/3, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(aParent, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite1->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, 2);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite1->runAction(Blink::create(5.0f, 10.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Sprite
|
|
|
|
//
|
|
|
|
aParent = Node::create();
|
2014-05-15 01:07:09 +08:00
|
|
|
aParent->setPosition( Vec2(2*s.width/3, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(aParent, 0);
|
|
|
|
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite1->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, 2);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite1->runAction(Blink::create(5.0f, 10.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteChildrenVisibility::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteChildrenVisibility::title() const
|
|
|
|
{
|
|
|
|
return "Sprite & SpriteBatchNode Visibility";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteChildrenVisibilityIssue665
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteChildrenVisibilityIssue665::SpriteChildrenVisibilityIssue665()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
Node *aParent;
|
|
|
|
Sprite *sprite1, *sprite2, *sprite3;
|
|
|
|
//
|
|
|
|
// SpriteBatchNode
|
|
|
|
//
|
|
|
|
// parents
|
|
|
|
aParent = SpriteBatchNode::create("animations/grossini.png", 50);
|
2014-05-15 01:07:09 +08:00
|
|
|
aParent->setPosition(Vec2(s.width/3, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(aParent, 0);
|
|
|
|
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite1->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// test issue #665
|
|
|
|
sprite1->setVisible(false);
|
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, 2);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Sprite
|
|
|
|
//
|
|
|
|
aParent = Node::create();
|
2014-05-15 01:07:09 +08:00
|
|
|
aParent->setPosition(Vec2(2*s.width/3, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(aParent, 0);
|
|
|
|
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite1->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// test issue #665
|
|
|
|
sprite1->setVisible(false);
|
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteChildrenVisibilityIssue665::~SpriteChildrenVisibilityIssue665()
|
|
|
|
{
|
|
|
|
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteChildrenVisibilityIssue665::title() const
|
|
|
|
{
|
|
|
|
return "Sprite & SpriteBatchNode Visibility";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteChildrenVisibilityIssue665::subtitle() const
|
|
|
|
{
|
|
|
|
return "No sprites should be visible";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteChildrenAnchorPoint
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteChildrenAnchorPoint::SpriteChildrenAnchorPoint()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
Node *aParent;
|
|
|
|
Sprite* sprite1, *sprite2, *sprite3, *sprite4, *point;
|
|
|
|
//
|
|
|
|
// SpriteBatchNode
|
|
|
|
//
|
|
|
|
// parents
|
|
|
|
|
|
|
|
aParent = Node::create();
|
|
|
|
addChild(aParent, 0);
|
|
|
|
|
|
|
|
// anchor (0,0)
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2(s.width/4,s.height/2));
|
|
|
|
sprite1->setAnchorPoint( Vec2::ANCHOR_BOTTOM_LEFT );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite4->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite4->setScale( 0.5f );
|
|
|
|
|
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, -2);
|
|
|
|
sprite1->addChild(sprite4, 3);
|
|
|
|
|
|
|
|
point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
|
|
|
|
// anchor (0.5, 0.5)
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2(s.width/2,s.height/2));
|
|
|
|
sprite1->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite4->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite4->setScale( 0.5f );
|
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, -2);
|
|
|
|
sprite1->addChild(sprite4, 3);
|
|
|
|
|
|
|
|
point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
|
|
|
|
// anchor (1,1)
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2(s.width/2+s.width/4,s.height/2));
|
|
|
|
sprite1->setAnchorPoint( Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite4->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite4->setScale( 0.5f );
|
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, -2);
|
|
|
|
sprite1->addChild(sprite4, 3);
|
|
|
|
|
|
|
|
point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteChildrenAnchorPoint::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteChildrenAnchorPoint::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteChildrenAnchorPoint::subtitle() const
|
|
|
|
{
|
|
|
|
return "children + anchor point";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeChildrenAnchorPoint
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteBatchNodeChildrenAnchorPoint::SpriteBatchNodeChildrenAnchorPoint()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
Node *aParent;
|
|
|
|
Sprite* sprite1, *sprite2, *sprite3, *sprite4, *point;
|
|
|
|
//
|
|
|
|
// SpriteBatchNode
|
|
|
|
//
|
|
|
|
// parents
|
|
|
|
|
|
|
|
aParent = SpriteBatchNode::create("animations/grossini.png", 50);
|
|
|
|
addChild(aParent, 0);
|
|
|
|
|
|
|
|
// anchor (0,0)
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2(s.width/4,s.height/2));
|
|
|
|
sprite1->setAnchorPoint( Vec2::ANCHOR_BOTTOM_LEFT );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite4->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite4->setScale( 0.5f );
|
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, -2);
|
|
|
|
sprite1->addChild(sprite4, 3);
|
|
|
|
|
|
|
|
point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
|
|
|
|
// anchor (0.5, 0.5)
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2(s.width/2,s.height/2));
|
|
|
|
sprite1->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite4->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite4->setScale( 0.5f );
|
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, -2);
|
|
|
|
sprite1->addChild(sprite4, 3);
|
|
|
|
|
|
|
|
point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
|
|
|
|
// anchor (1,1)
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2(s.width/2+s.width/4,s.height/2));
|
|
|
|
sprite1->setAnchorPoint( Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite2->setPosition(Vec2(20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite3->setPosition(Vec2(-20.0f,30.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite4->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite4->setScale( 0.5f );
|
|
|
|
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2, -2);
|
|
|
|
sprite1->addChild(sprite3, -2);
|
|
|
|
sprite1->addChild(sprite4, 3);
|
|
|
|
|
|
|
|
point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale( 0.25f );
|
|
|
|
point->setPosition( sprite1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeChildrenAnchorPoint::onExit()
|
|
|
|
{
|
|
|
|
SpriteTestDemo::onExit();
|
|
|
|
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeChildrenAnchorPoint::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeChildrenAnchorPoint::subtitle() const
|
|
|
|
{
|
|
|
|
return "children + anchor point";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeChildrenScale
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteBatchNodeChildrenScale::SpriteBatchNodeChildrenScale()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
|
|
|
|
|
|
|
|
Node *aParent;
|
|
|
|
Sprite* sprite1, *sprite2;
|
|
|
|
auto rot = RotateBy::create(10, 360);
|
|
|
|
auto seq = RepeatForever::create(rot);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Children + Scale using Sprite
|
|
|
|
// Test 1
|
|
|
|
//
|
|
|
|
aParent = Node::create();
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( s.width/4, s.height/4) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite1->setScaleX( -0.5f );
|
|
|
|
sprite1->setScaleY( 2.0f );
|
|
|
|
sprite1->runAction(seq);
|
|
|
|
|
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition( Vec2( 50,0) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
addChild(aParent);
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Children + Scale using SpriteBatchNode
|
|
|
|
// Test 2
|
|
|
|
//
|
|
|
|
|
|
|
|
aParent = SpriteBatchNode::create("animations/grossini_family.png");
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( 3*s.width/4, s.height/4) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite1->setScaleX( -0.5f );
|
|
|
|
sprite1->setScaleY( 2.0f );
|
|
|
|
sprite1->runAction( seq->clone() );
|
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition( Vec2( 50,0) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
addChild(aParent);
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Children + Scale using Sprite
|
|
|
|
// Test 3
|
|
|
|
//
|
|
|
|
|
|
|
|
aParent = Node::create();
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( s.width/4, 2*s.height/3) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite1->setScaleX( 1.5f );
|
|
|
|
sprite1->setScaleY( -0.5f );
|
|
|
|
sprite1->runAction( seq->clone() );
|
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition( Vec2( 50,0) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
addChild(aParent);
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Children + Scale using Sprite
|
|
|
|
// Test 4
|
|
|
|
//
|
|
|
|
|
|
|
|
aParent = SpriteBatchNode::create("animations/grossini_family.png");
|
|
|
|
sprite1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition( Vec2( 3*s.width/4, 2*s.height/3) );
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite1->setScaleX( 1.5f );
|
|
|
|
sprite1->setScaleY( -0.5f);
|
|
|
|
sprite1->runAction( seq->clone() );
|
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition( Vec2( 50,0) );
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
addChild(aParent);
|
|
|
|
aParent->addChild(sprite1);
|
|
|
|
sprite1->addChild(sprite2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeChildrenScale::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite / SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeChildrenScale::subtitle() const
|
|
|
|
{
|
|
|
|
return "child + scale + rot";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteChildrenChildren
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteChildrenChildren::SpriteChildrenChildren()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist");
|
|
|
|
|
|
|
|
Node *aParent;
|
|
|
|
Sprite *l1, *l2a, *l2b, *l3a1, *l3a2, *l3b1, *l3b2;
|
|
|
|
auto rot = RotateBy::create(10, 360);
|
|
|
|
auto seq = RepeatForever::create(rot);
|
|
|
|
|
|
|
|
auto rot_back = rot->reverse();
|
|
|
|
auto rot_back_fe = RepeatForever::create(rot_back);
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteBatchNode: 3 levels of children
|
|
|
|
//
|
|
|
|
|
|
|
|
aParent = Node::create();
|
|
|
|
addChild(aParent);
|
|
|
|
|
|
|
|
// parent
|
|
|
|
l1 = Sprite::createWithSpriteFrameName("father.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l1->setPosition( Vec2( s.width/2, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l1->runAction( seq->clone() );
|
|
|
|
aParent->addChild(l1);
|
|
|
|
auto l1Size = l1->getContentSize();
|
|
|
|
|
|
|
|
// child left
|
|
|
|
l2a = Sprite::createWithSpriteFrameName("sister1.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l2a->setPosition( Vec2( -50 + l1Size.width/2, 0 + l1Size.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->runAction( rot_back_fe->clone() );
|
|
|
|
l1->addChild(l2a);
|
|
|
|
auto l2aSize = l2a->getContentSize();
|
|
|
|
|
|
|
|
|
|
|
|
// child right
|
|
|
|
l2b = Sprite::createWithSpriteFrameName("sister2.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l2b->setPosition( Vec2( +50 + l1Size.width/2, 0 + l1Size.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->runAction( rot_back_fe->clone() );
|
|
|
|
l1->addChild(l2b);
|
|
|
|
auto l2bSize = l2a->getContentSize();
|
|
|
|
|
|
|
|
|
|
|
|
// child left bottom
|
|
|
|
l3a1 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3a1->setScale( 0.45f );
|
2014-05-15 01:07:09 +08:00
|
|
|
l3a1->setPosition( Vec2(0+l2aSize.width/2,-100+l2aSize.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->addChild(l3a1);
|
|
|
|
|
|
|
|
// child left top
|
|
|
|
l3a2 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3a2->setScale( 0.45f );
|
2014-05-15 01:07:09 +08:00
|
|
|
l3a1->setPosition( Vec2(0+l2aSize.width/2,+100+l2aSize.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->addChild(l3a2);
|
|
|
|
|
|
|
|
// child right bottom
|
|
|
|
l3b1 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3b1->setScale( 0.45f);
|
|
|
|
l3b1->setFlippedY( true );
|
2014-05-15 01:07:09 +08:00
|
|
|
l3b1->setPosition( Vec2(0+l2bSize.width/2,-100+l2bSize.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->addChild(l3b1);
|
|
|
|
|
|
|
|
// child right top
|
|
|
|
l3b2 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3b2->setScale( 0.45f );
|
|
|
|
l3b2->setFlippedY( true );
|
2014-05-15 01:07:09 +08:00
|
|
|
l3b1->setPosition( Vec2(0+l2bSize.width/2,+100+l2bSize.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->addChild(l3b2);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteChildrenChildren::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteChildrenChildren::subtitle() const
|
|
|
|
{
|
|
|
|
return "multiple levels of children";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeChildrenChildren
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeChildrenChildren::SpriteBatchNodeChildrenChildren()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist");
|
|
|
|
|
|
|
|
SpriteBatchNode *aParent;
|
|
|
|
Sprite *l1, *l2a, *l2b, *l3a1, *l3a2, *l3b1, *l3b2;
|
|
|
|
auto rot = RotateBy::create(10, 360);
|
|
|
|
auto seq = RepeatForever::create(rot);
|
|
|
|
|
|
|
|
auto rot_back = rot->reverse();
|
|
|
|
auto rot_back_fe = RepeatForever::create(rot_back);
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteBatchNode: 3 levels of children
|
|
|
|
//
|
|
|
|
|
|
|
|
aParent = SpriteBatchNode::create("animations/ghosts.png");
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
//TODO: minggo
|
|
|
|
// aParent->getTexture()->generateMipmap();
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(aParent);
|
|
|
|
|
|
|
|
// parent
|
|
|
|
l1 = Sprite::createWithSpriteFrameName("father.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l1->setPosition( Vec2( s.width/2, s.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l1->runAction( seq->clone() );
|
|
|
|
aParent->addChild(l1);
|
|
|
|
auto l1Size = l1->getContentSize();
|
|
|
|
|
|
|
|
// child left
|
|
|
|
l2a = Sprite::createWithSpriteFrameName("sister1.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l2a->setPosition( Vec2( -50 + l1Size.width/2, 0 + l1Size.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->runAction( rot_back_fe->clone() );
|
|
|
|
l1->addChild(l2a);
|
|
|
|
auto l2aSize = l2a->getContentSize();
|
|
|
|
|
|
|
|
|
|
|
|
// child right
|
|
|
|
l2b = Sprite::createWithSpriteFrameName("sister2.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l2b->setPosition( Vec2( +50 + l1Size.width/2, 0 + l1Size.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->runAction( rot_back_fe->clone() );
|
|
|
|
l1->addChild(l2b);
|
|
|
|
auto l2bSize = l2a->getContentSize();
|
|
|
|
|
|
|
|
|
|
|
|
// child left bottom
|
|
|
|
l3a1 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3a1->setScale( 0.45f );
|
2014-05-15 01:07:09 +08:00
|
|
|
l3a1->setPosition( Vec2(0+l2aSize.width/2,-100+l2aSize.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->addChild(l3a1);
|
|
|
|
|
|
|
|
// child left top
|
|
|
|
l3a2 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3a2->setScale( 0.45f );
|
2014-05-15 01:07:09 +08:00
|
|
|
l3a1->setPosition( Vec2(0+l2aSize.width/2,+100+l2aSize.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->addChild(l3a2);
|
|
|
|
|
|
|
|
// child right bottom
|
|
|
|
l3b1 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3b1->setScale( 0.45f );
|
|
|
|
l3b1->setFlippedY( true );
|
2014-05-15 01:07:09 +08:00
|
|
|
l3b1->setPosition( Vec2(0+l2bSize.width/2,-100+l2bSize.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->addChild(l3b1);
|
|
|
|
|
|
|
|
// child right top
|
|
|
|
l3b2 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3b2->setScale( 0.45f );
|
|
|
|
l3b2->setFlippedY( true );
|
2014-05-15 01:07:09 +08:00
|
|
|
l3b1->setPosition( Vec2(0+l2bSize.width/2,+100+l2bSize.height/2) );
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->addChild(l3b2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeChildrenChildren::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeChildrenChildren::subtitle() const
|
|
|
|
{
|
|
|
|
return "multiple levels of children";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeSkewNegativeScaleChildren
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteBatchNodeSkewNegativeScaleChildren::SpriteBatchNodeSkewNegativeScaleChildren()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
addChild(spritebatch);
|
|
|
|
|
|
|
|
for(int i=0;i<2;i++) {
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2( s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// Skew
|
|
|
|
auto skewX = SkewBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = SkewBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
|
|
|
if(i == 1)
|
|
|
|
{
|
|
|
|
sprite->setScale(-1.0f);
|
|
|
|
}
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
auto child1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
child1->setPosition(Vec2(sprite->getContentSize().width / 2.0f, sprite->getContentSize().height / 2.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
child1->setScale(0.8f);
|
|
|
|
|
|
|
|
sprite->addChild(child1);
|
|
|
|
|
|
|
|
spritebatch->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteBatchNodeSkewNegativeScaleChildren::~SpriteBatchNodeSkewNegativeScaleChildren()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeSkewNegativeScaleChildren::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeSkewNegativeScaleChildren::subtitle() const
|
|
|
|
{
|
|
|
|
return "skew + negative scale with children";
|
|
|
|
}
|
|
|
|
|
|
|
|
// SpriteSkewNegativeScaleChildren
|
|
|
|
|
|
|
|
SpriteSkewNegativeScaleChildren::SpriteSkewNegativeScaleChildren()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto parent = Node::create();
|
|
|
|
addChild(parent);
|
|
|
|
|
|
|
|
for(int i=0;i<2;i++) {
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2( s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// Skew
|
|
|
|
auto skewX = SkewBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = SkewBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
|
|
|
if(i == 1)
|
|
|
|
{
|
|
|
|
sprite->setScale(-1.0f);
|
|
|
|
}
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
auto child1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
child1->setPosition(Vec2(sprite->getContentSize().width / 2.0f, sprite->getContentSize().height / 2.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite->addChild(child1);
|
|
|
|
|
|
|
|
child1->setScale(0.8f);
|
|
|
|
|
|
|
|
parent->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteSkewNegativeScaleChildren::~SpriteSkewNegativeScaleChildren()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteSkewNegativeScaleChildren::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteSkewNegativeScaleChildren::subtitle() const
|
|
|
|
{
|
|
|
|
return "skew + negative scale with children";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteNilTexture
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteNilTexture::SpriteNilTexture()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
Sprite* sprite = nullptr;
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// TEST: If no texture is given, then Opacity + Color should work.
|
|
|
|
|
|
|
|
sprite = Sprite::create();
|
|
|
|
sprite->setTextureRect( Rect(0, 0, 300,300) );
|
|
|
|
sprite->setColor(Color3B::RED);
|
|
|
|
sprite->setOpacity(128);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(3*s.width/4, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(sprite, 100);
|
|
|
|
|
|
|
|
sprite = Sprite::create();
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite->setTextureRect(Rect(0.0f, 0.0f, 300.0f,300.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->setColor(Color3B::BLUE);
|
|
|
|
sprite->setOpacity(128);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(1*s.width/4, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(sprite, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteNilTexture::title() const
|
|
|
|
{
|
|
|
|
return "Sprite without texture";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteNilTexture::subtitle() const
|
|
|
|
{
|
|
|
|
return "opacity and color should work";
|
|
|
|
}
|
|
|
|
|
|
|
|
class MySprite1 : public Sprite
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(MySprite1);
|
2015-05-01 17:24:04 +08:00
|
|
|
MySprite1() {}
|
2014-05-04 14:37:55 +08:00
|
|
|
static MySprite1* createWithSpriteFrameName(const std::string& spriteFrameName)
|
|
|
|
{
|
|
|
|
auto sprite = MySprite1::create();
|
|
|
|
sprite->setSpriteFrame(spriteFrameName);
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MySprite2 : public Sprite
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(MySprite2);
|
2015-05-01 17:24:04 +08:00
|
|
|
MySprite2() {}
|
2014-05-04 14:37:55 +08:00
|
|
|
static MySprite2* create(const std::string& name)
|
|
|
|
{
|
|
|
|
auto sprite = MySprite2::create();
|
|
|
|
sprite ->setTexture(name);
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteSubclass
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSubclass::SpriteSubclass()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist");
|
|
|
|
auto aParent = SpriteBatchNode::create("animations/ghosts.png");
|
|
|
|
|
|
|
|
// MySprite1
|
|
|
|
MySprite1 *sprite = MySprite1::createWithSpriteFrameName("father.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2( s.width/4*1, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
aParent->addChild(sprite);
|
|
|
|
addChild(aParent);
|
|
|
|
|
|
|
|
// MySprite2
|
|
|
|
MySprite2 *sprite2 = MySprite2::create("Images/grossini.png");
|
|
|
|
addChild(sprite2);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition(Vec2(s.width/4*3, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteSubclass::title() const
|
|
|
|
{
|
|
|
|
return "Sprite subclass";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteSubclass::subtitle() const
|
|
|
|
{
|
|
|
|
return "Testing initWithTexture:rect method";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// AnimationCache
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
AnimationCacheTest::AnimationCacheTest()
|
|
|
|
{
|
|
|
|
auto frameCache = SpriteFrameCache::getInstance();
|
|
|
|
frameCache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
frameCache->addSpriteFramesWithFile("animations/grossini_gray.plist");
|
|
|
|
frameCache->addSpriteFramesWithFile("animations/grossini_blue.plist");
|
|
|
|
|
|
|
|
//
|
|
|
|
// create animation "dance"
|
|
|
|
//
|
|
|
|
Vector<SpriteFrame*> animFrames(15);
|
|
|
|
char str[100] = {0};
|
|
|
|
for(int i = 1; i < 15; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_%02d.png",i);
|
|
|
|
auto frame = frameCache->getSpriteFrameByName(str);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
|
|
|
|
|
|
|
|
// Add an animation to the Cache
|
|
|
|
AnimationCache::getInstance()->addAnimation(animation, "dance");
|
|
|
|
|
|
|
|
//
|
|
|
|
// create animation "dance gray"
|
|
|
|
//
|
|
|
|
animFrames.clear();
|
|
|
|
|
|
|
|
for(int i = 1; i < 15; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_dance_gray_%02d.png",i);
|
|
|
|
auto frame = frameCache->getSpriteFrameByName(str);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
|
|
|
|
|
|
|
|
// Add an animation to the Cache
|
|
|
|
AnimationCache::getInstance()->addAnimation(animation, "dance_gray");
|
|
|
|
|
|
|
|
//
|
|
|
|
// create animation "dance blue"
|
|
|
|
//
|
|
|
|
animFrames.clear();
|
|
|
|
|
|
|
|
for(int i = 1; i < 4; i++)
|
|
|
|
{
|
|
|
|
sprintf(str, "grossini_blue_%02d.png",i);
|
|
|
|
auto frame = frameCache->getSpriteFrameByName(str);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
|
|
|
|
|
|
|
|
// Add an animation to the Cache
|
|
|
|
AnimationCache::getInstance()->addAnimation(animation, "dance_blue");
|
|
|
|
|
|
|
|
|
|
|
|
auto animCache = AnimationCache::getInstance();
|
|
|
|
|
|
|
|
auto normal = animCache->getAnimation("dance");
|
|
|
|
normal->setRestoreOriginalFrame(true);
|
|
|
|
auto dance_grey = animCache->getAnimation("dance_gray");
|
|
|
|
dance_grey->setRestoreOriginalFrame(true);
|
|
|
|
auto dance_blue = animCache->getAnimation("dance_blue");
|
|
|
|
dance_blue->setRestoreOriginalFrame(true);
|
|
|
|
|
|
|
|
auto animN = Animate::create(normal);
|
|
|
|
auto animG = Animate::create(dance_grey);
|
|
|
|
auto animB = Animate::create(dance_blue);
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(animN, animG, animB, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// create an sprite without texture
|
|
|
|
auto grossini = Sprite::create();
|
|
|
|
auto frame = frameCache->getSpriteFrameByName("grossini_dance_01.png");
|
|
|
|
grossini->setSpriteFrame(frame);
|
|
|
|
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
grossini->setPosition(Vec2(winSize.width/2, winSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
addChild(grossini);
|
|
|
|
|
|
|
|
// run the animation
|
|
|
|
grossini->runAction(seq);
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:45:38 +08:00
|
|
|
AnimationCacheTest::~AnimationCacheTest()
|
|
|
|
{
|
|
|
|
auto frameCache = SpriteFrameCache::getInstance();
|
|
|
|
frameCache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
frameCache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
frameCache->removeSpriteFramesFromFile("animations/grossini_blue.plist");
|
|
|
|
}
|
|
|
|
|
2014-05-04 14:37:55 +08:00
|
|
|
std::string AnimationCacheTest::title() const
|
|
|
|
{
|
|
|
|
return "AnimationCache";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AnimationCacheTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "Sprite should be animated";
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnimationCacheFile
|
|
|
|
|
|
|
|
|
|
|
|
AnimationCacheFile::AnimationCacheFile()
|
|
|
|
{
|
|
|
|
auto frameCache = SpriteFrameCache::getInstance();
|
|
|
|
frameCache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
frameCache->addSpriteFramesWithFile("animations/grossini_gray.plist");
|
|
|
|
frameCache->addSpriteFramesWithFile("animations/grossini_blue.plist");
|
|
|
|
|
|
|
|
|
|
|
|
// Purge previously loaded animation
|
|
|
|
AnimationCache::destroyInstance();
|
|
|
|
|
|
|
|
auto animCache = AnimationCache::getInstance();
|
|
|
|
|
|
|
|
// Add an animation to the Cache
|
|
|
|
animCache->addAnimationsWithFile("animations/animations.plist");
|
|
|
|
|
|
|
|
|
|
|
|
auto normal = animCache->getAnimation("dance_1");
|
|
|
|
normal->setRestoreOriginalFrame(true);
|
|
|
|
auto dance_grey = animCache->getAnimation("dance_2");
|
|
|
|
dance_grey->setRestoreOriginalFrame(true);
|
|
|
|
auto dance_blue = animCache->getAnimation("dance_3");
|
|
|
|
dance_blue->setRestoreOriginalFrame(true);
|
|
|
|
|
|
|
|
auto animN = Animate::create(normal);
|
|
|
|
auto animG = Animate::create(dance_grey);
|
|
|
|
auto animB = Animate::create(dance_blue);
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(animN, animG, animB, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// create an sprite without texture
|
|
|
|
auto grossini = Sprite::create();
|
|
|
|
|
|
|
|
auto frame = frameCache->getSpriteFrameByName("grossini_dance_01.png");
|
|
|
|
grossini->setSpriteFrame(frame);
|
|
|
|
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
grossini->setPosition(Vec2(winSize.width/2, winSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
addChild(grossini);
|
|
|
|
|
|
|
|
|
|
|
|
// run the animation
|
|
|
|
grossini->runAction(seq);
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:45:38 +08:00
|
|
|
AnimationCacheFile::~AnimationCacheFile()
|
|
|
|
{
|
|
|
|
auto frameCache = SpriteFrameCache::getInstance();
|
|
|
|
frameCache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
frameCache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
frameCache->removeSpriteFramesFromFile("animations/grossini_blue.plist");
|
|
|
|
}
|
|
|
|
|
2014-05-04 14:37:55 +08:00
|
|
|
std::string AnimationCacheFile::title() const
|
|
|
|
{
|
|
|
|
return "AnimationCache - Load file";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AnimationCacheFile::subtitle() const
|
|
|
|
{
|
|
|
|
return "Sprite should be animated";
|
|
|
|
}
|
|
|
|
|
|
|
|
// SpriteBatchBug1217
|
|
|
|
|
|
|
|
SpriteBatchBug1217::SpriteBatchBug1217()
|
|
|
|
{
|
|
|
|
auto bn = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 15);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
auto s1 = Sprite::createWithTexture(bn->getTexture(), Rect(0.0f, 0.0f, 57.0f, 57.0f));
|
|
|
|
auto s2 = Sprite::createWithTexture(bn->getTexture(), Rect(0.0f, 0.0f, 57.0f, 57.0f));
|
|
|
|
auto s3 = Sprite::createWithTexture(bn->getTexture(), Rect(0.0f, 0.0f, 57.0f, 57.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
s1->setColor(Color3B(255, 0, 0));
|
|
|
|
s2->setColor(Color3B(0, 255, 0));
|
|
|
|
s3->setColor(Color3B(0, 0, 255));
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
s1->setPosition(Vec2(20.0f,200.0f));
|
|
|
|
s2->setPosition(Vec2(100.0f,0.0f));
|
|
|
|
s3->setPosition(Vec2(100.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
bn->setPosition(Vec2(0.0f,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
//!!!!!
|
|
|
|
s1->addChild(s2);
|
|
|
|
s2->addChild(s3);
|
|
|
|
bn->addChild(s1);
|
|
|
|
|
|
|
|
addChild(bn);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchBug1217::title() const
|
|
|
|
{
|
|
|
|
return "SpriteBatch - Bug 1217";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchBug1217::subtitle() const
|
|
|
|
{
|
|
|
|
return "Adding big family to spritebatch. You shall see 3 heads";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteOffsetAnchorSkew
|
|
|
|
//
|
|
|
|
SpriteOffsetAnchorSkew::SpriteOffsetAnchorSkew()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
addChild(point, 1);
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char tmp[50];
|
|
|
|
for (int j = 0; j < 14; j++)
|
|
|
|
{
|
|
|
|
sprintf(tmp, "grossini_dance_%02d.png", j + 1);
|
|
|
|
auto frame = cache->getSpriteFrameByName(tmp);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
auto skewX = SkewBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = SkewBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
addChild(sprite, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteOffsetAnchorSkew::~SpriteOffsetAnchorSkew()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorSkew::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorSkew::subtitle() const
|
|
|
|
{
|
|
|
|
return "offset + anchor + skew";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeOffsetAnchorSkew
|
|
|
|
//
|
|
|
|
SpriteBatchNodeOffsetAnchorSkew::SpriteBatchNodeOffsetAnchorSkew()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
addChild(spritebatch);
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
addChild(point, 200);
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char tmp[50];
|
|
|
|
for (int j = 0; j < 14; j++)
|
|
|
|
{
|
|
|
|
sprintf(tmp, "grossini_dance_%02d.png", j + 1);
|
|
|
|
auto frame = cache->getSpriteFrameByName(tmp);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
auto skewX = SkewBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = SkewBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
spritebatch->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteBatchNodeOffsetAnchorSkew::~SpriteBatchNodeOffsetAnchorSkew()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorSkew::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorSkew::subtitle() const
|
|
|
|
{
|
|
|
|
return "offset + anchor + skew";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteOffsetAnchorSkewScale
|
|
|
|
//
|
|
|
|
SpriteOffsetAnchorSkewScale::SpriteOffsetAnchorSkewScale()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
addChild(point, 1);
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char tmp[50];
|
|
|
|
for (int j = 0; j < 14; j++)
|
|
|
|
{
|
|
|
|
sprintf(tmp, "grossini_dance_%02d.png", j + 1);
|
|
|
|
auto frame = cache->getSpriteFrameByName(tmp);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
// Skew
|
|
|
|
auto skewX = SkewBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = SkewBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
// Scale
|
|
|
|
auto scale = ScaleBy::create(2, 2);
|
|
|
|
auto scale_back = scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_scale));
|
|
|
|
|
|
|
|
addChild(sprite, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteOffsetAnchorSkewScale::~SpriteOffsetAnchorSkewScale()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorSkewScale::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorSkewScale::subtitle() const
|
|
|
|
{
|
|
|
|
return "anchor + skew + scale";
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
SpriteBatchNodeOffsetAnchorSkewScale::SpriteBatchNodeOffsetAnchorSkewScale()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
addChild(spritebatch);
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
addChild(point, 200);
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char tmp[50];
|
|
|
|
for (int j = 0; j < 14; j++)
|
|
|
|
{
|
|
|
|
sprintf(tmp, "grossini_dance_%02d.png", j + 1);
|
|
|
|
auto frame = cache->getSpriteFrameByName(tmp);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
// skew
|
|
|
|
auto skewX = SkewBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = SkewBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
// scale
|
|
|
|
auto scale = ScaleBy::create(2, 2);
|
|
|
|
auto scale_back = scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_scale));
|
|
|
|
|
|
|
|
spritebatch->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteBatchNodeOffsetAnchorSkewScale::~SpriteBatchNodeOffsetAnchorSkewScale()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorSkewScale::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorSkewScale::subtitle() const
|
|
|
|
{
|
|
|
|
return "anchor + skew + scale";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteOffsetAnchorFlip
|
|
|
|
//
|
|
|
|
SpriteOffsetAnchorFlip::SpriteOffsetAnchorFlip()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
addChild(point, 1);
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char tmp[50];
|
|
|
|
for (int j = 0; j < 14; j++)
|
|
|
|
{
|
|
|
|
sprintf(tmp, "grossini_dance_%02d.png", i + 1);
|
|
|
|
auto frame = cache->getSpriteFrameByName(tmp);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
auto flip = FlipY::create(true);
|
|
|
|
auto flip_back = FlipY::create(false);
|
|
|
|
auto delay = DelayTime::create(1);
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(delay, flip, delay->clone(), flip_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq));
|
|
|
|
|
|
|
|
addChild(sprite, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteOffsetAnchorFlip::~SpriteOffsetAnchorFlip()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorFlip::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorFlip::subtitle() const
|
|
|
|
{
|
|
|
|
return "issue #1078: offset + anchor + flip";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeOffsetAnchorFlip
|
|
|
|
//
|
|
|
|
|
|
|
|
SpriteBatchNodeOffsetAnchorFlip::SpriteBatchNodeOffsetAnchorFlip()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
addChild(spritebatch);
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
addChild(point, 200);
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT );
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
char tmp[50];
|
|
|
|
for (int j = 0; j < 14; j++)
|
|
|
|
{
|
|
|
|
sprintf(tmp, "grossini_dance_%02d.png", i + 1);
|
|
|
|
auto frame = cache->getSpriteFrameByName(tmp);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
auto flip = FlipY::create(true);
|
|
|
|
auto flip_back = FlipY::create(false);
|
|
|
|
auto delay = DelayTime::create(1);
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(delay, flip, delay->clone(), flip_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq));
|
|
|
|
|
|
|
|
spritebatch->addChild(sprite, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteBatchNodeOffsetAnchorFlip::~SpriteBatchNodeOffsetAnchorFlip()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorFlip::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorFlip::subtitle() const
|
|
|
|
{
|
|
|
|
return "issue #1078: offset + anchor + flip";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// NodeSort
|
|
|
|
|
|
|
|
NodeSort::NodeSort()
|
|
|
|
{
|
|
|
|
_node = Node::create();
|
|
|
|
addChild(_node, 0, 0);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite1 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
|
|
|
|
_sprite1->setPosition(Vec2(100.0f, 160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_node->addChild(_sprite1, -6, 1);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite2 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
|
|
|
|
_sprite2->setPosition(Vec2(164.0f, 160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_node->addChild(_sprite2, -6, 2);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite4 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
|
|
|
|
_sprite4->setPosition(Vec2(292.0f, 160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_node->addChild(_sprite4, -3, 4);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite3 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
|
|
|
|
_sprite3->setPosition(Vec2(228.0f, 160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_node->addChild(_sprite3, -4, 3);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite5 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
|
|
|
|
_sprite5->setPosition(Vec2(356.0f, 160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_node->addChild(_sprite5, -3, 5);
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
schedule(CC_CALLBACK_1(NodeSort::reorderSprite, this), "reorder_sprite_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string NodeSort::title() const
|
|
|
|
{
|
|
|
|
return "node sort same index";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string NodeSort::subtitle() const
|
|
|
|
{
|
|
|
|
return "tag order in console should be 2,1,3,4,5";
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeSort::reorderSprite(float dt)
|
|
|
|
{
|
2014-10-04 08:11:39 +08:00
|
|
|
unschedule("reorder_sprite_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
log("Before reorder--");
|
|
|
|
|
|
|
|
auto& children = _node->getChildren();
|
|
|
|
|
|
|
|
for(const auto &child : children) {
|
|
|
|
log("tag %i z %i",(int)child->getTag(),(int)child->getLocalZOrder());
|
|
|
|
}
|
|
|
|
//z-4
|
|
|
|
_node->reorderChild( _node->getChildren().at(0), -6);
|
|
|
|
|
|
|
|
_node->sortAllChildren();
|
|
|
|
|
|
|
|
log("After reorder--");
|
|
|
|
for(const auto &child : children) {
|
|
|
|
log("tag %i z %i",(int)child->getTag(),(int)child->getLocalZOrder());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// SpriteBatchNodeReorderSameIndex
|
|
|
|
SpriteBatchNodeReorderSameIndex::SpriteBatchNodeReorderSameIndex()
|
|
|
|
{
|
|
|
|
_batchNode = SpriteBatchNode::create("Images/piece.png", 15);
|
|
|
|
addChild(_batchNode, 1, 0);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite1 = Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f,0.0f,64.0f,64.0f));
|
|
|
|
_sprite1->setPosition(Vec2(100.0f,160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_batchNode->addChild(_sprite1, 3, 1);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite2= Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f,0.0f,64.0f,64.0f));
|
|
|
|
_sprite2->setPosition(Vec2(164.0f,160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_batchNode->addChild(_sprite2, 4, 2);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite3 = Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f,0.0f,64.0f,64.0f));
|
|
|
|
_sprite3->setPosition(Vec2(228.0f,160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_batchNode->addChild(_sprite3, 4, 3);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite4 = Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f,0.0f,64.0f,64.0f));
|
|
|
|
_sprite4->setPosition(Vec2(292.0f,160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_batchNode->addChild(_sprite4, 5, 4);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
_sprite5 = Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f,0.0f,64.0f,64.0f));
|
|
|
|
_sprite5->setPosition(Vec2(356.0f,160.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
_batchNode->addChild(_sprite5, 6, 5);
|
|
|
|
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
scheduleOnce(CC_CALLBACK_1(SpriteBatchNodeReorderSameIndex::reorderSprite, this), 2, "reorder_sprite_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorderSameIndex::title() const
|
|
|
|
{
|
|
|
|
return "SpriteBatchNodeReorder same index";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorderSameIndex::subtitle() const
|
|
|
|
{
|
|
|
|
return "tag order in console should be 2,3,4,5,1";
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeReorderSameIndex::reorderSprite(float dt)
|
|
|
|
{
|
|
|
|
_batchNode->reorderChild(_sprite4, 4);
|
|
|
|
_batchNode->reorderChild(_sprite5, 4);
|
|
|
|
_batchNode->reorderChild(_sprite1, 4);
|
|
|
|
|
|
|
|
_batchNode->sortAllChildren();
|
|
|
|
|
|
|
|
for(const auto &sprite : _batchNode->getDescendants()) {
|
|
|
|
log("tag %i", sprite->getTag() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// SpriteBatchNodeReorderOneChild
|
|
|
|
SpriteBatchNodeReorderOneChild::SpriteBatchNodeReorderOneChild()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist");
|
|
|
|
|
|
|
|
SpriteBatchNode *aParent;
|
|
|
|
Sprite *l1, *l2a, *l2b, *l3a1, *l3a2, *l3b1, *l3b2;
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteBatchNode: 3 levels of children
|
|
|
|
//
|
|
|
|
|
|
|
|
aParent = SpriteBatchNode::create("animations/ghosts.png");
|
|
|
|
|
|
|
|
_batchNode = aParent;
|
|
|
|
//[[aParent texture] generateMipmap];
|
|
|
|
addChild(aParent);
|
|
|
|
|
|
|
|
// parent
|
|
|
|
l1 = Sprite::createWithSpriteFrameName("father.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l1->setPosition(Vec2( s.width/2, s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
aParent->addChild(l1);
|
|
|
|
auto l1Size = l1->getContentSize();
|
|
|
|
|
|
|
|
// child left
|
|
|
|
l2a = Sprite::createWithSpriteFrameName("sister1.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l2a->setPosition(Vec2( -10 + l1Size.width/2, 0 + l1Size.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
l1->addChild(l2a, 1);
|
|
|
|
auto l2aSize = l2a->getContentSize();
|
|
|
|
|
|
|
|
|
|
|
|
// child right
|
|
|
|
l2b = Sprite::createWithSpriteFrameName("sister2.gif");
|
2014-05-15 01:07:09 +08:00
|
|
|
l2b->setPosition(Vec2( +50 + l1Size.width/2, 0 + l1Size.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
l1->addChild(l2b, 2);
|
|
|
|
auto l2bSize = l2a->getContentSize();
|
|
|
|
|
|
|
|
|
|
|
|
// child left bottom
|
|
|
|
l3a1 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3a1->setScale(0.45f);
|
2014-05-15 01:07:09 +08:00
|
|
|
l3a1->setPosition(Vec2(0+l2aSize.width/2,-50+l2aSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->addChild(l3a1, 1);
|
|
|
|
|
|
|
|
// child left top
|
|
|
|
l3a2 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3a2->setScale(0.45f);
|
2014-05-15 01:07:09 +08:00
|
|
|
l3a2->setPosition(Vec2(0+l2aSize.width/2,+50+l2aSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l2a->addChild(l3a2, 2);
|
|
|
|
|
|
|
|
_reorderSprite = l2a;
|
|
|
|
|
|
|
|
// child right bottom
|
|
|
|
l3b1 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3b1->setScale(0.45f);
|
|
|
|
l3b1->setFlippedY(true);
|
2014-05-15 01:07:09 +08:00
|
|
|
l3b1->setPosition(Vec2(0+l2bSize.width/2,-50+l2bSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->addChild(l3b1);
|
|
|
|
|
|
|
|
// child right top
|
|
|
|
l3b2 = Sprite::createWithSpriteFrameName("child1.gif");
|
|
|
|
l3b2->setScale(0.45f);
|
|
|
|
l3b2->setFlippedY(true);
|
2014-05-15 01:07:09 +08:00
|
|
|
l3b2->setPosition(Vec2(0+l2bSize.width/2,+50+l2bSize.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
l2b->addChild(l3b2);
|
|
|
|
|
2014-10-04 08:11:39 +08:00
|
|
|
scheduleOnce(CC_CALLBACK_1(SpriteBatchNodeReorderOneChild::reorderSprite, this), 2.0f, "reorder_sprite_key");
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteBatchNodeReorderOneChild::reorderSprite(float dt)
|
|
|
|
{
|
|
|
|
_reorderSprite->getParent()->reorderChild(_reorderSprite, -1);
|
|
|
|
|
|
|
|
_batchNode->sortAllChildren();
|
|
|
|
//CCSprite* child;
|
|
|
|
//CCARRAY_FOREACH(batchNode.descendants,child) NSLog(@"tag %i",child.tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeReorderOneChild::title() const
|
|
|
|
{
|
|
|
|
return "SpriteBatchNode reorder 1 child";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteOffsetAnchorRotationalSkew
|
|
|
|
//
|
|
|
|
SpriteOffsetAnchorRotationalSkew::SpriteOffsetAnchorRotationalSkew()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
addChild(point, 1);
|
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
for(int i = 0; i < 14; i++)
|
|
|
|
{
|
|
|
|
char pngName[30];
|
|
|
|
snprintf(pngName, 30, "grossini_dance_%02d.png", (i+1));
|
|
|
|
auto frame = cache->getSpriteFrameByName(pngName);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
auto skewX = RotateBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = RotateBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
addChild(sprite, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteOffsetAnchorRotationalSkew::~SpriteOffsetAnchorRotationalSkew()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorRotationalSkew::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorRotationalSkew::subtitle() const
|
|
|
|
{
|
|
|
|
return "offset + anchor + rotational skew";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeOffsetAnchorRotationalSkew
|
|
|
|
//
|
|
|
|
SpriteBatchNodeOffsetAnchorRotationalSkew::SpriteBatchNodeOffsetAnchorRotationalSkew()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
addChild(spritebatch);
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
2016-02-09 03:25:37 +08:00
|
|
|
addChild(point, 1);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
for(int j = 0; j < 14; j++)
|
|
|
|
{
|
|
|
|
char pngName[30];
|
|
|
|
snprintf(pngName, 30, "grossini_dance_%02d.png", (j+1));
|
|
|
|
auto frame = cache->getSpriteFrameByName(pngName);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
auto skewX = RotateBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = RotateBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
2016-02-09 03:25:37 +08:00
|
|
|
spritebatch->addChild(sprite, 0);
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteBatchNodeOffsetAnchorRotationalSkew::~SpriteBatchNodeOffsetAnchorRotationalSkew()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorRotationalSkew::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorRotationalSkew::subtitle() const
|
|
|
|
{
|
|
|
|
return "offset + anchor + rotational skew";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteOffsetAnchorRotationalSkewScale
|
|
|
|
//
|
|
|
|
SpriteOffsetAnchorRotationalSkewScale::SpriteOffsetAnchorRotationalSkewScale()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
addChild(point, 1);
|
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
for(int j = 0; j < 14; j++)
|
|
|
|
{
|
|
|
|
char pngName[30];
|
|
|
|
snprintf(pngName, 30, "grossini_dance_%02d.png", (j+1));
|
|
|
|
auto frame = cache->getSpriteFrameByName(pngName);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
// Skew
|
|
|
|
auto skewX = RotateBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = RotateBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
// Scale
|
|
|
|
auto scale = ScaleBy::create(2, 2);
|
|
|
|
auto scale_back = scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_scale));
|
|
|
|
|
2016-02-09 03:25:37 +08:00
|
|
|
addChild(sprite, 0);
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteOffsetAnchorRotationalSkewScale::~SpriteOffsetAnchorRotationalSkewScale()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorRotationalSkewScale::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteOffsetAnchorRotationalSkewScale::subtitle() const
|
|
|
|
{
|
|
|
|
return "anchor + rot skew + scale";
|
|
|
|
}
|
|
|
|
|
|
|
|
// SpriteBatchNodeOffsetAnchorRotationalSkewScale
|
|
|
|
SpriteBatchNodeOffsetAnchorRotationalSkewScale::SpriteBatchNodeOffsetAnchorRotationalSkewScale()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
addChild(spritebatch);
|
|
|
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Animation using Sprite batch
|
|
|
|
//
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
2016-02-09 03:25:37 +08:00
|
|
|
addChild(point, 1);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
|
2014-05-04 14:37:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->setPosition(sprite->getPosition());
|
|
|
|
|
|
|
|
Vector<SpriteFrame*> animFrames(14);
|
|
|
|
for(int j = 0; j < 14; j++)
|
|
|
|
{
|
|
|
|
char pngName[30];
|
|
|
|
snprintf(pngName, 30, "grossini_dance_%02d.png", (j+1));
|
|
|
|
auto frame = cache->getSpriteFrameByName(pngName);
|
|
|
|
animFrames.pushBack(frame);
|
|
|
|
}
|
|
|
|
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
|
|
|
|
sprite->runAction(RepeatForever::create(Animate::create(animation)));
|
|
|
|
|
|
|
|
// Skew
|
|
|
|
auto skewX = RotateBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = RotateBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
// Scale
|
|
|
|
auto scale = ScaleBy::create(2, 2);
|
|
|
|
auto scale_back = scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_scale));
|
|
|
|
|
2016-02-09 03:25:37 +08:00
|
|
|
spritebatch->addChild(sprite, 0);
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteBatchNodeOffsetAnchorRotationalSkewScale::~SpriteBatchNodeOffsetAnchorRotationalSkewScale()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorRotationalSkewScale::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeOffsetAnchorRotationalSkewScale::subtitle() const
|
|
|
|
{
|
|
|
|
return "anchor + rot skew + scale";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteRotationalSkewNegativeScaleChildren
|
|
|
|
//
|
|
|
|
SpriteRotationalSkewNegativeScaleChildren::SpriteRotationalSkewNegativeScaleChildren()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto parent = Node::create();
|
|
|
|
addChild(parent);
|
|
|
|
|
|
|
|
for(int i=0;i<2;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
2016-02-09 03:25:37 +08:00
|
|
|
addChild(point, 1);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// Skew
|
|
|
|
auto skewX = RotateBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = RotateBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
|
|
|
if (1 == 1)
|
|
|
|
{
|
|
|
|
sprite->setScale(-1.0f);
|
|
|
|
}
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
auto child1 = Sprite::create("Images/grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
child1->setPosition(Vec2(sprite->getContentSize().width/2.0f, sprite->getContentSize().height/2.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite->addChild(child1);
|
|
|
|
|
|
|
|
child1->setScale(0.8f);
|
|
|
|
|
2016-02-09 03:25:37 +08:00
|
|
|
parent->addChild(sprite, 0);
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteRotationalSkewNegativeScaleChildren::~SpriteRotationalSkewNegativeScaleChildren()
|
|
|
|
{
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteRotationalSkewNegativeScaleChildren::title() const
|
|
|
|
{
|
|
|
|
return "Testing Sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteRotationalSkewNegativeScaleChildren::subtitle() const
|
|
|
|
{
|
|
|
|
return "rot skew + negative scale with children";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// SpriteBatchNodeRotationalSkewNegativeScaleChildren
|
|
|
|
//
|
|
|
|
SpriteBatchNodeRotationalSkewNegativeScaleChildren::SpriteBatchNodeRotationalSkewNegativeScaleChildren()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
|
|
|
|
|
|
|
auto parent = SpriteBatchNode::create("animations/grossini.png");
|
|
|
|
addChild(parent);
|
|
|
|
|
|
|
|
for(int i=0;i<2;i++)
|
|
|
|
{
|
|
|
|
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(s.width/4*(i+1), s.height/2));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition(sprite->getPosition());
|
2016-02-09 03:25:37 +08:00
|
|
|
addChild(point, 1);
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
// Skew
|
|
|
|
auto skewX = RotateBy::create(2, 45, 0);
|
|
|
|
auto skewX_back = skewX->reverse();
|
|
|
|
auto skewY = RotateBy::create(2, 0, 45);
|
|
|
|
auto skewY_back = skewY->reverse();
|
|
|
|
|
|
|
|
if (1 == 1)
|
|
|
|
{
|
|
|
|
sprite->setScale(-1.0f);
|
|
|
|
}
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
|
2014-05-04 14:37:55 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq_skew));
|
|
|
|
|
|
|
|
auto child1 = Sprite::create("Images/grossini_dance_01.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
child1->setPosition(Vec2(sprite->getContentSize().width/2.0f, sprite->getContentSize().height/2.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
|
|
|
|
sprite->addChild(child1);
|
|
|
|
|
|
|
|
child1->setScale(0.8f);
|
|
|
|
|
2016-02-09 03:25:37 +08:00
|
|
|
parent->addChild(sprite, 0);
|
2014-05-04 14:37:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteBatchNodeRotationalSkewNegativeScaleChildren::~SpriteBatchNodeRotationalSkewNegativeScaleChildren()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeRotationalSkewNegativeScaleChildren::title() const
|
|
|
|
{
|
|
|
|
return "Testing SpriteBatchNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteBatchNodeRotationalSkewNegativeScaleChildren::subtitle() const
|
|
|
|
{
|
|
|
|
return "rot skew + negative scale with children";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteCullTest1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteCullTest1::SpriteCullTest1()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
auto grossini = Sprite::create("Images/grossini.png");
|
|
|
|
|
|
|
|
grossini->setPosition(s.width/2, s.height/2);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
auto right = MoveBy::create(3, Vec2(s.width*2,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
auto back1 = right->reverse();
|
2019-09-24 11:31:35 +08:00
|
|
|
auto left = MoveBy::create(3, Vec2(-s.width*2,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
auto back2 = left->reverse();
|
2019-09-24 11:31:35 +08:00
|
|
|
auto up = MoveBy::create(3, Vec2(0.0f,s.height*2));
|
2014-05-04 14:37:55 +08:00
|
|
|
auto back3 = up->reverse();
|
2019-09-24 11:31:35 +08:00
|
|
|
auto down = MoveBy::create(3, Vec2(0.0f,-s.height*2));
|
2014-05-04 14:37:55 +08:00
|
|
|
auto back4 = down->reverse();
|
|
|
|
|
|
|
|
auto seq = Sequence::create(right, back1, left, back2, up, back3, down, back4, nullptr);
|
|
|
|
grossini->runAction(seq);
|
|
|
|
this->addChild(grossini);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string SpriteCullTest1::title() const
|
|
|
|
{
|
|
|
|
return "Testing Culling: No Scale, No Rotation";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteCullTest1::subtitle() const
|
|
|
|
{
|
|
|
|
return "Look at the GL calls";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SpriteCullTest2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpriteCullTest2::SpriteCullTest2()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
auto grossini = Sprite::create("Images/grossini.png");
|
|
|
|
|
|
|
|
grossini->setPosition(s.width/2, s.height/2);
|
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
auto right = MoveBy::create(3, Vec2(s.width*2,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
auto back1 = right->reverse();
|
2019-09-24 11:31:35 +08:00
|
|
|
auto left = MoveBy::create(3, Vec2(-s.width*2,0.0f));
|
2014-05-04 14:37:55 +08:00
|
|
|
auto back2 = left->reverse();
|
2019-09-24 11:31:35 +08:00
|
|
|
auto up = MoveBy::create(3, Vec2(0.0f,s.height*2));
|
2014-05-04 14:37:55 +08:00
|
|
|
auto back3 = up->reverse();
|
2019-09-24 11:31:35 +08:00
|
|
|
auto down = MoveBy::create(3, Vec2(0.0f,-s.height*2));
|
2014-05-04 14:37:55 +08:00
|
|
|
auto back4 = down->reverse();
|
|
|
|
|
|
|
|
grossini->setScale(0.1f);
|
|
|
|
|
|
|
|
auto seq = Sequence::create(right, back1, left, back2, up, back3, down, back4, nullptr);
|
|
|
|
grossini->runAction(seq);
|
|
|
|
this->addChild(grossini);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string SpriteCullTest2::title() const
|
|
|
|
{
|
|
|
|
return "Testing Culling: Scale, No Rotation";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteCullTest2::subtitle() const
|
|
|
|
{
|
|
|
|
return "Look at the GL calls";
|
|
|
|
}
|
2014-07-02 03:36:53 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Sprite 3D rotation test
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
Sprite3DRotationTest::Sprite3DRotationTest()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s1 = Sprite::create("Images/grossini.png");
|
|
|
|
s1->setPosition(s.width/4, s.height/4 * 3);
|
2019-09-24 11:31:35 +08:00
|
|
|
s1->setAnchorPoint(Vec2(0.0f, 0.0f));
|
|
|
|
s1->runAction(RepeatForever::create(RotateBy::create(6.0f, 360.0f)));
|
2014-07-02 03:36:53 +08:00
|
|
|
addChild(s1);
|
|
|
|
|
|
|
|
auto s2 = Sprite::create("Images/grossini.png");
|
|
|
|
s2->setPosition(s.width/4 * 3, s.height/4 * 3);
|
2019-09-24 11:31:35 +08:00
|
|
|
s2->runAction(RepeatForever::create(RotateBy::create(6.0f, 360.0f)));
|
2014-07-02 03:36:53 +08:00
|
|
|
addChild(s2);
|
|
|
|
|
|
|
|
sprite1 = Sprite::create("Images/grossini.png");
|
|
|
|
sprite1->setPosition(s.width/4, s.height/4);
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite1->setAnchorPoint(Vec2(0.0f,0.0f));
|
2014-07-02 03:36:53 +08:00
|
|
|
|
|
|
|
addChild(sprite1);
|
|
|
|
|
|
|
|
sprite2 = Sprite::create("Images/grossini.png");
|
|
|
|
sprite2->setPosition(s.width/4 * 3, s.height/4);
|
|
|
|
|
|
|
|
addChild(sprite2);
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule([&](float dt) {
|
|
|
|
rotation.y += 1;
|
|
|
|
sprite1->setRotation3D(rotation);
|
|
|
|
sprite2->setRotation3D(rotation);
|
|
|
|
}, "update_key");
|
2014-07-02 03:36:53 +08:00
|
|
|
}
|
|
|
|
|
2016-10-27 09:45:40 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Sprite::getSpriteFrame() test
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteGetSpriteFrameTest::SpriteGetSpriteFrameTest()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getVisibleSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s1 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->getTexture()->setAliasTexParameters();
|
|
|
|
s1->setPosition(s.width/2-s.width/3, s.height/2);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s1->setContentSize(s1->getContentSize()*2);
|
|
|
|
s1->setSpriteFrame(s1->getSpriteFrame());
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s2 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setPosition(s.width*2/4, s.height/2);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(128,0,64,128)));
|
|
|
|
s3->setPosition(s.width/2+s.width/3, s.height/2);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s3->setSpriteFrame(s3->getSpriteFrame());
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test1::SpriteSlice9Test1()
|
|
|
|
{
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
for (int i=2; i>0; --i)
|
|
|
|
{
|
|
|
|
auto s1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->setPosition(s.width*1/4, s.height*i/3);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2019-09-24 11:31:35 +08:00
|
|
|
s1->setContentSize(Size(s1->getContentSize().width, 200.0f));
|
|
|
|
auto action1 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s1->runAction(action1);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s2 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setPosition(s.width*2/4, s.height*i/3);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2019-09-24 11:31:35 +08:00
|
|
|
s2->setContentSize(Size(s2->getContentSize().width, 200.0f));
|
|
|
|
auto action2 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s2->runAction(action2);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setPosition(s.width*3/4, s.height*i/3);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
|
2019-09-24 11:31:35 +08:00
|
|
|
s3->setContentSize(Size(s3->getContentSize().width, 200.0f));
|
|
|
|
auto action3 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s3->runAction(action3);
|
|
|
|
|
|
|
|
if (i==2) {
|
2019-09-24 11:31:35 +08:00
|
|
|
s3->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
|
|
|
|
s2->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
|
|
|
|
s1->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
|
2016-10-27 09:45:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// "anchor points"
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition( s1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
auto point2 = Sprite::create("Images/r1.png");
|
|
|
|
point2->setScale(0.25f);
|
|
|
|
point2->setPosition(s2->getPosition());
|
|
|
|
addChild(point2, 10);
|
|
|
|
|
|
|
|
auto point3 = Sprite::create("Images/r1.png");
|
|
|
|
point3->setScale(0.25f);
|
|
|
|
point3->setPosition(s3->getPosition());
|
|
|
|
addChild(point3, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test2::SpriteSlice9Test2()
|
|
|
|
{
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
for (int i=2; i>0; i--)
|
|
|
|
{
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s1 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->setPosition(s.width*1/4, s.height*i/3);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2019-09-24 11:31:35 +08:00
|
|
|
s1->setContentSize(Size(80.0f, s1->getContentSize().height));
|
|
|
|
auto action1 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s1->runAction(action1);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s2 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setPosition(s.width*2/4, s.height*i/3);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2019-09-24 11:31:35 +08:00
|
|
|
s2->setContentSize(Size(80.0f, s2->getContentSize().height));
|
|
|
|
auto action2 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s2->runAction(action2);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setPosition(s.width*3/4, s.height*i/3);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
|
2019-09-24 11:31:35 +08:00
|
|
|
s3->setContentSize(Size(80.0f, s3->getContentSize().height));
|
|
|
|
auto action3 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s3->runAction(action3);
|
|
|
|
|
|
|
|
if (i==2) {
|
2019-09-24 11:31:35 +08:00
|
|
|
s3->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
|
|
|
|
s2->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
|
|
|
|
s1->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
|
2016-10-27 09:45:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// "anchor points"
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition( s1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
auto point2 = Sprite::create("Images/r1.png");
|
|
|
|
point2->setScale(0.25f);
|
|
|
|
point2->setPosition(s2->getPosition());
|
|
|
|
addChild(point2, 10);
|
|
|
|
|
|
|
|
auto point3 = Sprite::create("Images/r1.png");
|
|
|
|
point3->setScale(0.25f);
|
|
|
|
point3->setPosition(s3->getPosition());
|
|
|
|
addChild(point3, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #3
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test3::SpriteSlice9Test3()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=2; i>0; --i)
|
|
|
|
{
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s1 = Sprite::create("ccb/scale-9-demo.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->setPosition(s.width*1/4, s.height*i/3);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s1->setContentSize(s1->getContentSize());
|
2019-09-24 11:31:35 +08:00
|
|
|
auto action1 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s1->runAction(action1);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s2 = Sprite::create("ccb/scale-9-demo.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setPosition(s.width*2/4, s.height*i/3);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s2->setContentSize(s2->getContentSize() * 2);
|
2019-09-24 11:31:35 +08:00
|
|
|
auto action2 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s2->runAction(action2);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::create("ccb/scale-9-demo.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setPosition(s.width*3/4, s.height*i/3);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s3->setContentSize(s3->getContentSize() * 3);
|
2019-09-24 11:31:35 +08:00
|
|
|
auto action3 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s3->runAction(action3);
|
|
|
|
|
|
|
|
// enable slice 9, only in the first row
|
|
|
|
if (i==2) {
|
2016-10-30 08:52:33 +08:00
|
|
|
s1->setCenterRectNormalized(Rect(0.4, 0.4, 0.2, 0.2));
|
|
|
|
s2->setCenterRectNormalized(Rect(0.4, 0.4, 0.2, 0.2));
|
|
|
|
s3->setCenterRectNormalized(Rect(0.4, 0.4, 0.2, 0.2));
|
2016-10-27 09:45:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// "anchor points"
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.25f);
|
|
|
|
point->setPosition( s1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
auto point2 = Sprite::create("Images/r1.png");
|
|
|
|
point2->setScale(0.25f);
|
|
|
|
point2->setPosition(s2->getPosition());
|
|
|
|
addChild(point2, 10);
|
|
|
|
|
|
|
|
auto point3 = Sprite::create("Images/r1.png");
|
|
|
|
point3->setScale(0.25f);
|
|
|
|
point3->setPosition(s3->getPosition());
|
|
|
|
addChild(point3, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #4
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test4::SpriteSlice9Test4()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=2; i>0; --i)
|
|
|
|
{
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s1 = Sprite::create("ccs-res/cocosui/button.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->setPosition(s.width*1/4, s.height*i/3);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s1->setContentSize(s1->getContentSize() * 2);
|
2019-09-24 11:31:35 +08:00
|
|
|
auto action1 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s1->runAction(action1);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s2 = Sprite::create("ccs-res/cocosui/button.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setPosition(s.width*2/4, s.height*i/3);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s2->setContentSize(s2->getContentSize() * 3);
|
2019-09-24 11:31:35 +08:00
|
|
|
auto action2 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s2->runAction(action2);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::create("ccs-res/cocosui/button.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setPosition(s.width*3/4, s.height*i/3);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s3->setContentSize(s3->getContentSize() * 4);
|
2019-09-24 11:31:35 +08:00
|
|
|
auto action3 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s3->runAction(action3);
|
|
|
|
|
|
|
|
// enable slice 9, only in the first row
|
|
|
|
if (i==2) {
|
2016-10-30 08:52:33 +08:00
|
|
|
s1->setCenterRect(CC_RECT_PIXELS_TO_POINTS(Rect(6, 14, 2, 4)));
|
|
|
|
s2->setCenterRect(CC_RECT_PIXELS_TO_POINTS(Rect(6, 14, 2, 4)));
|
|
|
|
s3->setCenterRect(CC_RECT_PIXELS_TO_POINTS(Rect(6, 14, 2, 4)));
|
2016-10-27 09:45:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// "anchor points"
|
|
|
|
auto point = Sprite::create("Images/r1.png");
|
|
|
|
point->setScale(0.1f);
|
|
|
|
point->setPosition( s1->getPosition() );
|
|
|
|
addChild(point, 10);
|
|
|
|
|
|
|
|
auto point2 = Sprite::create("Images/r1.png");
|
|
|
|
point2->setScale(0.1f);
|
|
|
|
point2->setPosition(s2->getPosition());
|
|
|
|
addChild(point2, 10);
|
|
|
|
|
|
|
|
auto point3 = Sprite::create("Images/r1.png");
|
|
|
|
point3->setScale(0.1f);
|
|
|
|
point3->setPosition(s3->getPosition());
|
|
|
|
addChild(point3, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #5
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test5::SpriteSlice9Test5()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getVisibleSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s1 = Sprite::create("Images/grossinis_heads.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->getTexture()->setAliasTexParameters();
|
|
|
|
s1->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(0,0,64,128)));
|
|
|
|
s1->setPosition(s.width/2-s.width/3, s.height/2);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s1->setContentSize(Size(s.width/3, s.height));
|
2016-10-30 08:52:33 +08:00
|
|
|
s1->setCenterRectNormalized(Rect(0,0,1,1));
|
2016-10-27 09:45:40 +08:00
|
|
|
_sprites[0] = s1;
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s2 = Sprite::create("Images/grossinis_heads.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(64,0,64,128)));
|
|
|
|
s2->setPosition(s.width*2/4, s.height/2);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s2->setContentSize(Size(s.width/3, s.height));
|
2016-10-30 08:52:33 +08:00
|
|
|
s2->setCenterRectNormalized(Rect(0,0,1,1));
|
2016-10-27 09:45:40 +08:00
|
|
|
_sprites[1] = s2;
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::create("Images/grossinis_heads.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(128,0,64,128)));
|
|
|
|
s3->setPosition(s.width/2+s.width/3, s.height/2);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s3->setContentSize(Size(s.width/3, s.height));
|
2016-10-30 08:52:33 +08:00
|
|
|
s3->setCenterRectNormalized(Rect(0,0,1,1));
|
2016-10-27 09:45:40 +08:00
|
|
|
_sprites[2] = s3;
|
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
|
|
|
|
_elapsed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteSlice9Test5::update(float dt)
|
|
|
|
{
|
|
|
|
_elapsed += dt;
|
|
|
|
|
|
|
|
float angle = _elapsed;
|
|
|
|
|
|
|
|
// cap the value between 0 and 0.8
|
|
|
|
float x = ((cos(angle) + sin(angle*3)) + 2) / 5.0f;
|
|
|
|
float y1 = (sin(angle) + 1) / 2.5;
|
|
|
|
float y2 = (sin(angle+M_PI_2) + 1) / 2.5;
|
|
|
|
float y = y1;
|
|
|
|
for (int i=0; i<3; ++i) {
|
|
|
|
if (i==1) {
|
|
|
|
x = 0.8 - x;
|
|
|
|
y = y2;
|
|
|
|
} else if (i==2) {
|
|
|
|
y = 0.8 - y;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect rect(x,y,0.2, 0.2);
|
2016-10-30 08:52:33 +08:00
|
|
|
_sprites[i]->setCenterRectNormalized(rect);
|
2016-10-27 09:45:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #6
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test6::SpriteSlice9Test6()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getVisibleSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s1 = Sprite::create("Images/grossinis_heads.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->getTexture()->setAliasTexParameters();
|
|
|
|
s1->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(0,0,64,128)));
|
|
|
|
s1->setPosition(s.width/2-s.width/3, s.height/2);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s1->setContentSize(Size(s.width/3, s.height));
|
2016-10-30 08:52:33 +08:00
|
|
|
s1->setCenterRectNormalized(Rect(0,0,1,1));
|
2016-10-27 09:45:40 +08:00
|
|
|
_sprites[0] = s1;
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s2 = Sprite::create("Images/grossinis_heads.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(64,0,64,128)));
|
|
|
|
s2->setPosition(s.width*2/4, s.height/2);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s2->setContentSize(Size(s.width/3, s.height));
|
2016-10-30 08:52:33 +08:00
|
|
|
s2->setCenterRectNormalized(Rect(0,0,1,1));
|
2016-10-27 09:45:40 +08:00
|
|
|
_sprites[1] = s2;
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::create("Images/grossinis_heads.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(128,0,64,128)));
|
|
|
|
s3->setPosition(s.width/2+s.width/3, s.height/2);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s3->setContentSize(Size(s.width/3, s.height));
|
2016-10-30 08:52:33 +08:00
|
|
|
s3->setCenterRectNormalized(Rect(0,0,1,1));
|
2016-10-27 09:45:40 +08:00
|
|
|
_sprites[2] = s3;
|
2014-07-02 03:36:53 +08:00
|
|
|
|
2016-10-27 09:45:40 +08:00
|
|
|
scheduleUpdate();
|
2014-07-02 03:36:53 +08:00
|
|
|
|
2016-10-27 09:45:40 +08:00
|
|
|
_elapsed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteSlice9Test6::update(float dt)
|
|
|
|
{
|
|
|
|
_elapsed += dt;
|
|
|
|
|
|
|
|
float angle = _elapsed;
|
|
|
|
|
|
|
|
// cap the value between 0 and 1
|
|
|
|
float x = ((cos(angle*2) - sin(angle/2)) + 2) / 4;
|
|
|
|
float y1 = (sin(angle) + 1) / 2;
|
|
|
|
float y2 = (sin(angle+M_PI_2) + 1) / 2;
|
|
|
|
float y = y1;
|
|
|
|
for (int i=0; i<3; ++i) {
|
|
|
|
if (i==1) {
|
|
|
|
x = 1 - x;
|
|
|
|
y = y2;
|
|
|
|
} else if (i==2) {
|
|
|
|
y = 1 - y;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect rect((1-x)/2, (1-y)/2, x, y);
|
2016-10-30 08:52:33 +08:00
|
|
|
_sprites[i]->setCenterRectNormalized(rect);
|
2016-10-27 09:45:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #7
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test7::SpriteSlice9Test7()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getVisibleSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s1 = Sprite::create("Images/grossinis_heads.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->getTexture()->setAliasTexParameters();
|
|
|
|
s1->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(0,0,64,128)));
|
|
|
|
s1->setPosition(s.width/2-s.width/3, s.height/2);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s1->setContentSize(Size(s.width/3, s.height));
|
2016-10-30 08:52:33 +08:00
|
|
|
s1->setCenterRectNormalized(Rect(0,0,0.5,0.5));
|
2016-10-27 09:45:40 +08:00
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s2 = Sprite::create("Images/grossinis_heads.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(64,0,64,128)));
|
|
|
|
s2->setPosition(s.width*2/4, s.height/2);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s2->setContentSize(Size(s.width/3, s.height));
|
2016-10-30 08:52:33 +08:00
|
|
|
s2->setCenterRectNormalized(Rect(0.25,0.25,0.5,0.5));
|
2016-10-27 09:45:40 +08:00
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::create("Images/grossinis_heads.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setTextureRect(CC_RECT_PIXELS_TO_POINTS(Rect(128,0,64,128)));
|
|
|
|
s3->setPosition(s.width/2+s.width/3, s.height/2);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s3->setContentSize(Size(s.width/3, s.height));
|
2016-10-30 08:52:33 +08:00
|
|
|
s3->setCenterRectNormalized(Rect(0.5,0.5,0.5,0.5));
|
2016-10-27 09:45:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #8
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test8::SpriteSlice9Test8()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getVisibleSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
|
2016-10-30 08:52:33 +08:00
|
|
|
//
|
|
|
|
// flip BEFORE contentSize
|
|
|
|
//
|
2016-10-27 09:45:40 +08:00
|
|
|
auto s1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
|
|
|
|
addChild(s1);
|
2016-10-30 08:52:33 +08:00
|
|
|
s1->setPosition(s.width/2-s.width/3, s.height*2/3);
|
2016-10-27 09:45:40 +08:00
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2016-10-30 08:52:33 +08:00
|
|
|
s1->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s1->setFlippedX(true);
|
2016-10-30 08:52:33 +08:00
|
|
|
s1->setContentSize(s1->getContentSize()*2);
|
2016-10-27 09:45:40 +08:00
|
|
|
|
|
|
|
auto s2 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s2);
|
2016-10-30 08:52:33 +08:00
|
|
|
s2->setPosition(s.width*2/4, s.height*2/3);
|
2016-10-27 09:45:40 +08:00
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2016-10-30 08:52:33 +08:00
|
|
|
s2->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
|
|
|
s2->setFlippedX(true);
|
|
|
|
s2->setFlippedY(true);
|
2016-10-27 09:45:40 +08:00
|
|
|
s2->setContentSize(s2->getContentSize()*2);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
|
|
|
|
addChild(s3);
|
2016-10-30 08:52:33 +08:00
|
|
|
s3->setPosition(s.width/2+s.width/3, s.height*2/3);
|
2016-10-27 09:45:40 +08:00
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2016-10-30 08:52:33 +08:00
|
|
|
s3->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s3->setFlippedY(true);
|
2016-10-30 08:52:33 +08:00
|
|
|
s3->setContentSize(s3->getContentSize()*2);
|
|
|
|
|
|
|
|
//
|
|
|
|
// flip AFTER contentSize
|
|
|
|
//
|
|
|
|
auto s4 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
|
|
|
|
addChild(s4);
|
|
|
|
s4->setPosition(s.width/2-s.width/3, s.height*1/3);
|
|
|
|
s4->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s4->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
|
|
|
s4->setFlippedX(true);
|
|
|
|
s4->setContentSize(s4->getContentSize()*2);
|
|
|
|
|
|
|
|
auto s5 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s5);
|
|
|
|
s5->setPosition(s.width*2/4, s.height*1/3);
|
|
|
|
s5->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s5->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
|
|
|
s5->setFlippedX(true);
|
|
|
|
s5->setFlippedY(true);
|
|
|
|
s5->setContentSize(s5->getContentSize()*2);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s6 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
|
|
|
|
addChild(s6);
|
|
|
|
s6->setPosition(s.width/2+s.width/3, s.height*1/3);
|
|
|
|
s6->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s6->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
|
|
|
s6->setFlippedY(true);
|
|
|
|
s6->setContentSize(s6->getContentSize()*2);
|
2016-10-27 09:45:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #9
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test9::SpriteSlice9Test9()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getVisibleSize();
|
|
|
|
|
2016-10-30 08:52:33 +08:00
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
|
|
|
|
|
|
|
|
|
|
|
|
// flipped BEFORE content size
|
|
|
|
auto s1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->setPosition(s.width/2-s.width/3, s.height*2/3);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s1->setCenterRectNormalized(Rect(2/3.f, 2/3.f, 1/3.f, 1/3.f));
|
|
|
|
s1->setFlippedX(true);
|
|
|
|
s1->setContentSize(s1->getContentSize()*2);
|
|
|
|
|
|
|
|
auto s2 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setPosition(s.width*2/4, s.height*2/3);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s2->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 2/3.f, 2/3.f));
|
|
|
|
s2->setFlippedX(true);
|
|
|
|
s2->setFlippedY(true);
|
|
|
|
s2->setContentSize(s2->getContentSize()*2);
|
|
|
|
|
|
|
|
auto s3 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setPosition(s.width/2+s.width/3, s.height*2/3);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s3->setCenterRectNormalized(Rect(0.1f, 0.1f, 0.8f, 0.8f));
|
|
|
|
s3->setFlippedY(true);
|
|
|
|
s3->setContentSize(s3->getContentSize()*2);
|
|
|
|
|
|
|
|
|
|
|
|
// flipped AFTER content size
|
|
|
|
auto s4 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
|
|
|
|
addChild(s4);
|
|
|
|
s4->setPosition(s.width/2-s.width/3, s.height*1/3);
|
|
|
|
s4->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s4->setCenterRectNormalized(Rect(2/3.f, 2/3.f, 1/3.f, 1/3.f));
|
|
|
|
s4->setContentSize(s4->getContentSize()*2);
|
|
|
|
s4->setFlippedX(true);
|
|
|
|
|
|
|
|
auto s5 = Sprite::createWithSpriteFrameName("grossini.png");
|
|
|
|
addChild(s5);
|
|
|
|
s5->setPosition(s.width*2/4, s.height*1/3);
|
|
|
|
s5->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s5->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 2/3.f, 2/3.f));
|
|
|
|
s5->setContentSize(s5->getContentSize()*2);
|
|
|
|
s5->setFlippedX(true);
|
|
|
|
s5->setFlippedY(true);
|
|
|
|
|
|
|
|
auto s6 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
|
|
|
|
addChild(s6);
|
|
|
|
s6->setPosition(s.width/2+s.width/3, s.height*1/3);
|
|
|
|
s6->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
s6->setCenterRectNormalized(Rect(0.1f, 0.1f, 0.8f, 0.8f));
|
|
|
|
s6->setContentSize(s6->getContentSize()*2);
|
|
|
|
s6->setFlippedY(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Slice9 Test #10
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
SpriteSlice9Test10::SpriteSlice9Test10()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getVisibleSize();
|
|
|
|
|
2016-10-27 09:45:40 +08:00
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist");
|
|
|
|
|
|
|
|
|
|
|
|
auto s1 = Sprite::createWithSpriteFrameName("blocks9r.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->setPosition(s.width/2-s.width/3, s.height/2);
|
|
|
|
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2016-10-30 08:52:33 +08:00
|
|
|
s1->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s1->setContentSize(s1->getContentSize()*1.5);
|
|
|
|
s1->setFlippedX(true);
|
|
|
|
|
|
|
|
auto s2 = Sprite::createWithSpriteFrameName("blocks9r.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setPosition(s.width*2/4, s.height/2);
|
|
|
|
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2016-10-30 08:52:33 +08:00
|
|
|
s2->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s2->setContentSize(s2->getContentSize()*1.5);
|
|
|
|
|
|
|
|
//Create reference sprite that's rotating based on there anchor point
|
|
|
|
auto s3 = Sprite::createWithSpriteFrameName("blocks9r.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setPosition(s.width/2+s.width/3, s.height/2);
|
|
|
|
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2016-10-30 08:52:33 +08:00
|
|
|
s3->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
2016-10-27 09:45:40 +08:00
|
|
|
s3->setContentSize(s3->getContentSize()*1.5);
|
|
|
|
s3->setFlippedY(true);
|
|
|
|
}
|
2017-01-10 15:28:47 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Issue 17119
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
Issue17119::Issue17119()
|
|
|
|
: _accum(0)
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getVisibleSize();
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/issue_17119.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist");
|
|
|
|
|
|
|
|
|
|
|
|
auto s1 = Sprite::createWithSpriteFrameName("firstPic.png");
|
|
|
|
addChild(s1);
|
|
|
|
s1->setPosition(s.width/2-s.width/3, s.height/2);
|
|
|
|
s1->setScale(0.25f);
|
|
|
|
auto p1 = Sprite::create("Images/r1.png");
|
|
|
|
p1->setScale(0.25f);
|
|
|
|
p1->setPosition(s1->getPosition());
|
|
|
|
addChild(p1, 10);
|
|
|
|
|
|
|
|
auto s2 = Sprite::createWithSpriteFrameName("blocks9r.png");
|
|
|
|
addChild(s2);
|
|
|
|
s2->setPosition(s.width/2, s.height/2);
|
|
|
|
s2->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));
|
|
|
|
s2->setContentSize(s2->getContentSize()*1.5);
|
|
|
|
auto p2 = Sprite::create("Images/r1.png");
|
|
|
|
p2->setScale(0.25f);
|
|
|
|
p2->setPosition(s2->getPosition());
|
|
|
|
addChild(p2, 10);
|
|
|
|
|
|
|
|
auto s3 = Sprite::create("Images/grossini.png");
|
|
|
|
addChild(s3);
|
|
|
|
s3->setPosition(s.width/2+s.width/3, s.height/2+s.height/3);
|
|
|
|
s3->setContentSize(s3->getContentSize()*1.5);
|
|
|
|
auto p3 = Sprite::create("Images/r1.png");
|
|
|
|
p3->setScale(0.25f);
|
|
|
|
p3->setPosition(s3->getPosition());
|
|
|
|
addChild(p3, 10);
|
|
|
|
|
|
|
|
auto s4 = Sprite::create("Images/grossini.png");
|
|
|
|
addChild(s4);
|
|
|
|
s4->setPosition(s.width/2+s.width/3, s.height/2-s.height/3);
|
|
|
|
s4->setContentSize(s2->getContentSize()*1.5);
|
2017-01-23 09:25:56 +08:00
|
|
|
s4->setStretchEnabled(false);
|
2017-01-10 15:28:47 +08:00
|
|
|
auto p4 = Sprite::create("Images/r1.png");
|
|
|
|
p4->setScale(0.25f);
|
|
|
|
p4->setPosition(s3->getPosition());
|
|
|
|
addChild(p4, 10);
|
|
|
|
|
|
|
|
_s1 = s1;
|
|
|
|
_s2 = s2;
|
|
|
|
_s3 = s3;
|
|
|
|
_s4 = s4;
|
|
|
|
scheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Issue17119::update(float dt)
|
|
|
|
{
|
|
|
|
_accum += dt;
|
|
|
|
if (_accum > 0.5) {
|
|
|
|
_accum = 0;
|
|
|
|
auto flipped = _s1->isFlippedX();
|
|
|
|
_s1->setFlippedX(!flipped);
|
|
|
|
_s2->setFlippedX(!flipped);
|
|
|
|
_s3->setFlippedX(!flipped);
|
|
|
|
_s4->setFlippedX(!flipped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|