In Corona SDK the background image always cover other images

Posted by user1446126 on Stack Overflow See other posts from Stack Overflow or by user1446126
Published on 2012-07-08T09:11:03Z Indexed on 2012/07/08 9:15 UTC
Read the original article Hit count: 266

Filed under:
|

I'm currently making a tower defense game with Corona SDK. However, while I'm making the gaming scene, The background scene always cover the monster spawn, I've tried background:toBack() ,however it's doesn't work.Here is my code:

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

and the monster just stuck at the spawn point and stay there. enter image description here

but, When i comment these 3 lines of code:

--local bg = display.newImage ("image/levels/1/bg.png");
--bg.x = _W/2;bg.y = _H/2;
--bg:toBack();

The problem disappear enter image description here

Any ideas??Thanks for helping

© Stack Overflow or respective owner

Related posts about game-development

Related posts about corona