Hello,
Has anyone tried to center two line of text without them overlapping each other? It seems as though I have tried everything and no matter what they will not center and one overlaps the other. any ideas what I am doing wrong? [import]uid: 69302 topic_id: 29851 reply_id: 329851[/import]
Well, are you wanting them side by side or one up top and one below?
for top/below I would do something along the lines of:
[lua]myText1.x = display.contentWidth /2;
myText1.y = display.contentHeight /2;
myText2.x = display.contentWidth /2;
myText2.y = myText1.y + myText1.contentHeight /2 + myText2.contentHeight /2;[/lua]
Basically only the way y axis you are using ‘fluid’ UI logic so that your second text object will always appear below text1.
There are a few ways that you could do side by side. Below should work(warning, i am too lazy to test my own code).
[lua]myText1.x = display.contentWidth /2 - myText1.contentWidth /2;
myText2.x = display.contentWidth /2 + myText2.contentWidth / 2;[/lua]
You could do it a little different if you set reference points(http://docs.coronalabs.com/api/type/DisplayObject/setReferencePoint.html) but I usually don’t bother with that.
Oh, as a probably ‘Gotcha’, you may need to run the above code each time you change the text of those objects if you do not define a height/width when you create the initial text object. The reason for this is your textObject width will change if it is not defined. [import]uid: 147305 topic_id: 29851 reply_id: 119701[/import]
Hello budershank, thanks a lot. I am new to lua so when you say mytext1 is that where I put the text I want? if not where would I place the text I want to display? I didn’t mention it,but the first line of my text is just two words and the second part I want is more of a paragraph or better yet a description of my app( with multiple lines). will the example you gave me still work? and yes I would like the text to read one top and one below it. [import]uid: 69302 topic_id: 29851 reply_id: 119747[/import]
The code above was with the intention that you had already created your text objects and were just positioning them. Below would be a more complete example.
[lua]local myText1= display.newText(“you can put text here”, 0, 0, native.systemFont, 12)
myText1.text = “Or you can change the text here”
myText1.x = display.contentWidth /2;
myText1.y = display.contentHeight /2;
myText1:setTextColor(0, 0, 0)
local myText2= display.newText(“you can put text here”, 0, 0,200, 200 native.systemFont, 12)
myText2.text = “Or you can change the text here”
myText2.x = display.contentWidth /2;
myText2.y = myText1.y + myText1.contentHeight /2 + myText2.contentHeight /2;
myText2:setTextColor(0, 0, 0)[/lua]
Since myText2 is going to be your paragraph the size is set to 200x200. Doing this will make auto-word wrap.
[import]uid: 147305 topic_id: 29851 reply_id: 119750[/import]
Thanky you so much dudershank. I will test it out and let you know if it works [import]uid: 69302 topic_id: 29851 reply_id: 119756[/import]
So I tested it out. And it works except for some reason it put it on the second screen not my main screen even though that is where I placed it. Do you know why this is so? [import]uid: 69302 topic_id: 29851 reply_id: 119801[/import]
Well, the text will show up as soon as you run whatever code block it is in. Taking a guess, the text is probably showing up behind other objects and when you switch scenes the other objects are disposed of so your text shows up then. If you are comfortable posting some code that would help. [import]uid: 147305 topic_id: 29851 reply_id: 119813[/import]
Nope actually I put the code in my main.lua file and it shows up in my menu.lua. but I want it displayed in my main.lua file. I just used the example you gave me to test it. but I am pasting everything I have in the main.lua to see if you can see anything. Thanks
– hide the status bar
display.setStatusBar( display.HiddenStatusBar )
– include the Corona “storyboard” module
local storyboard = require “storyboard”
– load menu screen
storyboard.gotoScene( “menu” )
–local background = display.newImage( “Icon.png”, -37,-37)
–local multiText = display.newText( “Have you ever been out enjoying yourself like I have and missed a special occasion because you were busy and forgot to send a Happy Birthday or Happy New Year text message? Well never again, with forgetful memory”, 90, 90, 135, 500 Helvetica, 18 )
–multiText:setTextColor( 255,255,255 )
local myText = display.newText( “About Us”, 0, 0, native.systemFont, 50 )
–myText.x = display.contentWidth / 4
–myText.y = display.contentHeight / 2
myText:setTextColor( 255, 0, 0 )
local myText1= display.newText(“you can put text here”, 0, 0, native.systemFont, 12)
myText1.text = “Or you can change the text here”
myText1.x = display.contentWidth /2;
myText1.y = display.contentHeight /2;
myText1:setTextColor(0, 0, 0)
local myText2= display.newText(“you can put text here”, 0, 0,200, 200, native.systemFont, 12)
myText2.text = “Or you can change the text here”
myText2.x = display.contentWidth /2;
myText2.y = myText1.y + myText1.contentHeight /2 + myText2.contentHeight /2;
myText2:setTextColor(0, 0, 0) [import]uid: 69302 topic_id: 29851 reply_id: 119816[/import]
Oye, not sure how to explain this… also not sure how exactly you want it to display. Basically what’s going on is when the app is run it is going down your code and you move to your menu scene then after that it creates the text objects which sound like they show up in a layer undernearth your menu scene. You don’t have a ‘main’ scene. I think what would help would be to describe what you want to happen when you open the app. Are you wanting it to display your text and then, after a few seconds, move to the menu? [import]uid: 147305 topic_id: 29851 reply_id: 119817[/import]
okay so what I want it to do is when the user click on the app it opens of course and they see a brief about us and at the bottom of the page there is a button and when the user clicks it goes to the menu scene. So I want the text be displayed on the main.lua page then click a button to go to the menu screen. did I make that clear? [import]uid: 69302 topic_id: 29851 reply_id: 119819[/import]
Alright, so what you want to do is not call your storyboard.goto code until a user pushes a button. When the user pushes the button you want to remove both text objects(like myText1:removeSelf()) and then use your storyboard.goto code.
Here is the documentation(with examples) on how to create a button.
http://docs.coronalabs.com/api/library/widget/newButton.html
There is also a semi-recent blog on them that you can search for as well. [import]uid: 147305 topic_id: 29851 reply_id: 119824[/import]
Ok so I am confused. I have a button and it goes to the next screen just as I want it to do. So I am not understanding what is causing the text to overlap versus being one over the top. [import]uid: 69302 topic_id: 29851 reply_id: 119944[/import]
Well, are you wanting them side by side or one up top and one below?
for top/below I would do something along the lines of:
[lua]myText1.x = display.contentWidth /2;
myText1.y = display.contentHeight /2;
myText2.x = display.contentWidth /2;
myText2.y = myText1.y + myText1.contentHeight /2 + myText2.contentHeight /2;[/lua]
Basically only the way y axis you are using ‘fluid’ UI logic so that your second text object will always appear below text1.
There are a few ways that you could do side by side. Below should work(warning, i am too lazy to test my own code).
[lua]myText1.x = display.contentWidth /2 - myText1.contentWidth /2;
myText2.x = display.contentWidth /2 + myText2.contentWidth / 2;[/lua]
You could do it a little different if you set reference points(http://docs.coronalabs.com/api/type/DisplayObject/setReferencePoint.html) but I usually don’t bother with that.
Oh, as a probably ‘Gotcha’, you may need to run the above code each time you change the text of those objects if you do not define a height/width when you create the initial text object. The reason for this is your textObject width will change if it is not defined. [import]uid: 147305 topic_id: 29851 reply_id: 119701[/import]
Hello budershank, thanks a lot. I am new to lua so when you say mytext1 is that where I put the text I want? if not where would I place the text I want to display? I didn’t mention it,but the first line of my text is just two words and the second part I want is more of a paragraph or better yet a description of my app( with multiple lines). will the example you gave me still work? and yes I would like the text to read one top and one below it. [import]uid: 69302 topic_id: 29851 reply_id: 119747[/import]
The code above was with the intention that you had already created your text objects and were just positioning them. Below would be a more complete example.
[lua]local myText1= display.newText(“you can put text here”, 0, 0, native.systemFont, 12)
myText1.text = “Or you can change the text here”
myText1.x = display.contentWidth /2;
myText1.y = display.contentHeight /2;
myText1:setTextColor(0, 0, 0)
local myText2= display.newText(“you can put text here”, 0, 0,200, 200 native.systemFont, 12)
myText2.text = “Or you can change the text here”
myText2.x = display.contentWidth /2;
myText2.y = myText1.y + myText1.contentHeight /2 + myText2.contentHeight /2;
myText2:setTextColor(0, 0, 0)[/lua]
Since myText2 is going to be your paragraph the size is set to 200x200. Doing this will make auto-word wrap.
[import]uid: 147305 topic_id: 29851 reply_id: 119750[/import]
Thanky you so much dudershank. I will test it out and let you know if it works [import]uid: 69302 topic_id: 29851 reply_id: 119756[/import]
So I tested it out. And it works except for some reason it put it on the second screen not my main screen even though that is where I placed it. Do you know why this is so? [import]uid: 69302 topic_id: 29851 reply_id: 119801[/import]
Well, the text will show up as soon as you run whatever code block it is in. Taking a guess, the text is probably showing up behind other objects and when you switch scenes the other objects are disposed of so your text shows up then. If you are comfortable posting some code that would help. [import]uid: 147305 topic_id: 29851 reply_id: 119813[/import]
Nope actually I put the code in my main.lua file and it shows up in my menu.lua. but I want it displayed in my main.lua file. I just used the example you gave me to test it. but I am pasting everything I have in the main.lua to see if you can see anything. Thanks
– hide the status bar
display.setStatusBar( display.HiddenStatusBar )
– include the Corona “storyboard” module
local storyboard = require “storyboard”
– load menu screen
storyboard.gotoScene( “menu” )
–local background = display.newImage( “Icon.png”, -37,-37)
–local multiText = display.newText( “Have you ever been out enjoying yourself like I have and missed a special occasion because you were busy and forgot to send a Happy Birthday or Happy New Year text message? Well never again, with forgetful memory”, 90, 90, 135, 500 Helvetica, 18 )
–multiText:setTextColor( 255,255,255 )
local myText = display.newText( “About Us”, 0, 0, native.systemFont, 50 )
–myText.x = display.contentWidth / 4
–myText.y = display.contentHeight / 2
myText:setTextColor( 255, 0, 0 )
local myText1= display.newText(“you can put text here”, 0, 0, native.systemFont, 12)
myText1.text = “Or you can change the text here”
myText1.x = display.contentWidth /2;
myText1.y = display.contentHeight /2;
myText1:setTextColor(0, 0, 0)
local myText2= display.newText(“you can put text here”, 0, 0,200, 200, native.systemFont, 12)
myText2.text = “Or you can change the text here”
myText2.x = display.contentWidth /2;
myText2.y = myText1.y + myText1.contentHeight /2 + myText2.contentHeight /2;
myText2:setTextColor(0, 0, 0) [import]uid: 69302 topic_id: 29851 reply_id: 119816[/import]
Oye, not sure how to explain this… also not sure how exactly you want it to display. Basically what’s going on is when the app is run it is going down your code and you move to your menu scene then after that it creates the text objects which sound like they show up in a layer undernearth your menu scene. You don’t have a ‘main’ scene. I think what would help would be to describe what you want to happen when you open the app. Are you wanting it to display your text and then, after a few seconds, move to the menu? [import]uid: 147305 topic_id: 29851 reply_id: 119817[/import]