Hi,
I’m trying to set up a menu page that uses scrollview but I can’t figure out how to make the buttons work along with it. The overSrc effect takes place but the touch event does not. Here’s what I’m working in:
module(..., package.seeall)
-- Main function - MUST return a display.newGroup()
function new()
local menuGroup = display.newGroup()
local ui = require("ui")
local scrollview = require("scrollview")
local util = require("util")
-- AUDIO
local tapSound = audio.loadSound( "button.mp3" )
--local backgroundSound = audio.loadStream( "rainsound.mp3" ) --\> This is how you'd load music
local drawScreen = function()
local shadeRect = display.newRect( 0, 0, 480, 320 )
shadeRect.xScale = shadeRect.contentWidth; shadeRect.yScale = shadeRect.contentWidth
shadeRect:setFillColor( 0, 0, 0, 255 )
shadeRect.alpha = 0
menuGroup:insert( shadeRect )
transition.to( shadeRect, { time=100, alpha=1 } )
local moreSectionBg = display.newImageRect( "scrollmore-bg.png", 480, 320 )
moreSectionBg.x = 240
moreSectionBg.y = 160
moreSectionBg.isVisible = false
menuGroup:insert(moreSectionBg)
timer.performWithDelay( 200, function() moreSectionBg.isVisible = true; end, 1 )
-- Setup a scrollable content group
local topBoundary = display.screenOriginY
local bottomBoundary = display.screenOriginY
local scrollview = scrollview.new{ top=topBoundary, bottom=bottomBoundary }
local linkPanels = display.newImageRect( "scrollmore.png", 480, 320 )
linkPanels.x = display.contentCenterX
linkPanels.y = display.contentCenterY
linkPanels.isVisible = false
timer.performWithDelay( 200, function() linkPanels.isVisible = true; end, 1 )
scrollview:insert(linkPanels)
--BACK BUTTON
local backBtn
local onBackTouch = function( event )
if event.phase == "release" then
audio.play( tapSound, { channel=2, onComplete=audio.stop( 2 ) } )
audio.dispose( 2 )
tapSound = nil
scrollview.isActive = false
--CLEAN OUT MENU GROUP BEFORE CHANGING SCENES
cleanGroup( menuGroup )
menuGroup = nil
cleanGroup( scrollview )
scrollview = nil
director:changeScene( "mainmenu" )
end
end
backBtn = ui.newButton{
defaultSrc = "backbutton.png",
defaultX = 159,
defaultY = 45,
overSrc = "backbutton-over.png",
overX = 159,
overY = 45,
onEvent = onBackTouch,
id = "Back Button",
text = "",
font = "Helvetica",
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
backBtn.x = 140; backBtn.y = 100
backBtn.isVisible = false
scrollview:insert( backBtn )
timer.performWithDelay( 201, function() backBtn.isVisible = true; end, 1 )
local myText = display.newText("Move Up to Scroll", 0, 0, "Trebuchet MS", 24)
myText:setTextColor(255, 255, 0)
myText.x = math.floor(display.contentWidth\*0.5)
myText.y = backBtn.y + 60
scrollview:insert(myText)
-- add some text to the scrolling screen
local lotsOfText = "Lorem ipsum dolor sit amet... "
local lotsOfTextObject = util.wrappedText( lotsOfText, 39, 14, native.systemFont, {255,255,0}, " ", " " )
scrollview:insert(lotsOfTextObject)
lotsOfTextObject.x = 10
lotsOfTextObject.y = math.floor(myText.y + myText.height/2)
-- Important! Add a background to the scroll view for a proper hit area
local scrollBackground = display.newRect(60, 0, 360, scrollview.height+64)
scrollBackground:setFillColor(0, 0, 255)
scrollview:insert(1, scrollBackground)
scrollview:addScrollBar()
local reorderLayers = function()
menuGroup:insert( menuGroup )
scrollview:toFront()
end
end
drawScreen()
--audio.play( backgroundSound, { channel=1, loops=-1, fadein=5000 } )
unloadMe = function()
--if tapSound then audio.dispose( tapSound ); end
end
-- MUST return a display.newGroup()
return menuGroup
end
Also, any way to control the paragraph alignment of wrappedText string? [import]uid: 14032 topic_id: 8984 reply_id: 308984[/import]
[import]uid: 14032 topic_id: 8984 reply_id: 32782[/import]