MOAIViewport Positioning Bug [v1.0 r3]

Discussion about using Moai SDK - post questions, bugs and issues here.

Moderators: seebs, franciscotufro

MOAIViewport Positioning Bug [v1.0 r3]

Postby Qubbe » Mon Apr 09, 2012 7:45 am

I have just updated to using MOAI v1.0 r3 from 0.95 where I have been using non-fullscreen viewports and positioning them using function setSize ( MOAIViewport self, number left, number top, number right, number bottom ). In 0.95 this worked great, if I setSize(0, 0, 320, 200) it would make a 320x200 viewport showing in the topleft of my (1024x768) window and any buttons or interaction I add work as expected no matter where i position the viewport. In v1.0 the same code creates the a 320,200 viewport in the bottom left of my window but all button and mouse interactivity respond as if the viewport is at the topleft of the window.


You can see recreation using the input-picking sample from the MOAI SDK. Just make the window size bigger than the viewport size.

Code: Select all
  1.  

  2. ----------------------------------------------------------------

  3. -- Copyright (c) 2010-2011 Zipline Games, Inc.

  4. -- All Rights Reserved.

  5. -- <!-- m --><a class="postlink" href="http://getmoai.com">http://getmoai.com</a><!-- m -->

  6. ----------------------------------------------------------------

  7.  

  8. MOAISim.openWindow ( "test", 1024, 768 )

  9.  

  10. layer = MOAILayer2D.new ()

  11. MOAISim.pushRenderPass ( layer )

  12.  

  13. viewport = MOAIViewport.new ()

  14. viewport:setSize ( 320, 480 )

  15. viewport:setScale ( 320, 480 )

  16. layer:setViewport ( viewport )

  17.  

  18. partition = MOAIPartition.new ()

  19. layer:setPartition ( partition )

  20.  

  21. gfxQuad = MOAIGfxQuad2D.new ()

  22. gfxQuad:setTexture ( "cathead.png" )

  23. gfxQuad:setRect ( -64, -64, 64, 64 )

  24.  

  25. function addSprite ( x, y, xScl, yScl, name )

  26.         local prop = MOAIProp2D.new ()

  27.         prop:setDeck ( gfxQuad )

  28.         prop:setPriority ( priority )

  29.         prop:setLoc ( x, y )

  30.         prop:setScl ( xScl, yScl )

  31.         prop.name = name

  32.         partition:insertProp ( prop )

  33. end

  34.  

  35. addSprite ( -64, 64, 0.5, 0.5, "sprite1" )

  36. addSprite ( 64, 64, 0.5, 0.5, "sprite2" )

  37. addSprite ( 0, 0, 0.5, 0.5, "sprite3" )

  38. addSprite ( 64, -64, 0.5, 0.5, "sprite4" )

  39. addSprite ( -64, -64, 0.5, 0.5, "sprite5" )

  40.  

  41. mouseX = 0

  42. mouseY = 0

  43.  

  44. priority = 5

  45.  

  46. local function printf ( ... )

  47.         return io.stdout:write ( string.format ( ... ))

  48. end

  49.  

  50. function pointerCallback ( x, y )

  51.        

  52.         local oldX = mouseX

  53.         local oldY = mouseY

  54.        

  55.         mouseX, mouseY = layer:wndToWorld ( x, y )

  56.        

  57.         if pick then

  58.                 pick:addLoc ( mouseX - oldX, mouseY - oldY )

  59.         end

  60. end

  61.                

  62. function clickCallback ( down )

  63.        

  64.         if down then

  65.                

  66.                 pick = partition:propForPoint ( mouseX, mouseY )

  67.                

  68.                 if pick then

  69.                         print ( pick.name )

  70.                         pick:setPriority ( priority )

  71.                         priority = priority + 1

  72.                         pick:moveScl ( 0.25, 0.25, 0.125, MOAIEaseType.EASE_IN )

  73.                 end

  74.         else

  75.                 if pick then

  76.                         pick:moveScl ( -0.25, -0.25, 0.125, MOAIEaseType.EASE_IN )

  77.                         pick = nil

  78.                 end

  79.         end

  80. end

  81.  

  82. if MOAIInputMgr.device.pointer then

  83.        

  84.         -- mouse input

  85.         MOAIInputMgr.device.pointer:setCallback ( pointerCallback )

  86.         MOAIInputMgr.device.mouseLeft:setCallback ( clickCallback )

  87. else

  88.  

  89.         -- touch input

  90.         MOAIInputMgr.device.touch:setCallback (

  91.        

  92.                 function ( eventType, idx, x, y, tapCount )

  93.  

  94.                         pointerCallback ( x, y )

  95.                

  96.                         if eventType == MOAITouchSensor.TOUCH_DOWN then

  97.                                 clickCallback ( true )

  98.                         elseif eventType == MOAITouchSensor.TOUCH_UP then

  99.                                 clickCallback ( false )

  100.                         end

  101.                 end

  102.         )

  103. end

Last edited by Qubbe on Tue Apr 10, 2012 10:42 am, edited 1 time in total.
Qubbe
 
Posts: 2
Joined: Thu Apr 05, 2012 3:51 pm

Re: MOAIViewport Positioning Bug [v1.0 r3]

Postby dana » Mon Apr 09, 2012 11:34 am

That's strange. Thanks for the report, I will look into it right now and get back to you.
User avatar
dana
Site Admin
 
Posts: 200
Joined: Fri Mar 02, 2012 6:10 pm
Location: Zipline Games

Re: MOAIViewport Positioning Bug [v1.0 r3]

Postby Qubbe » Mon Apr 23, 2012 2:44 pm

I am working on a gui systems where we can have scrollable windows and am using the viewports as a means of clipping content, is this an acceptable way of doing it in moai? Is there a better way? Also any news on the viewport bug or work arounds?

Thanks :)
Qubbe
 
Posts: 2
Joined: Thu Apr 05, 2012 3:51 pm

Re: MOAIViewport Positioning Bug [v1.0 r3]

Postby mirsadm » Mon Apr 23, 2012 4:02 pm

I've noticed the same issue. It is behaving quite oddly in 1.0 r3. I had a quick look at the MOAIViewport commits and my guess is it broke with the window->world changes. I'm compiling 0.95 beta now to compare.

Edit: Seems to be broken with portrait aspect ratios. For eg:

viewport:setSize ( 300, 400 )
viewport:setScale ( 300, -400 )
viewport:setOffset ( -1, 1 )

It appears to be correct and the top-left point on the window is 0, 0 as expected. If you try with

viewport:setSize ( 600, 800 )
viewport:setScale ( 600, -800 )
viewport:setOffset ( -1, 1 )

the top-left corner is no longer 0,0. If you have an image at 0,0 it'll be cut off.

Maybe I'm just crazy can someone else confirm?
Last edited by mirsadm on Mon Apr 23, 2012 5:01 pm, edited 1 time in total.
mirsadm
 
Posts: 14
Joined: Mon Apr 23, 2012 3:59 pm

Re: MOAIViewport Positioning Bug [v1.0 r3]

Postby adam » Mon Apr 23, 2012 4:47 pm

We're looking into this right now. ( https://github.com/moai/moai-dev/issues/259 ). Hopefully we'll resolve it soon.
User avatar
adam
 
Posts: 262
Joined: Wed Sep 14, 2011 11:50 am


Return to Moai SDK

Who is online

Users browsing this forum: No registered users and 0 guests

x