hi, i have a little problem im working on my first project is a game with a rocket in the space, the rocket has to evade the enemies, the rocket only moves up and down, and i have a code from a user here on this page but im only understand it from parts, is a code of a line following the rocket like a fire leaving behind. my problem is when i reload the scene with my reload button all of my objects works perfectly but the line starts to paint for all the screen.
i think my problem is when i reload all the scene im not reloading the line and its paints again, but i don’t know how to reload the line like my other objects
this is an example of my image group in the scene.
local storyboard = require ("storyboard") local scene = storyboard.newScene() function scene:createScene(event) local screenGroup = self.view object = display.newImage("rocket.png") object:scale(0.023,0.023) object.x = 113 object.y = 160 physics.addBody( object, "dynamic", physicsData:get("rocket") ) screenGroup:insert(object) end
and this is the code of the line following the rocket
xpos = { x = 0 } -- A proxy object for the exhaust local my\_line, prevx, prevy local X = 90 local TimePerScreen = 2000 local NumberOfScreens = 2 local FinalX = -NumberOfScreens \* display.contentWidth transition.to(xpos, { time = TimePerScreen \* NumberOfScreens, x = FinalX, iterations = -1, -- Repeat forever onRepeat = function() transition.to(my\_line, { -- Move the old line the rest of the way off screen... time = TimePerScreen, x = my\_line.x - display.contentWidth, onComplete = my\_line:removeSelf() }) my\_line = nil -- ...and start a new one. prevx = prevx - FinalX -- Correct the previous x to account for the split end }) timer.performWithDelay(5, function() local x, y = xpos.x, object.y if x == FinalX then -- x might still be a big negative value for a few frames x = 0 end if x ~= prevx or y ~= prevy then if my\_line then -- line already exists? my\_line.x = X + x my\_line:append(X, y) elseif prevx then -- previous point exists? my\_line = display.newLine(X + prevx, prevy, X, y) my\_line:setStrokeColor( 0,0.6,0.9 ) my\_line.strokeWidth = 20 my\_line.alpha= 0.3 end prevx, prevy = x, y end end, 0) function scene:enterScene(event) end function scene:exitScene(event) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene
My question is how to put the object my_line in the image group to reload it with my other objects together
sorry if i not express my self correctly im learning english.