how to i put object in a group and remove without display group?

To explain why I am not using display groups, it is because I am use the perspective library (in code contribute on corona) in my game and can not have 2 display groups i believe. I have been trying to use tables but have had not luck. A lot of the code is from https://coronalabs.com/blog/2013/04/09/physics-radial-gravity-and-predicting-trajectory/ 

this not my whole lua file but good enough i hope.

36 and 37 have errors by the way.

local composer = require("composer") local physics = require("physics") local perspective = require("perspective") physics.start( ) physics.setGravity( 0, 10 ) --physics.setDrawMode( "hybrid" ) local camera = perspective.createView() --later local function getTrajectoryPoint( startingPosition, startingVelocity, n ) --velocity and gravity are given per second but we want time step values here local t = 1/display.fps --seconds per time step at 60fps local stepVelocity = { x=t\*startingVelocity.x, y=t\*startingVelocity.y } --b2Vec2 stepVelocity = t \* startingVelocity local stepGravity = { x=t\*0, y=t\*10 } --b2Vec2 stepGravity = t \* t \* m\_world return { x = startingPosition.x + n \* stepVelocity.x + 0.25 \* (n\*n+n) \* stepGravity.x, y = startingPosition.y + n \* stepVelocity.y + 0.25 \* (n\*n+n) \* stepGravity.y } --startingPosition + n \* stepVelocity + 0.25 \* (n\*n+n) \* stepGravity end -- here is main problem local function updatePrediction( event ) if (circT~= nil) then for i=1, 20 do camera:remove("circT"..i) circT[i]:removeSelf() --error here circT[i] = nil --error here circT= nil end end circT = {} local startingVelocity = { x=((event.x-event.xStart)\*-1), y=((event.y-event.yStart)\*-1) } for i = 1,20 do --for (int i = 0; i \< 180; i++) local s = { x=(rollyPolly.x), y=(rollyPolly.y) } local trajectoryPosition = getTrajectoryPoint( s, startingVelocity, i ) -- b2Vec2 trajectoryPosition = getTrajectoryPoint( startingPosition, startingVelocity, i ) circT[i]= display.newCircle(trajectoryPosition.x, trajectoryPosition.y, 5 ) circT[i].alpha= .2 camera:add(circT[i], 1) end end -- end of problem area local function fireProj( event ) if ( event.xStart \< -ox+44 or event.xStart \> display.contentWidth+ox-44 or event.yStart \< -oy+44 or event.yStart \> display.contentHeight+oy-44 ) then display.remove( prediction ) return end local proj = display.newImageRect( "object.png", 64, 64 ) physics.addBody( proj, { bounce=0.2, density=1.0, radius=14 } ) proj.x, proj.y = event.xStart, event.yStart local vx, vy = event.x-event.xStart, event.y-event.yStart proj:setLinearVelocity( vx,vy ) end

thank you ,

Scott Harrison

Hi Scott,

I’m aware of – but haven’t used – the perspective library, but this seems to be unrelated. If I understand what you’re trying to do, it’s to place a path of “predictive” circles for the trajectory inside the “camera view”, then later you want to remove all of those circles, for example when the player changes the trajectory or fires the projectile. Correct?

If so, I would suggest using a holding table (an empty table to begin) that is first declared somewhere above and outside of your “updatePrediction” function. This table could be named “circT” like you have it, but it should be local (not global) and in the proper scope so that your function(s) recognize it.

With that declared, when you first call “updatePrediction()”, loop through that table backwards and clear out any members, if they exist:

[lua]

for i = #circT,1,-1 do

   display.remove( circT[i] )

   circT[i] = nil

end

[/lua]

I don’t think you need to remove them from the “camera” in addition, but again, I’m not familiar with that library’s code.

Now sometime after that, when you want to plot out a new path, the code you’re already using should be fine, because it adds each new circle to the “circT” table.

Hope this helps,

Brent

Thanks that is what I am trying to do, I will try that when I get home.

Thanks,
Scott

edit I fixed it thanks for all your help

Hi Scott,

I’m aware of – but haven’t used – the perspective library, but this seems to be unrelated. If I understand what you’re trying to do, it’s to place a path of “predictive” circles for the trajectory inside the “camera view”, then later you want to remove all of those circles, for example when the player changes the trajectory or fires the projectile. Correct?

If so, I would suggest using a holding table (an empty table to begin) that is first declared somewhere above and outside of your “updatePrediction” function. This table could be named “circT” like you have it, but it should be local (not global) and in the proper scope so that your function(s) recognize it.

With that declared, when you first call “updatePrediction()”, loop through that table backwards and clear out any members, if they exist:

[lua]

for i = #circT,1,-1 do

   display.remove( circT[i] )

   circT[i] = nil

end

[/lua]

I don’t think you need to remove them from the “camera” in addition, but again, I’m not familiar with that library’s code.

Now sometime after that, when you want to plot out a new path, the code you’re already using should be fine, because it adds each new circle to the “circT” table.

Hope this helps,

Brent

Thanks that is what I am trying to do, I will try that when I get home.

Thanks,
Scott

edit I fixed it thanks for all your help