我目前正在用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