0
votes

I am trying to draw a sprite with NSImage using the drawInRect method. I noticed quickly that the coordinates passed in the rects are not in pixels but in points. I need to draw my sprites with pixel level accuracy, as each sprite is say exactly 73x92 pixels in dimensions.

In short, it seems I need either one of the following: 1) NSImage to accept my rects that are in pixels not some other unit. 2) a very accurate conversion from pixel to NSImage units such that addressing a pixel will not lead to any blurriness due to anti-aliasing effects.

1
Why not just break each image out into a separate image?Peter Hosey
You will have to give us an example, maybe with example images, you could be suffering from some antialiasing due to 75/72 dpi conversions...Grady Player
I'm with Peter. Why bother mucking about with sprite sheets when you can just load the images individually? I understand on iOS/OpenGL this can improve performance but the Mac is so much more powerful there is really very little need to use sprite sheets.Rob Keniger
I should add a disclaimer that I'm not a game developer, so I'm prepared to be called wrong on this one…Rob Keniger

1 Answers

1
votes

There is nothing fundamentally wrong with NSImage that would make that impossible. If you give it appropriate source and destination rects, it can certainly draw with pixel-level accuracy. You'll have to post your code for us to help in that regard.

However, you may find it easier to deal with a lower-level API. NSImage is designed to work with anything that seems like an image -- bitmaps, PDFs, etc. That generality, and its age, leads to some confusing behavior sometimes. I've found that using CGImage (which is always a bitmap) can be a lot more predictable. Or, try NSBitmapImageRep.