How can I rotate a layer 180 degrees?

New to Moai? Get started here with our best tips and tutorials.

How can I rotate a layer 180 degrees?

Postby anddrewscott » Tue Jun 26, 2012 4:32 pm

Code: Select all
  1. MOAISim.openWindow ( "layer rotation", 320, 480 )

  2.  

  3. viewport = MOAIViewport.new ()

  4. viewport:setSize ( 320, 480 )

  5. viewport:setScale ( 320, -480 )

  6.  

  7. layer = MOAILayer2D.new ()

  8. layer:setViewport ( viewport )

  9. MOAISim.pushRenderPass ( layer )

  10.  

  11. gfxQuad = MOAIGfxQuad2D.new ()

  12. gfxQuad:setTexture ( "moai.png" )

  13. gfxQuad:setRect ( 0, 0, 128, 128 )

  14. gfxQuad:setUVRect ( 0, 0, 1, 1 )

  15.  

  16. prop = MOAIProp2D.new ()

  17. prop:setDeck ( gfxQuad )

  18. layer:insertProp ( prop )

  19.  



I am trying to rotate a layer by 180 degrees but am not having much success.

Code: Select all
  1. layer:setPiv(160, 240)

  2. layer:seekRot ( 180, 1 )


I tried the code above (set pivot point at the centre of the screen and then rotate. The prop is seen to expand and then shrink. This transformation leaves no changes.

Code: Select all
  1. layer:seekRot ( 180, 1 )

  2. layer:seekLoc(320, 480, 1)


(The second line of the code above is to move the layer back in to the screen as the prop 'rotates off' the screen.)
In the code above the prop is seen to loop around but not rotate. Again this transformation leaves no changes once it has finished.

Could anyone help me with this?
anddrewscott
 
Posts: 153
Joined: Fri Sep 02, 2011 7:39 am

Re: How can I rotate a layer 180 degrees?

Postby nosheet » Thu Jun 28, 2012 12:45 am

I haven't tried to rotate layers yet, but usually if I wanted to group objects I would create MOAITransform object and assign it as a parent to props I want to group. Not sure if this would be helpful in your case.
Another thing, you say the prop shrinks and expands - could it be that you are actually rotating a layer but around x axis in 3d space, and since you have ortho view it looks confusing? I am asking this because I had some problems where rotation would sometimes unexplainably work only in 2D, although given 4 parameters (I was trying to rotate in 3d at the time), so maybe the opposite could be true (although not likely)?
You may hate my haircut, but you'll love my games:
http://www.spin-up-game.com and http://www.foosballhero.com
User avatar
nosheet
 
Posts: 194
Joined: Mon May 28, 2012 2:40 pm
Location: Madrid, Spain

Re: How can I rotate a layer 180 degrees?

Postby sgeos » Thu Jun 28, 2012 6:48 am

nosheet wrote:I haven't tried to rotate layers yet, but usually if I wanted to group objects I would create MOAITransform object and assign it as a parent to props I want to group.

This is what I am doing. I set one object to be the parent, and then children then move relative to the parent.
Code: Select all
  1. local result = MOAIProp2D.new()

  2. result:setDeck( pTileset )

  3. result:setAttr( MOAIProp2D.ATTR_INDEX, pIndex )

  4. result:setParent( pParent )

  5. result:setPiv( pPivot.x, pPivot.y )

  6. result:setLoc( pOffset.x, pOffset.y )

  7. return result

Any original code posted by me is released via the CC0 Public Domain Dedication. It is in the public domain. Do whatever you want with it.
User avatar
sgeos
 
Posts: 241
Joined: Sat Apr 28, 2012 4:42 am
Location: Married in Japan.


Return to New Users

Who is online

Users browsing this forum: No registered users and 1 guest

x