ImageRect won't rotate at time of creation

I’m trying to insert a newImageRect object and then rotate it according to the device’s orientation (i.e. I want “up” on the image to be “up” on the display).

 local img = display.newImageRect( fname, 100,100 ) img:setReferencePoint( display.CenterReferencePoint ) img.touch = processTouch img:addEventListener( "touch", img ) img.x = display.contentWidth \* 0.50 img.y = display.contentHeight \* 0.50 if( (scene.orientation=="portrait") or (scene.orientation=="portraitUpsideDown") ) then -- no rotation needed elseif( (scene.orientation=="landscapeLeft") or (scene.orientation=="landscapeRight") ) then print( "rotating image at creation time" ) img:rotate( math.pi/2 ) end gfxArea:insert( img )

The img:rotate command executes (I can see the print-out), but the object itself isn’t rotated.  If I rotate the object later (in response to device orientation change), then it DOES rotate properly … it just won’t do it at creation time.

Any ideas? 

Try using this:

        img.rotation = ( math.pi/2 )

No luck … img.rotation=(math.pi/2) doesn’t work either   :frowning:

Strange… it works fine for me. Have you tried changing:

scene.orientation

to

system.orientation

for testing?

DOH!   I assume that the angle was in radians … but it’s in degrees!    (it was probably rotating it properly, but pi/2 is 1.57 degrees … too small to see)

Try using this:

        img.rotation = ( math.pi/2 )

No luck … img.rotation=(math.pi/2) doesn’t work either   :frowning:

Strange… it works fine for me. Have you tried changing:

scene.orientation

to

system.orientation

for testing?

DOH!   I assume that the angle was in radians … but it’s in degrees!    (it was probably rotating it properly, but pi/2 is 1.57 degrees … too small to see)