在iPhone上绘制矢量图形 [英] Drawing vector graphics on iphone

查看:80
本文介绍了在iPhone上绘制矢量图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅新手问题.我有一个iPhone游戏,当前使用很多png图像进行动画处理.虽然效果很好,但图像占用了大量内存.我也有矢量格式的图像,我更愿意使用这些图像而不是png.

Please forgive the newbie question. I have an iphone game that currently uses lots of png images for animations. While this works well, the images are taking up alot of memory. I have the images in a vector format as well and I would prefer to use those instead of the pngs.

是否有一种本机的方法?

Is there a native way to do that?

推荐答案

我假设您要使用Core Animation,对吗?在这种情况下,您的选择非常有限.有几类显示图形的图层:CALayer绘制位图,CAShapeLayer绘制贝塞尔曲线路径,CAGradientLayer绘制线性渐变,CATextLayer绘制文本.您也可以将OpenGL与CAEAGLLayer一起使用,但是在性能方面,它不能很好地与其他Quartz图形混合使用.最有可能的是,您无论如何都必须使用PNG,因为即使您有可以通过Core Graphics显示的PDF,也必须将它们栅格化,然后才能在CALayer中显示它们.而且,光栅化将在CPU上完成,您不希望每个动画帧都发生这种情况.

I assume you want to use Core Animation, right? In that case your options are pretty limited. There are several classes of layers which display graphics: CALayer draws a bitmap, CAShapeLayer draws a bezier path, CAGradientLayer draws a linear gradient, CATextLayer draws text. You can also use OpenGL with CAEAGLLayer, but it doesn't mix with other Quartz graphics very well performance-wise. Most likely, you will have to use PNGs anyway because even if you have PDFs which you can display via Core Graphics, they will have to be rasterized before you can show them in a CALayer. Moreover, the rasterization will be done on the CPU, which you don't want to be happening with each animation frame.

关于内存使用,我感到您很痛苦.大量图像==大量内存.Core Animation并非完全是游戏引擎,它在设计时考虑了UI动画.我曾经用CA制作过一款iPhone游戏,除了占用内存外,当同时进行过多动画处理时,还存在性能问题.看一下Cocos2D,它更适合于游戏,并且正在积极开发中.当然,它有其自身的问题,值得一提.

With regard to memory usage, I feel your pain. A lot of images == a lot of memory. Core Animation is not exactly a gaming engine, it is designed with UI animation in mind. I once did an iPhone game with CA and besides memory usage there were performance problems too when too many animations took place simultaneously. Have a look at Cocos2D, it is much better suited for games and is being actively developed. Granted, it has issues of its own, it deserves mentioning as an option.

这篇关于在iPhone上绘制矢量图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆