I create scrolling for the menu in the Lua CORONA SDK.
Source file menu.lua
local composer = require( "composer" ) local widget = require( "widget" ) local scene = composer.newScene() local function onButtonRelease( event ) composer.gotoScene( event.target.id:lower(), { effect="fade", time=300 } ) --composer.recycleOnSceneChange = true end function scene:create( event ) local sceneGroup = self.view local sceneTitle = display.newText( sceneGroup, "Выберете уровень", display.contentCenterX, 10, composer.getVariable( "appFont" ), 20 ) -- Создание массива из кнопок меню local menuButtons = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18" } -- Создание цикла для кнопок меню local rowNum = 0 for i = 1,#menuButtons do rowNum = rowNum+1 local button = widget.newButton( { label = menuButtons[i], id = menuButtons[i], shape = "circle", radius = 20, font = composer.getVariable( "appFont" ), fontSize = 16, fillColor = { default={ 0.12,0.32,0.52,1 } ,over={ 0.132,0.352,0.572,1 } }, -- цвет кнопки и нажатия на кнопку labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, -- цвет шрифта на кнопках onRelease = onButtonRelease }) mod = math.fmod(i, 2) -- определение кратности if (i*mod >= 1 ) then -- если кратно 1 button.x = display.contentCenterX -50 elseif (i*mod == 0) then -- если кратно 0 button.x = display.contentCenterX + 50 end button.y = 65 + ((rowNum-1)*35) -- растояние по y между кнопками sceneGroup:insert( button ) -- обновление сцены после нажатия на кнопку end end scene:addEventListener( "create", scene ) -- слушатель на создание сцены --обработка касаний function scene:touch(e) -- body if(e.phase == "began") then print("начало a"); elseif (e.phase == "moved") then scene.x = ex; scene.y = ey; print("двигаю a"); elseif(e.phase == "ended") then print("отпустил a"); end end scene:addEventListener("touch", scene); return scene For clarity, attach the image
For touch processing, I tried both with the scene, and with the menu, and with an array of buttons.
Tell me, please, the solution to my problem.
