【发布时间】:2010-01-29 01:50:34
【问题描述】:
我最近在我的应用程序中添加了一些 Core Graphics 元素,但它的速度显着变慢,使它几乎毫无用处。我不确定我是否只是没有有效地使用 Core Graphics(如何让它更快?)或者这个问题是否是使用 Core Graphics 所固有的。在此描述之后,我的代码如下:
有在屏幕上移动的气泡(在 x 和 y 中)。每个气泡在屏幕底部都有一个相应的图像,该图像也沿 x 和 y 方向移动。我正在使用 Core Graphics 从语音气泡中绘制一个三角形,终止于底部图像。屏幕上可以同时出现 10 个以上的三角形,它们都在移动。每 1/10 秒就会触发一个计时器,计算所有物体的位置,并在我构建的三角形对象上调用 setNeedsDisplay。
三角形对象的代码:
- (void)drawRect:(CGRect)rect {
// Drawing code
// Drawing code
CGContextRef ctx = UIGraphicsGetCurrentContext(); //get the graphics context
CGContextSetRGBStrokeColor(ctx, 1.0, 0, 0, 1); //there are two relevant color states, "Stroke" -- used in Stroke drawing functions and "Fill" - used in fill drawing functions
//Create an array of points for triangle
CGPoint leftTrianglePoint;
CGPoint rightTrianglePoint;
rightTrianglePoint = CGPointMake(pointBlob.x, (pointBlob.y + 10.0));
leftTrianglePoint = CGPointMake(pointBlob.x, (pointBlob.y - 10.0));
CGPoint triangleArray [] =
{
pointGrid,
rightTrianglePoint,
leftTrianglePoint,
pointGrid,};
//Add lines to the context
CGContextAddLines( ctx, triangleArray, 4);
//draw the path
//color the context - using a function for gray, to matche the saved blobs
CGContextSetGrayFillColor(ctx, 0.0, .7);
//Now fill the path
CGContextFillPath(ctx);
}
如何加快速度/提高效率,让我的图形再次顺畅移动?
【问题讨论】:
标签: iphone objective-c core-animation performance core-graphics