我目前正在用Corona SDK制作塔防游戏。然而,当我在做游戏的场景,背景场景总是覆盖怪物的刷新,我已经试过background:toBack()
,但是它不work.Here是我的代码:在Corona SDK中,背景图片总是覆盖其他图片
module(..., package.seeall)
function new()
local localGroup = display.newGroup();
local level=require(data.levelSelected);
local currentDes = 1;
monsters_list = display.newGroup()
--The background
local bg = display.newImage ("image/levels/1/bg.png");
bg.x = _W/2;bg.y = _H/2;
bg:toBack();
--generate the monsters
function spawn_monster(kind)
local monster=require("monsters."..kind);
newMonster=monster.new()
--read the spawn(starting point) in level, and spawn the monster there
newMonster.x=level.route[1][1];newMonster.y=level.route[1][2];
monsters_list:insert(newMonster);
localGroup:insert(monsters_list);
return monsters_list;
end
function move(monster,x,y)
-- Using pythagoras to calauate the moving distace, Hence calauate the time consumed according to speed
transition.to(monster,{time=math.sqrt(math.abs(monster.x-x)^2+math.abs(monster.y-y)^2)/(monster.speed/30),x=x, y=y, onComplete=newDes})
end
function newDes()
currentDes=currentDes+1;
end
--moake monster move according to the route
function move_monster()
for i=1,monsters_list.numChildren do
move(monsters_list[i],200,200);
print (currentDes);
end
end
function agent()
spawn_monster("basic");
end
--Excute function above.
timer2 = timer.performWithDelay(1000,agent,10);
timer.performWithDelay(100,move_monster,-1);
timer.performWithDelay(10,update,-1);
move_monster();
return localGroup;
end
和怪物正好卡在重生点并留在那里。
但是,当我评论这3行代码:
--local bg = display.newImage ("image/levels/1/bg.png");
--bg.x = _W/2;bg.y = _H/2;
--bg:toBack();
问题消失
??感谢任何想法,帮助
也许你是多次产卵的背景?尝试在产生背景检查后立即添加'print(“衍生”)。只是一个想法,可能不是解决方案。 – Jutanium 2012-07-08 10:31:51
我试过了,但它不起作用,无论如何,谢谢你的建议! – 2012-07-08 11:46:03
这个问题仍然很好,每个人都会遇到这个问题。但接受的答案已过时。 Corona Labs在2014年推出了用于场景管理的Composer API(https://coronalabs.com/blog/2014/01/21/introducing-the-composer-api-plus-tutorial/)。[我的回答](http ://stackoverflow.com/a/42976328/6286781)更新了作曲家接受的答案。 – GoojajiGreg 2017-03-23 12:44:26