Hi all,
I’m experiencing something strange with my code: director does not remove my images, although I add them to a group. I re-read the code again and again, and yet, I cannot spot the error.
Basically, I add some images, and center them on screen. When transitioning to the very same scene , I get duplicate images. At first I though that saving the image table pointer was the culprit, but as you can see, I commented it and still I get duplicates.
Can somebody see what I’m doing wrong?
Thanks & Cheers!
[code]
module(…, package.seeall)
local director = require(“director”)
local platform = require(“platform”)
local utils = require(“utils”)
local crt = display.newGroup()
new = function(params)
– Menu items { image, scene, pointer, timer }
local menuItems =
{
{ img = “images/menu1.jpg”, scene = “scratch”, ptr = nil, timer = nil },
{ img = “images/menu2.jpg”, scene = “menu”, ptr = nil, timer = nil },
{ img = “images/menu3.jpg”, scene = “menu”, ptr = nil, timer = nil },
{ img = “images/menu4.jpg”, scene = “menu”, ptr = nil, timer = nil },
{ img = “images/menu5.jpg”, scene = “menu”, ptr = nil, timer = nil },
{ img = “images/menu6.jpg”, scene = “menu”, ptr = nil, timer = nil }
}
– Graphics and number of items per row
local w = 260
local x = platform.left() + w / 2
local y = platform.top() + w / 2
local n = 3
– The menu group
local grp = display.newGroup()
for i, val in ipairs(menuItems) do
– Add menu item
local menuImage = utils.newScaledImage(val.img, { width = w })
menuImage.x = x
menuImage.y = y
menuImage:rotate(math.random(-5, 5))
–val.ptr = menuImage
crt:insert(menuImage)
grp:insert(menuImage)
– Last row with #items == 2
print("i == " … i … " width == " … grp.width)
– Layout
if ((i + 1) % n) == 1 and (i ~= 1) then
– Move to the next line
x = w / 2
y = y + 50 + w
else
x = x + 50 + w
end
menuImage:addEventListener(“tap”, function(event) director:changeScene(menuItems[i].scene, “crossfade”) end)
end
grp.x = (platform.right() - platform.left() - grp.width ) / 2
grp.y = (platform.bottom() - platform.top() - grp.height) / 2
timer.performWithDelay(1000, function(event) transition.to(menuItems[1].ptr, { time = 200, rotation = 45 }) end)
crt:insert(grp)
return crt
end
[/code] [import]uid: 94362 topic_id: 33907 reply_id: 333907[/import]