I have a problem (obviously). Actually I don't know why this solution doesnt work.
I have background which is moving on every frame rate. I have also 2 buttons on screen. When I push and hold left button background rotate to left, when right - background rotate to right. In point (1) I'm making some calculation how this background should move in current frame. Later I assign result of this calculation in point (2). Everything works fine -- lets call it situation A.
Now I want to add group of some objects which will be move in the same direction as background..and here appear problem. When I add in point (3) eventListener to this group (called myGroup), background and myGroup are moving in different way than background alone (from situation A).
Here are my questions:
- Can I put group into another group?
- Can I add event listener into group?
or any other idea why after adding listener into myGroup, background and myGroup don't move as backround alone (without myGroup with listener)?
I hope I explained my problem clearly. Thx in advance for help!
function createGame()
background = display.newImage("background.jpg", 0, 0, true);
background.x = _W/2; background.y = _H/2;
background.enterFrame = onFrame;
Runtime:addEventListener("enterFrame", background);
group:insert(background);
myGroup = display.newGroup();
myGroup.xReference = _W/2; myGroup.yReference = _H/2;
myGroup.enterFrame = onFrame;
Runtime:addEventListener("enterFrame", myGroup); -- (3)
group:insert(myGroup); -- this group called "group" comes from storyboard
myGroup:insert(some other objects);
end
-- Move background:
function onFrame(self)
-- (1) Calculate next move of background:
-- (I'm making some calculation here how background should move. Calculation returns X and Y)
-- (2) Move background and group:
self.y = self.y + Y;
self.x = self.x + X;
self.yReference = self.yReference - Y;
self.xReference = self.xReference - X;
end