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