In my project, I wish to create a RepeatForever MoveBy action with random position in a centain rectangle. The random position and random action could be created easily. But the most difficult thing is how to run different actions one by one and create next random action automatically between two actions.
How to resolve this problem? Thanks.
How to create a RepeatForever MoveBy action with random position?
(5 posts) (4 voices)-
Posted 2 years ago #
-
Maybe make your own IntervalAction subclass similar to MoveTo:
@interface MoveToRandomPointInBox : IntervalAction <NSCopying> { CGPoint endPosition; CGPoint startPosition; CGPoint delta; CGRect box; } /** creates the action */ +(id) actionWithDuration:(ccTime)duration inBox:(CGRect)aBox; /** initializes the action */ -(id) initWithDuration:(ccTime)duration inBox:(CGRect)aBox; @endSo make the code the same as MoveTo (or maybe it should be a subclass of MoveTo?) but in the -start method pick a point at random thats inside box and store that in endPosition. Everything else stays the same as MoveTo. Make sense?
Posted 2 years ago # -
[moved to cocos2d-discuss]
Posted 2 years ago # -
To Codemattic: Thanks a lot. I follow your idea and everything work fine as I wish.
Posted 2 years ago # -
Thanks, Codemattic! also riq
Posted 2 years ago #
Reply
You must log in to post.