Hi Richar9,
Thank you for your reply.
This is not working…i have a error in the corona simulator :
File: ERROR
ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: in function ‘insert’
?: in function ‘insert’
main.lua:74: in main chunk
Here is the code for option 1 ( i named my images “image01.png, image02.png”):
display.setStatusBar( display.HiddenStatusBar ) local backok = display.newImageRect( "bg.jpg", 360, 570 ) backok.x = display.contentCenterX backok.y = display.contentCenterY local backslide = display.newRect( 0, 396, 0, 173 ) backslide:setFillColor( .365, .808, .773 ) backslide.anchorY = 1 backslide.width = display.contentWidth backslide.x = display.contentCenterX backslide.y = display.actualContentHeight + display.screenOriginY local widget = require( "widget" ) -- Our ScrollView listener local function scrollListener( event ) local phase = event.phase local direction = event.direction if "began" == phase then --print( "Began" ) elseif "moved" == phase then --print( "Moved" ) elseif "ended" == phase then --print( "Ended" ) end -- If the scrollView has reached it's scroll limit if event.limitReached then if "up" == direction then print( "Reached Top Limit" ) elseif "down" == direction then print( "Reached Bottom Limit" ) elseif "left" == direction then print( "Reached Left Limit" ) elseif "right" == direction then print( "Reached Right Limit" ) end end return true end -- Create a ScrollView local scrollView = widget.newScrollView { left = 0, top = -25, width = display.contentWidth, height = display.contentHeight, bottomPadding = 0, id = "onBottom", horizontalScrollDisabled = false, verticalScrollDisabled = true, listener = scrollListener, hideBackground = true, } --Create a Rectangle local xPos = 50 -- this is the first rectangle position local yPos = 0 -- this is the yPosition of all your rectangles for i = 1, 10 do -- you have 9 rectangles, so this means to the stuff inside 9 times -- This rectangle is local, so "myRectangle" doesn't exist outside this loop. -- instead, the rects would be scrollView[1], scrollView[2], etc. -- The (optional) first argument of any display object is the parentgroup, so you -- can save using the :insert() command later. local myRectangle = display.newImageRect(scrollView, "image"..i, 91, 122) scrollView:insert( myRectangle ) myRectangle:setFillColor(1, 0.2, 0.2) myRectangle.anchorY = 1 myRectangle.y = display.actualContentHeight + display.screenOriginY -- Now you need to increment the xPos so each rectangle is not on the same spot xPos = xPos + 100 end local groupslide = display.newGroup() groupslide:insert( backslide ) groupslide:insert( scrollView ) groupslide.alpha = 0 local myRoundedRect = display.newRoundedRect( 150, 150, 100, 50, 12 ) myRoundedRect.strokeWidth = 3 myRoundedRect:setFillColor( 0.5 ) myRoundedRect:setStrokeColor( 1, 0, 0 )
And for option 2 :
File: ERROR
ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: in function ‘insert’
?: in function ‘insert’
main.lua:78: in main chunk
display.setStatusBar( display.HiddenStatusBar ) local backok = display.newImageRect( "bg.jpg", 360, 570 ) backok.x = display.contentCenterX backok.y = display.contentCenterY local backslide = display.newRect( 0, 396, 0, 173 ) backslide:setFillColor( .365, .808, .773 ) backslide.anchorY = 1 backslide.width = display.contentWidth backslide.x = display.contentCenterX backslide.y = display.actualContentHeight + display.screenOriginY local widget = require( "widget" ) -- Our ScrollView listener local function scrollListener( event ) local phase = event.phase local direction = event.direction if "began" == phase then --print( "Began" ) elseif "moved" == phase then --print( "Moved" ) elseif "ended" == phase then --print( "Ended" ) end -- If the scrollView has reached it's scroll limit if event.limitReached then if "up" == direction then print( "Reached Top Limit" ) elseif "down" == direction then print( "Reached Bottom Limit" ) elseif "left" == direction then print( "Reached Left Limit" ) elseif "right" == direction then print( "Reached Right Limit" ) end end return true end -- Create a ScrollView local scrollView = widget.newScrollView { left = 0, top = -25, width = display.contentWidth, height = display.contentHeight, bottomPadding = 0, id = "onBottom", horizontalScrollDisabled = false, verticalScrollDisabled = true, listener = scrollListener, hideBackground = true, } local images = {} images[1] = "image01.png" images[2] = "image02.png" images[3] = "image03.png" --Create a Rectangle local xPos = 50 -- this is the first rectangle position local yPos = 0 -- this is the yPosition of all your rectangles for i = 1, 10 do -- you have 9 rectangles, so this means to the stuff inside 9 times -- This rectangle is local, so "myRectangle" doesn't exist outside this loop. -- instead, the rects would be scrollView[1], scrollView[2], etc. -- The (optional) first argument of any display object is the parentgroup, so you -- can save using the :insert() command later. local myRectangle = display.newImageRect(scrollView, images[i], 91, 122) scrollView:insert( myRectangle ) myRectangle:setFillColor(1, 0.2, 0.2) myRectangle.anchorY = 1 myRectangle.y = display.actualContentHeight + display.screenOriginY -- Now you need to increment the xPos so each rectangle is not on the same spot xPos = xPos + 100 end local groupslide = display.newGroup() groupslide:insert( backslide ) groupslide:insert( scrollView ) groupslide.alpha = 0 local myRoundedRect = display.newRoundedRect( 150, 150, 100, 50, 12 ) myRoundedRect.strokeWidth = 3 myRoundedRect:setFillColor( 0.5 ) myRoundedRect:setStrokeColor( 1, 0, 0 )
Thank you for your time.