[英]How to move/animate CGRects
I'm having trouble moving CGRects around. 我在移动CGRect时遇到麻烦。 I'm trying to make a breakout game.
我正在尝试制作突破游戏。 In my drawView file, I have written code in the drawRect function by removing the comments.
在我的drawView文件中,我通过删除注释在drawRect函数中编写了代码。 I end my drawRect function with this
moveBall(&_ball, &_context, rect);
我用这个
moveBall(&_ball, &_context, rect);
结束了我的drawRect函数moveBall(&_ball, &_context, rect);
moveball()
is declared/implemented in my viewController.h/viewController.m. moveball()
在我的viewController.h / viewController.m中声明/实现。
I'm not sure how to then move/animate the ball once it is in my controller. 我不确定一旦球进入控制器后如何移动/动画。 I have the following code:
我有以下代码:
void moveBall(CGRect *ball, CGContextRef *context, CGRect rect)
{
CGFloat velX = 1;
CGFloat velY = 1;
while (ball->origin.x + CGRectGetWidth(*ball) < CGRectGetWidth(rect))
{
CGContextClearRect(*context, *ball);
*ball = CGRectOffset(*ball, velX, velY);
CGContextFillEllipseInRect(*context, *ball);
}
};
What happens is that the ball is "moved" to a different place, not animated there. 发生的事情是,球被“移动”到了另一个位置,而不是在那里动画。 The problem is that the while loop is implemented and the final result is displayed.
问题是实施while循环并显示最终结果。 I want the while loop to run after the drawing is done.
我希望while循环在绘制完成后运行。
Can anyone guide me to make the ball move? 谁能引导我使球移动?
Trying to make animations inside the drawRect
method using CoreGraphics framework is exercise in futility. 尝试使用CoreGraphics框架在
drawRect
方法内制作动画是徒劳的。
For animations you should use other frameworks/technologies intended for that. 对于动画,您应该使用其他用于此目的的框架/技术。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.