English 中文(简体)
Sprete 由于跟踪, 具有jigging 效果
原标题:Sprite has a jigging effect because of tracking

我有一个图示,它跟踪和跟踪屏幕上的东西, 朝它们移动。

方法在时间表上运行, 基本上看起来是这样的 :

- (void) nextFrame:(ccTime)dt {
    //calculate distance between the bubble and the fish
    float dx = bubbleToChase.position.x - fish.position.x;
    float dy = bubbleToChase.position.y - fish.position.y;
    float d = sqrt(dx*dx + dy*dy);
    float v = 400;

    if (d >  190){
        NSLog(@"moving the fish!");
        fish.position = ccp( fish.position.x + dx/d * v *dt, 
                            fish.position.y + dy/d * v *dt);

    }
}

当距离超过190码时 鱼会游向它

问题是物体有物理, 所以它们会滑动在屏幕上。 这会对鱼的图案产生振动/ 惊人的影响, 因为鱼一旦到达泡泡, 鱼就会停下来, 但是随着泡沫逐渐流走( d & gt; 190), 鱼就会跳动并快速停止。

怎样才能摆脱这种刺激效应呢?我想在鱼到达泡泡位置后阻止它移动。或者任何能让它平滑的替代方法。任何帮助都会感谢,谢谢。

问题回答
if (d >  190 && !fish.parked){
    NSLog(@"moving the fish!");
    fish.position = ccp( fish.position.x + dx/d * v *dt, 
                        fish.position.y + dy/d * v *dt);

}else{
   if( fish.parked ){
   // what you want to do while parked
   // just sit there, wander randomly, 
   // then unpark the fish...
   if(unpark)
      fish.parked=FALSE;
   }else{
     fish.parked=TRUE;
     // set variables for parked state.
   }

}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签