[Bug?] Group, mask, runtime event + rotation

When i rotate a group object that contains an image with a mask, the image is rotating, but not the mask. I’m confused…

This is my code:

local group = display.newGroup()  
group.x = 100; group.y = 100  
  
local mask = graphics.newMask("mask.png")  
  
local image = display.newImage("image.png")  
image:setMask(mask)  
  
group:insert(image)  
  
function onEnterFrame(event)  
 group:rotate(1)  
end  
  
Runtime:addEventListener( "enterFrame", onEnterFrame )  

What wrong with my code?

Thanks already! [import]uid: 10863 topic_id: 19077 reply_id: 319077[/import]

Have you tried applying the mask to the display group instead of the image? Instead of:

[lua]image:setMask(mask)[/lua]

…you might try:

[lua]group:setMask(mask)[/lua] [import]uid: 27119 topic_id: 19077 reply_id: 73586[/import]

Try this:

[code]

local group = display.newGroup()
group.x = 100; group.y = 100

local mask = graphics.newMask(“mask.png”)

local image = display.newImage(“image.png”)
image:setMask(mask)

group:insert(image)

function onEnterFrame(event)
group.maskRotation = group.maskRotation + 1
group.rotation = group.rotation + 1
end

Runtime:addEventListener( “enterFrame”, onEnterFrame )

[/code] [import]uid: 24111 topic_id: 19077 reply_id: 73587[/import]

I actually ran into the same problem just yesterday. I use several masks. Then when “rotationfix.lua” kicks in, everything goes nuts. It would be nice if mask just followed. [import]uid: 99244 topic_id: 19077 reply_id: 73607[/import]

@drewns

Yes, but that’s not what i want. I need the mask within the group.

@oskwish

Your solution doesn’t work. Thank you anyway!

@tsuriyathep

I’m curious how you did that. Can you share some code? [import]uid: 10863 topic_id: 19077 reply_id: 73612[/import]

Can you insert the mask into the display group?

[lua]group:insert(image)
group:insert(mask)[/lua] [import]uid: 27119 topic_id: 19077 reply_id: 73618[/import]

No. I receive a runtime error. I think the mask belongs to the image and cannot be moved to the group. [import]uid: 10863 topic_id: 19077 reply_id: 73620[/import]

I use masks that have a different maskX, maskY. Maybe that is what is causing my issues. Corona might not have tested group rotation with different mask XY other than 0, since its a new feature. [import]uid: 99244 topic_id: 19077 reply_id: 73626[/import]

This could be a solution:

  1. Create a new file with a group object, a event listener and return it.
-- group.lua  
local repairedGroup = display.newGroup()  
  
local function onEnterFrame()  
 local child  
 for i = 1, repairedGroup.numChildren do  
 child = repairedGroup[i]  
 child.xReference = 0; child.yReference = 0  
 end  
end  
  
Runtime:addEventListener("enterFrame", onEnterFrame)  
  
return repairedGroup  
  1. Then require group.lua and use it like any group.
-- main.lua  
local group = require("group")  
  
local mask = graphics.newMask("mask.png")  
   
local image = display.newImage("brick.gif")  
image:setMask(mask)  
   
group:insert(image)  
  
local function onEnterFrame()  
 group:rotate(1)  
end  
  
Runtime:addEventListener("enterFrame", onEnterFrame)  

Does this have much impact on performance? [import]uid: 10863 topic_id: 19077 reply_id: 73723[/import]