Hi,
I need help, i want to be able to understand how to remove objects when not needed. many tutorials and examples would be great. Also help on my code would even be better. ill try and be very detailed but i am new so if i miss anything let me know.
in my code, i want to remove all my objects on the screen (besides the play button) and rerun a new set of random objects.
first off on the builder code, i am building a buttonLetter object that will have a displayGroup of 2 display images (one over the other). example:
local pigCard = {}
function buttonLetter(color, alphab, xLoc, yLoc)
local pigCardFrame = display.newImage("images/buttons/"..colors[color]..".png") -- frame layer --
local pigCardLetter = display.newImage("images/uc/"..alphab..".png") -- letter in frame --
pigCard.graphics = display.newGroup()
pigCard.graphics:insert(pigCardFrame) -- inserts this image first --
pigCard.graphics:insert(pigCardLetter) -- then inserts this aferwards, and etc --
--[[ IMPORTANT - make sure that the button is touched
and the image has been centered to your touch; without this
the image is 0,0 reference click
]]--
pigCard.graphics:setReferencePoint(display.CenterReferencePoint)
pigCard.graphics.x = 80 + xLoc; -- this moves the graphics x pos
pigCard.graphics.y = 80 + yLoc; -- this moves the graphics y pos
pigCard.graphics.xScale = .5 -- for phone users --
pigCard.graphics.yScale = .5
--[[DRAGGLE PIG CARD]]--
local function dragCard (event)
pigCard.graphics.x = event.x
pigCard.graphics.y = event.y
if event.phase == "began" then
event.target:toFront() -- on touch the object is upFront to anything else
end
if event.phase == "ended" then
pigCard.graphics.x = 80 + xLoc;
pigCard.graphics.y = 80 + yLoc;
end
return true
end
--[[local function removeMe (event)
if "ended" == event.phase then
print("i printed this")
event.target:removeSelf()
end
end]]--
pigCard.graphics:addEventListener ("touch", dragCard)
--pigCard.graphics:addEventListener ("touch", removeMe)
return pigCard.graphics
second is the wordCreation function, this is where i run a random word in a table list and formulate each letter to create the word
local wordCreate = {}
function wordCreation()
--[[lets see if we can print out string of words into letters]]
local wordCall = word[math.random(1,3)].word;
local xl, yl = 30
for i=1, string.len(wordCall), 1
do
wordCreate[i-1] = letterContent.buttonLetter(math.random(1,6), string.sub(wordCall, i, i), xl, 20)
xl = xl + 60
print("this letter is "..string.sub(wordCall, i, i))
end
end
To call my code at launch , i just call examples local makeWord = wordCall.wordCreation assuming my local wordCall = require(“wordCreationFile”)
so now in my main, that calls the above wordCall, i also have a button with an event listener, when pressed, i want to be able to clear out the word and rerun my wordCreation again? but i dont have a clue how, i tried wordCall:removeSelf() but i just get a “attempt to index upvalue ‘wordCall’ (a nil value)”.
any suggestions would be greatly appreciated.
also on one example i read on a code, is there a way to determine different event.phase say example if i touch a image and drag it around i would use addEventListener(“touch”, dragMe") but what if i want to also add that if i tap the image it will disappear, is that still the touch event?
[import]uid: 9114 topic_id: 12130 reply_id: 312130[/import]