makotok/Hanappe

DisplayObject:setLayer() doesn't call setParent()

Closed this issue · 7 comments

Is this a bug or a design choice?
If it's the former, add it. If it's the latter, fix your samples since the movement transitions fail because of this.

Edit
When calling setParent() on a prop to attach it to the layer transform-wise, the touch handler gets stuck in an infinite loop every time a touch event triggers for that prop.
The DisplayObject.parent member causes this.

I'm not sure is a problem.
Do you have a sample?

I am actually not sure what the problem is either, since nothing I try to do fixes it.

In a given scene, if you try to call seekLoc/seekScl/moveLoc/moveScl on the scene itself or on a layer, nothing happens. If you call it on a group/image/whatever it works.

If you try to call seekRot/moveRot, it instantly gets to the end of the animation without actually animating.

seekColor/moveColor work fine.

If you set the parent of a given group/image/whatever to a layer attached to the screen, all the above work, but every time it gets a touch event, the touch handler gets into an infinite loop until it reaches stack overflow.

Here are a few scenes to illustrate all the issues, this is the start of every scene

module(..., package.seeall)

local layer = flower.Layer()
local image = flower.Image("cathead.png")

layer:setTouchEnabled(true)
image:setLayer(layer)
...
-- move/seekRot fails
function onCreate(e)
  scene:addChild(layer)

  -- This instantly rotates the image and stops touch events from reaching it
  image:moveRot(180, 1)

  -- Doesn't work
  image:addEventListener("touchDown", function (e) print("Touched") end)
end
-- move/seekLoc fails
function onCreate(e)
  scene:addChild(layer)

  -- This works
  image:moveLoc(100, 0, 0, 1)

  -- These don't do anything...
  layer:moveLoc(0, 100, 0, 1)
  scene:moveLoc(0, 100, 0, 1)

  -- Doesn't work if layer/scene move/seekLoc are called
  -- The touch events get sent to the REAL position of the prop, 200 pixels down on the Y axis
  image:addEventListener("touchDown", function (e) print("Touched") end)
end
-- setParent fails
function onCreate(e)
  scene:addChild(layer)

  image:setParent(layer)

  -- These work now...
  layer:moveLoc(0, 50, 0, 1)
  scene:moveLoc(50, 0, 0, 1)

  --...but they stop touch events from working properly.
  -- They are sent further down, so click a little below and to the right of 
  -- the image to get the next bug: an infinite loop and stack overflow
  image:addEventListener("touchDown", function (e) print("Touched") end)
end

A side effect of these bugs is that any transition that involves movement (popIn, popOut, slideLeft, slideRight, slideTop, slideBottom) isn't working correctly.
How on Earth did you not see this in your sample demo...

Thank you. I understood.
Have problems when I upgraded to V1.4.
Already been fixed. You should see it in the latest build.

#37
moai/moai-dev#660

-- NG. Not 3D. Not MOAIProp2D 2D Interface.
image:moveRot(180, 1)
-- OK
image:moveRot(0, 0, 180, 1)
--- #37
layer:moveLoc(0, 100, 0, 1)
scene:moveLoc(0, 100, 0, 1)
-- NG. Not support.
image:setParent(layer)
-- OK
group:addChild(image)
image:setParent(prop)

I see, too bad nobody made any nightly build since a month ago. I can't be arsed to install Visual Studio now...

Hmm...
I'll try to prompt you for an update on the team of Moai.

There is a thing that is not stable release of MoaiSDK.
It is a bad part of Moai.

Still have the old version.
I can also work around this version for a while.

Moai SDK Version 1.3 (Build 160)
https://dashboard.moaicloud.com/download.php
(Login after)