填充显示表corona sdk中的对象

时间:2014-12-14 16:29:43

标签: lua corona

我在使用Corona SDK创建关卡样式选择页面时遇到了一些问题。我正在制作一个出现日历风格的应用程序,我想创建一个日历页面,用户每天可以选择一天,它将打开播放一些圣诞音乐,精灵等。

我的问题是我似乎无法在日历上的日图标之间添加填充(所有图标都非常紧凑)。

关于这个问题的任何帮助都会很棒!感谢

(我的代码可以在下面找到)

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()


-- local forward references should go here --

--levelProgress = 0
--levelImg = {}
--allLevels = {}


levels = 
{   
1,  2, 2, 2 , 2,  --1 means level is open to    be played (level.png)
2, 2, 2, 2, 2,   --2 means level is locked (locked.png)
2, 2, 2, 2, 2,
2, 2, 2, 2, 2,
2, 2, 2, 2, 2,
-- 3 means level is completed (greenchecked.png)
}

images ={
       -- {topPaddig = 50},
    { getFile = "gift.png", types = "play", bottomPadding = 50   },
    { getFile = "lock.png", types = "locked", bottomPaddingPadding = 50},
    { getFile = "greenchecked.png", types = "done", bottomPadding = 50}
}


local function buttonHit(event)
    storyboard.gotoScene ( event.target.destination, {effect = "slideUp"} ) 
    print( event.target.destination)
        return true
end

-- Called when the scene's view does not exist:
function scene:createScene( event )
    local group = self.view

    local levelIndex =0
        for i=0,4 do
            for j=1,5 do
                tablePlace =   i*5 + j  
                levelIndex = levelIndex + 1
                    local imagesId = levels[levelIndex] 
                        levelImg = display.newImageRect (images[imagesId].getFile , 50, 50 )
                        levelImg.x = 0 + (j*55)
                        levelImg.y  = 130+ (i*55)
                        group:insert(levelImg)

                        leveltxt = display.newText("Day "..tostring(tablePlace), 0,0, "Helvetica", 10)
                        leveltxt.x = 0 + (j*55)
                        leveltxt .y = 155+ (i*55)
                        leveltxt:setTextColor (250, 255, 251)
                        group:insert (leveltxt)

                        levelImg.destination = "level0"..tostring(tablePlace)

                        if images[imagesId].types ~= "locked" then
                        levelImg:addEventListener("tap", buttonHit)
                        end
 end

end




    -- CREATE display objects and add them to 'group' here.
    -- Example use-case: Restore 'group' from previously saved state.

    local title = display.newText( "Level Selection", 0, 0, "Helvetica", 20 )
    title.x = centerX
    title.y = display.screenOriginY + 40
    group:insert(title)

    local backBtn = display.newText(  "Back", 0, 0, "Helvetica", 20 )
    backBtn.x = display.screenOriginX + 50
    backBtn.y = display.contentHeight  - 30 
    backBtn.destination = "menu" 
    backBtn:addEventListener("tap", buttonHit)
    group:insert(backBtn)



end


-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
    local group = self.view

    -- INSERT code here (e.g. start timers, load audio, start listeners, etc.)

end


-- Called when scene is about to move offscreen:
function scene:exitScene( event )
    local group = self.view

    -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
    -- Remove listeners attached to the Runtime, timers, transitions, audio tracks

end


-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
    local group = self.view

    -- INSERT code here (e.g. remove listeners, widgets, save state, etc.)
    -- Remove listeners attached to the Runtime, timers, transitions, audio tracks

end



---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------

-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )

-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )

-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )

-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )


---------------------------------------------------------------------------------

return scene

1 个答案:

答案 0 :(得分:0)

您是否尝试过引用每个对象的锚点? object.anchorX = 0.5; object.anchorY = 0.5 read here for more