Yes i had everything inserted into the level group. I tried changing the order in which i inserted everything into the the groups and still the physical objects don’t move away even though in debug mode it shows them going to a different spot.
Here is my code.
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
localGroup.x = 0;
localGroup.y = 0;
local bg = display.newRect(0,0,_w,_h)
bg:setFillColor(255,255,255)
localGroup:insert(bg)
local level = display.newGroup()
localGroup:insert(level)
level.x = 0;
level.y = 0;
local physics = require(“physics”);
physics.start();
physics.setDrawMode(“hybrid”);
local bottom = display.newRect(0,0,300,14)
bottom:setFillColor (100,0,0)
level:insert(bottom)
bottom.y = _h - 6
bottom.x = _w/2
local bullet_time = math.random (8000, 14000)
staticMaterial = {density=2, friction=0.3, bounce=0.1}
physics.addBody(bottom, “kinematic”, staticMaterial);
local function spawnBullet(e)
local bullet = display.newRect(0,0,20,20)
localGroup:insert(bullet)
bullet:setFillColor(0,0,0)
bullet.x = _w - 20
bullet.y = math.random (_h - _h + 35,_h - 35)
physics.addBody(bullet, “kinematic”, staticMaterial)
bullet:setLinearVelocity(-200,0)
bullet.name = bullet
end
timer.performWithDelay(bullet_time, spawnBullet, -1)
local lpos = 0
function move(e)
lpos = lpos -5
level.x = lpos
end
timer.performWithDelay(10, move, -1)
– SPRITE –
— Very important! —
require “sprite”
local heroSheet = sprite.newSpriteSheet(“gravman.png”, 32.14, 39)
– Our sprite sheet –
– 32 is the width of each “box”, this is the image width divided by the number of images across —
– 39 is the height of each “box”, this is the image height divided by the number of images down —
local heroSet = sprite.newSpriteSet (heroSheet, 1, 12)
sprite.add (heroSet, “heroBottom”,1 , 7, 300, 0)
sprite.add (heroSet, “heroTop”, 8, 7, 300, 0)
– The sprite set uses images 1 to 14 (all of them) —
– “heroBottom” starts at image 1 and includes 7 frames. (In this case 1, 2, 3.) —
– The “300” indicates .3 seconds per frame, the “0” indicates it will repeat until we stop it. —
local square = {-16,-39, 16,-39, 11,38, -16,38}
– We insert out hero sprite –
local hero = sprite.newSprite (heroSet)
localGroup:insert(hero)
hero.x = _w/2
hero.y = _h/1.5
physics.addBody(hero, “dynamic”, { density = 1.0, friction = 0.3,bounce=0} )
hero.isFixedRotation = true
hero.isBullet = true
hero.name = “hero”
hero.isSleepingAllowed = false
hero:prepare(“heroBottom”)
hero:prepare(“heroBottom”)
hero:play(“heroBottom”)
– MOVEMENT –
function moveDown (e)
hero:prepare(“heroBottom”)
hero:play(“heroBottom”)
end
function moveUp (e)
hero:prepare(“heroTop”)
hero:play(“heroTop”)
end
local button_up = display.newRect(_w/12,_h/8,45,45)
button_up:setFillColor(100,0,0)
local function changeGravityUp(e)
if e.phase == “ended” then
physics.setGravity(0,-20)
end
timer.performWithDelay(300, moveUp, 1)
end
button_up:addEventListener(“touch”, changeGravityUp)
local button_down = display.newRect(_w/12,_h/1.4,45,45)
button_down:setFillColor(100,0,0)
local function changeGravityDown(e)
if e.phase == “ended” then
physics.setGravity(0,20)
end
timer.performWithDelay(300, moveDown, 1)
end
button_down:addEventListener(“touch”, changeGravityDown)
return localGroup
end [/lua] [import]uid: 62404 topic_id: 13075 reply_id: 48117[/import]