Re: How to animate the drawing of UIImages inside a drawRect: method of a UIView?
Re: How to animate the drawing of UIImages inside a drawRect: method of a UIView?
- Subject: Re: How to animate the drawing of UIImages inside a drawRect: method of a UIView?
- From: WT <email@hidden>
- Date: Fri, 3 Apr 2009 16:13:05 +0200
Presuming that this is full-size, It is uncommon to have views that
are so small (the balls must be, what, 4X4 pixels or something?),
I'd say.
No, no, the smallest ball is 13x13 pixels and the whole picture is
nearly 320 pixels on each side. I had to shrink the picture to such a
small size because of the cocoa-dev limitations on the size of
attachments (25 kb max).
Intuitively, it 'looks' to me like the 'normal' architecture for
something like this would be to have one custom view for the entire
grid (of course, there are always exceptions, and I don't know the
full background of your app).
I do have a custom UIView for the grid, but it doesn't do much for
now, since I'm currently using the UIImageView instances to do the
heavy lifting.
If it's taxing the device, then I would recommend creating your own
view, and compositing the images yourself in drawRect:, as you
suggest.
That's what I was inclined to do from the start, but I found it easier
to code the UIImageView solution first, to see how it works out.
To get your animation, just set a timer at your frame rate and call
setNeedsDisplay on the view in its callback. Inside drawRect, you
could either work out what to display based on the time, or you
could set some flags in your timer routine setting 'state' for
drawrect to use before you make the setNeedsDisplay call.
Ah, ok. This is the guidance I needed. Thanks!
Look at the UIImage's drawInRect and/or drawAtPoint: methods for how
to draw the images. There are methods that let you specify alpha
and blend mode, and the drawInRect method will scale the image to
fit the rect you specify.
Yes, I'm familiar with them.
Note that you won't need an UIImage instance for every 'ball' - ones
that are the same looking can just be drawn by reusing the same
UIImage instance and drawing it multiple times.
Indeed. In fact, I have a custom class working as a singleton image
server that hands out cached versions of the necessary images.
If this is still taxing, you might want to look into using a custom
OpenGL view to do your rendering (although you might want to run
through a few OpenGL tutorials first if you've never used OpenGL
before, I'd say it's quite a different style of API in many ways).
I considered openGL as well, but I have no practical experience with
it and this is not the best time for me to learn it, while I'm trying
to finish this application.
Thank you for your help.
Wagner
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden