Rob
i have assigned color to every object is created, when i tap the object it gives color but when i create bombstartnew local outside adddobject function and when i tap it, it gives me wrong color
Gives correct color when tocuhed
local function addnewobject() local startingpoint = math.random(display.contentWidth\*0.1,display.contentWidth\*0.9) local bombstartnew = display.newRect( startingpoint, -340, 50, 50) physics.addBody( bombstartnew ) local color1, color2, color3 = ragdogLib.convertHexToRGB(randomcolor()) bombstartnew:setFillColor(color1, color2, color3); bombstartnew.fillColor = {color1, color2, color3} bombCount = bombCount + 1 myBombTable[#myBombTable+1] = bombstartnew bombstartnew.myNumber = bombCount local function bombTouched(event) if ( event.phase == "began" ) then print(unpack(bombstartnew.fillColor)) Runtime:removeEventListener( "enterFrame", event.self ) event.target:removeSelf() score = score + 1 -- add new score to current score scoreText.text = score end end bombstartnew.enterFrame = offscreen Runtime:addEventListener( "enterFrame", bombstartnew ) bombstartnew:addEventListener( "touch", bombTouched ) end
wrong color when touched
local bombstartnew local function bombTouched(event) if ( event.phase == "began" ) then print(unpack(bombstartnew.fillColor)) Runtime:removeEventListener( "enterFrame", event.self ) event.target:removeSelf() score = score + 1 -- add new score to current score scoreText.text = score end end local function addnewobject() local startingpoint = math.random(display.contentWidth\*0.1,display.contentWidth\*0.9) bombstartnew = display.newRect( startingpoint, -340, 50, 50) physics.addBody( bombstartnew ) local color1, color2, color3 = ragdogLib.convertHexToRGB(randomcolor()) bombstartnew:setFillColor(color1, color2, color3); bombstartnew.fillColor = {color1, color2, color3} bombCount = bombCount + 1 myBombTable[#myBombTable+1] = bombstartnew bombstartnew.myNumber = bombCount bombstartnew.enterFrame = offscreen Runtime:addEventListener( "enterFrame", bombstartnew ) bombstartnew:addEventListener( "touch", bombTouched ) end