Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

how to move between scenes inside a scroll view
Started by milestudios73 Oct 29 2019 06:31 AM

9 replies to this topic
scenes corona is awesome love the forum support

Best Answer XeduR @Spyric , 01 November 2019 - 03:29 AM

@milestudios73, I couldn't agree more with Nick.

Your questions seem to be the type that could be and would be answered by simply typing them to google. You need to take some initiative yourself when you are learning to a new programming language. If you just ask the forums for every little thing, you are only hindering your own development as a programmer.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

milestudios73

[GLOBAL: userInfoPane.html]
milestudios73
  • Observer

  • 9 posts
  • Corona SDK

followed the tut about managing large blocks of text and it worked out pretty fine thanks to all the help i got now i have another problem

1.i cant display a custom background i.e putting my own background colour since i think the white one is eye straining

2. i cant call other functions like changing the scene (back to the main menu perhaps)

 

any and all help is greatly appreciated!!!!



[TOPIC: post.html]
#2

veracode

[GLOBAL: userInfoPane.html]
veracode
  • Enthusiast

  • 37 posts
  • Corona SDK

i'm not sure if i can help as i'm pretty new to corona but without seeing your code its tough to try and help.


  • pixec likes this

[TOPIC: post.html]
#3

milestudios73

[GLOBAL: userInfoPane.html]
milestudios73
  • Observer

  • 9 posts
  • Corona SDK

here is my code


local composer = require( "composer" )

local scene = composer.newScene()

-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------

local myText = [[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque semper mollis erat a interdum. Praesent tristique diam in nulla varius, nec aliquet mauris posuere. Suspendisse pretium risus lacus, commodo lacinia sapien dictum et. Sed non varius felis. Curabitur elementum tortor non libero pulvinar, at convallis lectus varius. Interdum et malesuada fames ac ante ipsum primis in faucibus. Curabitur sit amet nunc congue, molestie erat vel, facilisis turpis. Morbi vitae diam ligula. Suspendisse purus turpis, commodo in aliquam id, lobortis a sapien. Sed at libero porta, aliquam odio nec, porta dui. In a congue velit. Aliquam ac quam feugiat, ultricies metus nec, porta neque. Phasellus posuere mollis magna, ac vestibulum ligula congue id. Pellentesque imperdiet aliquam lacus, ac pellentesque dui eleifend nec. Suspendisse auctor vehicula facilisis. Pellentesque id massa tincidunt neque luctus varius.
 
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas sit amet dapibus nulla. Suspendisse ut risus nulla. Maecenas varius elit non faucibus fermentum. Fusce rhoncus, nisl et varius tristique, enim felis egestas purus, et feugiat lorem urna a augue. Maecenas non pulvinar tortor. Aenean condimentum nibh id eros fringilla viverra. Fusce condimentum urna ut volutpat porttitor. Nunc tincidunt congue ligula.
 
Duis placerat felis varius, convallis massa sed, volutpat magna. Sed vitae viverra neque. Integer ac sollicitudin libero, at ornare purus. Aliquam egestas hendrerit tellus. Aliquam eu elit vitae lorem lacinia tempus. Proin vel dictum mi. Maecenas porttitor, justo a dictum volutpat, nisl libero dictum ligula, vitae posuere urna elit a quam. Nam arcu metus, semper suscipit pellentesque ac, tempor ut arcu. Vestibulum eu nibh erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed semper sollicitudin lorem, vel commodo libero commodo eget. Proin lacinia euismod elit vitae porttitor. Proin ipsum neque, dictum at dictum eu, egestas malesuada turpis. Nulla eros lectus, adipiscing eget velit sed, malesuada aliquam ipsum. Curabitur et egestas massa. Vestibulum luctus est est, tincidunt viverra nisi vulputate id.
 
Integer lobortis tellus eu ligula viverra egestas. Quisque commodo, massa vel pretium imperdiet, nisl enim euismod justo, sed ultricies lacus mi ut nisi. Maecenas molestie vitae magna non interdum. In gravida ornare orci in vulputate. Praesent suscipit lobortis dui ut interdum. Proin pulvinar metus ligula, a malesuada nunc interdum at. Aenean et scelerisque enim. Integer eget congue sapien. Etiam suscipit mauris neque, id semper quam volutpat vel. Proin venenatis dictum felis quis ultricies. Suspendisse feugiat mi congue ante gravida, id accumsan leo mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In hac habitasse platea dictumst. Nulla facilisi.
 
Nam arcu mauris, convallis sit amet dictum consequat, imperdiet at mi. Vestibulum velit erat, accumsan sit amet vehicula vitae, tempor id nisi. Quisque eu tellus vulputate nisi vestibulum tincidunt at vitae tellus. Quisque sed pretium nisl. Vivamus a aliquet purus. Integer pulvinar neque in dapibus pharetra. Quisque convallis urna vulputate ligula mattis dictum. Vivamus pharetra molestie nunc, ac rhoncus dolor euismod at. Cras fringilla sollicitudin sapien vel sagittis. Donec dignissim scelerisque mi nec pulvinar. Mauris at metus gravida, lacinia dolor quis, vehicula lacus. Donec a pellentesque tellus. Praesent sit amet lorem nisl. Pellentesque interdum felis quis vehicula vestibulum. Donec ut dolor tortor.
]]


local widget = require( "widget" )
 




-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------

-- create()
function scene:create( event )

	local sceneGroup = self.view
	-- Code here runs when the scene is first created but has not yet appeared on screen

	local scrollView = widget.newScrollView(
{
    top = 0,
    left = 0,
    width = display.contentWidth,
    height = display.contentHeight,
    horizontalScrollDisabled = true
})
 
local paragraphs = {}
local paragraph
local tmpString = myText
 
local yStart = 10
local mainPadding = 20





	repeat
    paragraph, tmpString = string.match ( tmpString, "([^\n]*)\n(.*)" )
    paragraphs[#paragraphs+1] = display.newText( { text=paragraph, width=scrollView.width-(mainPadding*2), fontSize=14 } )
    paragraphs[#paragraphs].anchorX = 0
    paragraphs[#paragraphs].anchorY = 0
    paragraphs[#paragraphs].x = mainPadding
    paragraphs[#paragraphs].y = yStart
    paragraphs[#paragraphs]:setFillColor( 0 )
    scrollView:insert( paragraphs[#paragraphs] )
    yStart = yStart + paragraphs[#paragraphs].height
until tmpString == nil or string.len( tmpString ) == 0

scrollView:setScrollHeight( scrollView:getView().height + (mainPadding*2) )

end


-- show()
function scene:show( event )

	local sceneGroup = self.view
	local phase = event.phase

	if ( phase == "will" ) then
		-- Code here runs when the scene is still off screen (but is about to come on screen)

	elseif ( phase == "did" ) then
		-- Code here runs when the scene is entirely on screen

	end
end


-- hide()
function scene:hide( event )

	local sceneGroup = self.view
	local phase = event.phase

	if ( phase == "will" ) then
		-- Code here runs when the scene is on screen (but is about to go off screen)

	elseif ( phase == "did" ) then
		-- Code here runs immediately after the scene goes entirely off screen

	end
end


-- destroy()
function scene:destroy( event )

	local sceneGroup = self.view
	-- Code here runs prior to the removal of scene's view

end


-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------

return scene

i tried adding a bg pic but it only display a small rectangle in the top any help??



[TOPIC: post.html]
#4

OlinaChang

[GLOBAL: userInfoPane.html]
OlinaChang
  • Observer

  • 22 posts
  • Corona SDK

Hi there,

Although I am entry level too, your code looks odd for me. Do you code with Lua??
After I pasted your code in Visual Studio Code, problem is obvious. Maybe you want to try a better coding software?
y2DoCIT.png
double brackets are making block commands, so here you are not assign anything to myText variable.

Next, I don't see you set up any background. You will have to create a display object with display.newImageRect.

Finally, I am not familiar with repeat function, but it's OK. At least I know, if you create a function, you might want to call/run/execute it somewhere. In this case, in order to make the widget working, you might want to call the function inside the create scene area.

Hope this helps.



[TOPIC: post.html]
#5

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 981 posts
  • Corona SDK

Actually, using those brackets is completely fine.

 

For instance,

local chunkOfText = [[This is so much text and
so poorly formatted
that
I just chose to use these brackets]]

local object = display.newText( chunkOfText, display.contentCenterX, display.contentCenterY, native.systemFontBold, 40 )

If you enter the code inside those brackets, then it will take the line breaks and such as is and it will be perfectly displayed on the screen. There's no issue with that part of @milestudios73's code.


  • OlinaChang likes this

[TOPIC: post.html]
#6

OlinaChang

[GLOBAL: userInfoPane.html]
OlinaChang
  • Observer

  • 22 posts
  • Corona SDK

Oops! You are right. I just tried your post. Sorry about it.



[TOPIC: post.html]
#7

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 981 posts
  • Corona SDK

@milestudios73

 

When you say you want to change the background, if all you need is to change the background colour from single colour to another, you can simply do:

display.setDefault( "background", 0.5 )

If you wish to add an image to the background or add a rectangle with a gradient or texture fill, then check out the docs.

 

-

 

Now, when you say that you can't call other functions, what do you mean exactly? Your code doesn't have any other functions in it, i.e. you aren't doing anything apart from creating that scroll view.

 

If your problem is with creating functions in general, then you should refer to Corona's getting started tutorials: https://docs.coronalabs.com/guide/programming/index.html

 

If all you need is a way yo move from that scene to the previous one, then you could create a button and add a simple touch event where if the button is touched, you go to the previous scene. For how buttons and touch listeners work, see https://docs.coronalabs.com/api/library/widget/newButton.html#default.



[TOPIC: post.html]
#8

milestudios73

[GLOBAL: userInfoPane.html]
milestudios73
  • Observer

  • 9 posts
  • Corona SDK

OK thanks but is it possible to add an event listener on the back buttons of an android device too because every time i press the back button on my phone the app closes



[TOPIC: post.html]
#9

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,861 posts
  • Corona SDK

https://lmgtfy.com/?q=corona+android+back+button&pp=1&s=g&t=w



[TOPIC: post.html]
#10

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 981 posts
  • Corona SDK

  Best Answer

@milestudios73, I couldn't agree more with Nick.

Your questions seem to be the type that could be and would be answered by simply typing them to google. You need to take some initiative yourself when you are learning to a new programming language. If you just ask the forums for every little thing, you are only hindering your own development as a programmer.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: scenes, corona is awesome, love the forum support