开发者

Best way to go about making ccTime function just for a sprite's movement?

开发者 https://www.devze.com 2023-04-12 01:07 出处:网络
I\'m trying to make a simple game and I am currently trying to make an arrow shoot out. So far I have two functions,

I'm trying to make a simple game and I am currently trying to make an arrow shoot out. So far I have two functions,

-(void)ccTouchesBegan

Touches began does some math and gets a vector from the initial shooting point of arrow and the thumbpress, then passes this data into开发者_运维知识库 another function:

-(void)shatArrow:(CGPoint)cl:(CGPoint)nv{

}

What I want is for the shatArrow function to call a ccTime function that runs solely for the purpose of making the arrow move, and once the arrow is done with it's projection, the ccTime function will stop, and can be called again later when needed.

How would I go about this?


Schedule the update selector (ie in the init method of your class):

[self scheduleUpdate];

Then implement the update method:

-(void) update:(ccTime)delta
{
  if (isArrowMoving)
  {
     // arrow move code here

     if (arrow movement should end)
     {
        isArrowMoving = NO;
     }
  }
}

You can keep the update method running, unless you have hundreds of arrows it won't affect performance.

-(void) shootArrow:(CGPoint)cl:(CGPoint)nv
{
   isArrowMoving = YES;
   // other arrow movement init code here
}

Btw, it's "shoot, shot, shot" and not "shoot, shot, shat" or something like that. (I suppose you didn't ask for a #LinguisticsOverflow answer) ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号