开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜