-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Added tmx animated tile support, with test case. #20315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d1541f5
Added tmx animated tile support, with test case. Tile animation are d…
DEAGS3000 ec6d550
changed tileset tococos own's
DEAGS3000 8d1e294
used cocos2dx own's tileset
DEAGS3000 1d28f29
Merge remote-tracking branch 'upstream/v3' into tmx_animated_tile_sup…
DEAGS3000 c0bcfa1
changed return type of TMXLayer::getAnimTileCoord to pointer for lua …
DEAGS3000 e958a94
deleted useless code, improved api
DEAGS3000 1363499
re-generated script binding
DEAGS3000 5ca534c
added CC_DLL to new classes, solved some problem posted on pull request
DEAGS3000 20a3351
changed return type of getTasks to pointer
DEAGS3000 59936a9
made TileAnimTask inherit form Ref
DEAGS3000 a63bdcf
removed a fixed FIXME
DEAGS3000 e81a746
added const to getTasks, deleted unneeded empty lines, re-generated s…
DEAGS3000 8a46242
deleted empty lines in TMXXMLParser
DEAGS3000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ NS_CC_BEGIN | |
| class TMXMapInfo; | ||
| class TMXLayerInfo; | ||
| class TMXTilesetInfo; | ||
| class TMXTileAnimManager; | ||
| struct _ccCArray; | ||
|
|
||
| /** | ||
|
|
@@ -294,6 +295,22 @@ class CC_DLL TMXLayer : public SpriteBatchNode | |
| */ | ||
| virtual std::string getDescription() const override; | ||
|
|
||
| /** Map from gid of animated tile to its instance. | ||
| * | ||
| * @return Map from gid of animated tile to its instance. | ||
| */ | ||
| const std::map<uint32_t, std::vector<Vec2>>* getAnimTileCoord() { | ||
| return &_animTileCoord; | ||
| } | ||
|
|
||
| bool hasTileAnimation() const { | ||
| return !_animTileCoord.empty(); | ||
| } | ||
|
|
||
| TMXTileAnimManager* getTileAnimManager() const { | ||
| return _tileAnimManager; | ||
| } | ||
|
|
||
| protected: | ||
| Vec2 getPositionForIsoAt(const Vec2& pos); | ||
| Vec2 getPositionForOrthoAt(const Vec2& pos); | ||
|
|
@@ -353,6 +370,72 @@ class CC_DLL TMXLayer : public SpriteBatchNode | |
| int _hexSideLength; | ||
| /** properties from the layer. They can be added using Tiled */ | ||
| ValueMap _properties; | ||
|
|
||
| /** map from gid of animated tile to its instance. Also useful for optimization*/ | ||
| std::map<uint32_t, std::vector<Vec2>> _animTileCoord; | ||
| /** pointer to the tile animation manager of this layer */ | ||
| TMXTileAnimManager *_tileAnimManager = nullptr; | ||
| }; | ||
|
|
||
| /** @brief TMXTileAnimTask represents the frame-tick task of an animated tile. | ||
| * It is a assistant class for TMXTileAnimTicker. | ||
| */ | ||
| class CC_DLL TMXTileAnimTask : public Ref | ||
| { | ||
| public: | ||
| TMXTileAnimTask(TMXLayer *layer, TMXTileAnimInfo *animation, const Vec2 &tilePos); | ||
| static TMXTileAnimTask * create(TMXLayer *layer, TMXTileAnimInfo *animation, const Vec2 &tilePos); | ||
| /** start the animation task */ | ||
| void start(); | ||
| /** stop the animation task */ | ||
| void stop(); | ||
| bool isRunning() const { | ||
| return _isRunning; | ||
| } | ||
|
|
||
| protected: | ||
| /** set texture of tile to current frame */ | ||
| void setCurrFrame(); | ||
| /** tick to next frame and schedule next tick */ | ||
| void tickAndScheduleNext(float dt); | ||
|
|
||
| bool _isRunning = false; | ||
| /** key of schedule task for specific animated tile */ | ||
| std::string _key; | ||
| TMXLayer *_layer; | ||
| /** position of the animated tile */ | ||
| Vec2 _tilePosition; | ||
| /** AnimationInfo on this tile */ | ||
| TMXTileAnimInfo *_animation = nullptr; | ||
| /** Index of the frame that should be drawn currently */ | ||
| uint32_t _currentFrame = 0; | ||
| uint32_t _frameCount = 0; | ||
| }; | ||
|
|
||
| /** @brief TMXTileAnimManager controls all tile animation of a layer. | ||
| */ | ||
| class CC_DLL TMXTileAnimManager : public Ref | ||
| { | ||
| public: | ||
| static TMXTileAnimManager * create(TMXLayer *layer); | ||
| explicit TMXTileAnimManager(TMXLayer *layer); | ||
|
|
||
| /** start all tile animations */ | ||
| void startAll(); | ||
| /** stop all tile animations */ | ||
| void stopAll(); | ||
|
|
||
| /** get vector of tasks | ||
| */ | ||
| Vector<TMXTileAnimTask*>& getTasks(){ | ||
| return _tasks; | ||
| } | ||
minggo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| protected: | ||
| bool _started = false; | ||
| /** vector contains all tasks of this layer */ | ||
| Vector<TMXTileAnimTask*> _tasks; | ||
| TMXLayer* _layer; | ||
minggo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| // end of tilemap_parallax_nodes group | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.