reflecting an NSImage in the Y-axis

dave.h

Registered
Is there a fast, practical way to reflect an NSImage across the vertical axis? I'm writing a 2-d game and it just seems stupid to me that I have different sprites for the same person walking to the Left and to the Right, thereby pretty much doubling the RAM the program requires...

I'm familiar with NSAffineTransform, but don't think it applies here..

I also know of the drawAtPoint method, which is what I'm using... I'm not sure if drawInRect would work.. would a rect with negative width draw mirrored?

I appreciate any response.
 
Scale the image by -1.0 on whichever axis you want to flip it.

http://www.stone.com/The_Cocoa_Files/Cocoamotion.html

Code:
        // make a new transform:
NSAffineTransform *t = [NSAffineTransform transform];
        
        // by scaling Y negatively, we effectively flip the image:
[t scaleXBy:1.0 yBy:-1.0];
        
        // but we also have to translate it back by its height:
[t translateXBy:0.0 yBy:-_bounds.size.height];
        
        // apply the transform:
[t concat];
 
yey, thanks...

okay, however after fooling around with NSAffineTransform for a while, I realized I'm really not sure how concat is supposed to work. It apparently applies the Transform matrix associated with NSA.T. as what the current view uses for all drawing. So I check a variable to determine if the image should be displayed mirrored, then call [at concat] followed immediately by doing all the drawing. But there is no horizontal flipping. I'm confident I initialized and set up the matrix properly, but I don't think I'm concatting quite right...

I would expect the concat call to have to be closer to [self something:[at concat]] but I couldn't find anything in NSView that requires an affine-transform matrix...

I've also tried passing a rect with negative width into NSImage's drawInRect, which resulted in nothing being displayed.

Apparently I still need some help.. :(
Thanks for starting to clarify the picture though.
 
Back
Top