This page has a lot going on. it’s a new player set up screen, scrolls and has text box entries. I am using director.
My one problem is that the scrolling messes with the localGroup:inserts, I have a create button that when clicked will take you to the play game screen, but nothing is removed, when I move the localGroup:inserts after the scrollView:insert, nothing appears here, I figure it’s under the scroll background use the move the screen. What do I have to do to use the localGroup:inserts and scrollView:insert
My other question is about the text input, since it doesn’t test on the simulator I don’t know if the way I have it will even work.
If there is text in the text input boxes will they get applied to the variables how I have them defined here or do I have to add anything to the create button? Luckly this is the only input I will have in the whole game. I will have a lot of buttons and scrollers though,
[code]
module(…, package.seeall)
new = function ()
– Groups
local localGroup = display.newGroup()
– Your code here
–import the scrolling classes
local scrollView = require(“scrollView”)
local util = require(“util”)
local ui = require(“ui”)
require(“hijacks”)
local tHeight
local background = display.newRect(0, 0, display.contentWidth, display.contentHeight)
background:setFillColor(255, 255, 255)
localGroup:insert(background)
– Setup a scrollable content group
local topBoundary = display.screenOriginY
local bottomBoundary = display.screenOriginY
local scrollView = scrollView.new{ top=topBoundary, bottom=bottomBoundary }
local function fieldHandler( event )
if ( “began” == event.phase ) then
– This is the “keyboard has appeared” event
– In some cases you may want to adjust the interface when the keyboard appears.
elseif ( “ended” == event.phase ) then
– This event is called when the user stops editing a field: for example, when they touch a different field
elseif ( “submitted” == event.phase ) then
– This event occurs when the user presses the “return” key (if available) on the onscreen keyboard
– Hide keyboard
native.setKeyboardFocus( nil )
end
end
– *** Create native input textfields ***
– Note: currently this feature works in device builds or Xcode simulator builds only
– Note: currently this feature works in device builds only
local isAndroid = “Android” == system.getInfo(“platformName”)
local inputFontSize = 18
local inputFontHeight = 30
tHeight = 30
if isAndroid then
– Android text fields have more chrome. It’s either make them bigger, or make the font smaller.
– We’ll do both
inputFontSize = 14
inputFontHeight = 42
tHeight = 40
end
– *** InPUT fields labels ***
usernameField = native.newTextField( 10, 70, 180, tHeight, fieldHandler )
usernameField.font = native.newFont( native.systemFontBold, inputFontSize )
usernameField.inputType = “username”
usernameField.x = 105
usernameField.y = 260
scrollView:insert(usernameField)
passwordField = native.newTextField( 10, 230, 180, tHeight, fieldHandler )
passwordField.font = native.newFont( native.systemFontBold, inputFontSize )
passwordField.inputType = “password”
passwordField.isSecure = true
passwordField.x = 105
passwordField.y = 320
scrollView:insert(passwordField)
local UsernameLabel = display.newText( “Username”, 200, 35, native.systemFont, 18 )
UsernameLabel:setTextColor( 0, 0, 0 )
UsernameLabel.x = 255
UsernameLabel.y = 260
scrollView:insert(UsernameLabel)
local PasswordLabel = display.newText( “Password”, 200, 235, native.systemFont, 18 )
PasswordLabel:setTextColor( 0, 0, 0)
PasswordLabel.x = 255
PasswordLabel.y = 320
scrollView:insert(PasswordLabel)
– *** END Add field labels ***
sexMale = display.newText( “Male”, 200, 35, native.systemFont, 12 )
sexMale:setTextColor( 0, 0, 0 )
sexMale.x = 70
sexMale.y = 80
scrollView:insert(sexMale)
sexFemale = display.newText( “Female”, 200, 35, native.systemFont, 12 )
sexFemale:setTextColor( 0, 0, 0 )
sexFemale.x = 210
sexFemale.y = 80
scrollView:insert(sexFemale)
local setupText = display.newText("", 0, 0, native.systemFontBold, 10)
setupText.x = 75
setupText.y = 40
setupText:setTextColor(0, 0, 0)
localGroup:insert(setupText)
setupText.text = “bldj wsjwjf wjrjfg iwj ig wiroaf”
scrollView:insert(setupText)
local PlayerImageHeight=160
– Sets the create the player
local playerMaleImage = display.newImage (“images/male.png”)
playerMaleImage.x = 75
playerMaleImage.y = PlayerImageHeight
localGroup:insert(playerMaleImage)
scrollView:insert(playerMaleImage)
local playerFemaleImage = display.newImage (“images/female.png”)
playerFemaleImage.x = 199
playerFemaleImage.y = PlayerImageHeight
localGroup:insert(playerFemaleImage)
scrollView:insert(playerFemaleImage)
local listener = function( event )
– Hide keyboard
print(“tap pressed”)
native.setKeyboardFocus( nil )
end
– Determine if running on Corona Simulator
local isSimulator = “simulator” == system.getInfo(“environment”)
– Native Text Fields not supported on Simulator
if isSimulator then
msg = display.newText( “Native Text Fields not supported on Simulator!”, 0, 280, “Verdana-Bold”, 12 )
msg.x = display.contentWidth/2 – center title
msg:setTextColor( 255,255,0 )
localGroup:insert(msg)
end
– Add listener to background for user “tap”
background:addEventListener( “tap”, listener )
–=============SO Button
local ButtonHeight=400
local createPlayerBut = display.newImage (“images/Button.png”)
createPlayerBut.x = 75
createPlayerBut.y = ButtonHeight
localGroup:insert(createPlayerBut)
scrollView:insert(createPlayerBut)
local createPlayerText = display.newText("", 0, 0, native.systemFontBold, 17)
createPlayerText.x = 80
createPlayerText.y = ButtonHeight
createPlayerText:setTextColor(0, 0, 0)
localGroup:insert(createPlayerText)
createPlayerText.text = “Create Player”
scrollView:insert(createPlayerText)
local function createPlayer (event)
director:changeScene(“play”)
end
createPlayerBut:addEventListener(“touch”, createPlayer)
–============= EO Button
– Important! Add a background to the scroll view for a proper hit area
local scrollBackground = display.newRect(0, 0, display.contentWidth, scrollView.height+64)
scrollBackground:setFillColor(0, 255, 0)
localGroup:insert(scrollBackground)
scrollView:insert(1, scrollBackground)
scrollView:addScrollBar()
– MUST return a display.newGroup()
return localGroup
end
[/code] [import]uid: 78446 topic_id: 13100 reply_id: 313100[/import]