@@ -36,6 +36,7 @@ NS_CC_BEGIN
36
36
class TMXMapInfo ;
37
37
class TMXLayerInfo ;
38
38
class TMXTilesetInfo ;
39
+ class TMXTileAnimManager ;
39
40
struct _ccCArray ;
40
41
41
42
/* *
@@ -276,6 +277,22 @@ class CC_DLL TMXLayer : public SpriteBatchNode
276
277
*/
277
278
virtual std::string getDescription () const override ;
278
279
280
+ /* * Map from gid of animated tile to its instance.
281
+ *
282
+ * @return Map from gid of animated tile to its instance.
283
+ */
284
+ const std::map<uint32_t , std::vector<Vec2>>* getAnimTileCoord () {
285
+ return &_animTileCoord;
286
+ }
287
+
288
+ bool hasTileAnimation () const {
289
+ return !_animTileCoord.empty ();
290
+ }
291
+
292
+ TMXTileAnimManager* getTileAnimManager () const {
293
+ return _tileAnimManager;
294
+ }
295
+
279
296
protected:
280
297
Vec2 getPositionForIsoAt (const Vec2& pos);
281
298
Vec2 getPositionForOrthoAt (const Vec2& pos);
@@ -337,6 +354,72 @@ class CC_DLL TMXLayer : public SpriteBatchNode
337
354
ValueMap _properties;
338
355
};
339
356
357
+ /* * map from gid of animated tile to its instance. Also useful for optimization*/
358
+ std::map<uint32_t , std::vector<Vec2>> _animTileCoord;
359
+ /* * pointer to the tile animation manager of this layer */
360
+ TMXTileAnimManager *_tileAnimManager = nullptr ;
361
+ };
362
+
363
+ /* * @brief TMXTileAnimTask represents the frame-tick task of an animated tile.
364
+ * It is a assistant class for TMXTileAnimTicker.
365
+ */
366
+ class CC_DLL TMXTileAnimTask : public Ref
367
+ {
368
+ public:
369
+ TMXTileAnimTask (TMXLayer *layer, TMXTileAnimInfo *animation, const Vec2 &tilePos);
370
+ static TMXTileAnimTask * create (TMXLayer *layer, TMXTileAnimInfo *animation, const Vec2 &tilePos);
371
+ /* * start the animation task */
372
+ void start ();
373
+ /* * stop the animation task */
374
+ void stop ();
375
+ bool isRunning () const {
376
+ return _isRunning;
377
+ }
378
+
379
+ protected:
380
+ /* * set texture of tile to current frame */
381
+ void setCurrFrame ();
382
+ /* * tick to next frame and schedule next tick */
383
+ void tickAndScheduleNext (float dt);
384
+
385
+ bool _isRunning = false ;
386
+ /* * key of schedule task for specific animated tile */
387
+ std::string _key;
388
+ TMXLayer *_layer = nullptr ;
389
+ /* * position of the animated tile */
390
+ Vec2 _tilePosition;
391
+ /* * AnimationInfo on this tile */
392
+ TMXTileAnimInfo *_animation = nullptr ;
393
+ /* * Index of the frame that should be drawn currently */
394
+ uint32_t _currentFrame = 0 ;
395
+ uint32_t _frameCount = 0 ;
396
+ };
397
+
398
+ /* * @brief TMXTileAnimManager controls all tile animation of a layer.
399
+ */
400
+ class CC_DLL TMXTileAnimManager : public Ref
401
+ {
402
+ public:
403
+ static TMXTileAnimManager * create (TMXLayer *layer);
404
+ explicit TMXTileAnimManager (TMXLayer *layer);
405
+
406
+ /* * start all tile animations */
407
+ void startAll ();
408
+ /* * stop all tile animations */
409
+ void stopAll ();
410
+
411
+ /* * get vector of tasks */
412
+ const Vector<TMXTileAnimTask*>& getTasks () const {
413
+ return _tasks;
414
+ }
415
+
416
+ protected:
417
+ bool _started = false ;
418
+ /* * vector contains all tasks of this layer */
419
+ Vector<TMXTileAnimTask*> _tasks;
420
+ TMXLayer* _layer = nullptr ;
421
+ };
422
+
340
423
// end of tilemap_parallax_nodes group
341
424
/* * @} */
342
425
0 commit comments