external module - group and object to front problem

hi,

I have this problem with this external module :

  1. i make a  another group with a rectangle and images (groupe)
  2. externally at this group i make a mask who must be in front of 

the problem is that the mask is below. i use

e.body.mask:toFront()

but it’s still below. the snippet is a the bottom. I could use an another external module to solve this but i would understand 

how it’s possible like this. thanks for your help.

local p=require( "parameters" ) local paper={} local paper\_mt = { \_\_index = paper } --set metatable -------------------------------------------------------------------------------- -- public function -------------------------------------------------------------------------------- function paper.draw( group,posx,posy,numberOfPaper,width)     local e={} --e for paper     height = numberOfPaper\*width     local groupe = display.newGroup()     groupe.main=display.newRect(groupe,0,0,width,height)     groupe.main.anchorY=0     groupe.unite = {}     for i=1, numberOfPaper do         groupe.unite[i]=display.newImageRect(groupe,"paper2.png",width,width)         groupe.unite[i].anchorY=1         groupe.unite[i].y=i\*width     end     e.body=groupe     e.body.x=posx     e.body.y=posy     e.body.anchorY=1 --here i can't have e.body.above who is in front of e.body     e.body.above = display.newRect(group,posx+10,p.position.limit,width,height)     e.body.above:setFillColor(0,0,0)     e.body.above.anchorY = 0     return setmetatable ( e,paper\_mt ) end return paper

I’m not sure you can create a mask from a display.newRect. Masks have to be solid white where you want the masked image/group to show through and black where you don’t. There is a requirement of a black border that is at least 3 pixels wide and the total mask width and height must be evenly divisible by 4 (so I make my black border at least 4px on all sides). You’re code isn’t creating a valid mask.

Then I don’t think you can control foreground/background on a mask. Either the mask exists or it doesn’t. The object will automatically put the mask where it belongs.

Rob

Hi Rob,

My english is bad > by mask i would say a rectangle wich is above the e.body

if my snippet is more simple like this :

local e={} e.body=display.newRect(100,100,100,100) e.above=display.newRect(80,80,80,80) e.above:setFillColor(1,0,0) e.above.alpha=.5

the e.above is good above e.body.

in my first snippet the usage of a group inside an another group creates the problem…Why ?

Nobody?

Instead of:

e.body.above = display.newRect(group,posx+10,p.position.limit,width,height)

try:

e.body.above = display.newRect(posx+10,p.position.limit,width,height)

Objects can only be in one group at a time. You’re putting the rectangle in “group”. I would think what you had should work. It’s very hard to follow. You’re adding things as members to an object (that happens to be a group), but lots of things you just inserting in to the parent “group”.

Rob

thanks a lot Rob it works and i have understand my error

I’m not sure you can create a mask from a display.newRect. Masks have to be solid white where you want the masked image/group to show through and black where you don’t. There is a requirement of a black border that is at least 3 pixels wide and the total mask width and height must be evenly divisible by 4 (so I make my black border at least 4px on all sides). You’re code isn’t creating a valid mask.

Then I don’t think you can control foreground/background on a mask. Either the mask exists or it doesn’t. The object will automatically put the mask where it belongs.

Rob

Hi Rob,

My english is bad > by mask i would say a rectangle wich is above the e.body

if my snippet is more simple like this :

local e={} e.body=display.newRect(100,100,100,100) e.above=display.newRect(80,80,80,80) e.above:setFillColor(1,0,0) e.above.alpha=.5

the e.above is good above e.body.

in my first snippet the usage of a group inside an another group creates the problem…Why ?

Nobody?

Instead of:

e.body.above = display.newRect(group,posx+10,p.position.limit,width,height)

try:

e.body.above = display.newRect(posx+10,p.position.limit,width,height)

Objects can only be in one group at a time. You’re putting the rectangle in “group”. I would think what you had should work. It’s very hard to follow. You’re adding things as members to an object (that happens to be a group), but lots of things you just inserting in to the parent “group”.

Rob

thanks a lot Rob it works and i have understand my error