使用ios7中的Core Graphics连续动画uiview

时间:2014-06-02 04:17:57

标签: ios iphone ios7 uiview core-graphics

我正在创建一个类似泡泡射击游戏的游戏,其中uiview对象将根据触摸屏幕的位置连续制作动画。我能够根据触摸事件动画我的uiview对象,但问题是,它停在我点击的触摸点。我使用uiview动画,我给1秒动画球。但我不想在那时停止球,并希望它自动前进我点击的方向,它也应该照顾球(UIView)不会离开的屏幕大小。这是我的代码

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
 gameTimer = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateDisplay:)];
 [gameTimer addToRunLoop:[NSRunLoop currentRunLoop]forMode:NSDefaultRunLoopMode];
}
-(void) updateDisplay:(CADisplayLink*)sender
{


                        if (lastTime == 0.0)
                        {
                           // First time through, initialize the lastTime
                             lastTime = previousTimeStampValue;


                         }
                         else
                         {

                             timeDelta = sender.timestamp - lastTime; // Update the lastTime
                             lastTime = sender.timestamp;


                             ballRect.origin.x += ballVelocity.x * timeDelta;
                             ballRect.origin.y += ballVelocity.y * timeDelta;

                             [self checkCollisionWithScreenEdges];
                        }

                   [currentBallView setFrame:ballRect];


                  // currentBallView.center = ballRect.origin;



}

0 个答案:

没有答案