-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
display.setDefault( "background", 255, 255, 255 )
local textoptions =
{
text = "text",
x = display.contentWidth * 0.5,
y = display.contentHeight * 0.5,
width = display.contentWidth - 150,
-- font = native.systemFont,
font = "fontfile.ttf",
fontSize = nil,
align = "center"
}
local myText = display.newText( textoptions )
myText:setFillColor( 255, 0, 0 )
local nextButton = display.newImageRect("img.png", 35, 35)
nextButton.x = display.contentWidth - 20
nextButton.y = display.contentHeight / 2
nextButton:addEventListener( "tap", tapListener )
local function tapListener( event )
return true
end
local myButton = display.newImageRect("img1.png", 35, 35)
myButton.x = display.contentWidth * 0.1
myButton.y = display.contentHeight / 2
myButton:addEventListener( "tap", tapListener1 )
local function tapListener1( event )
return true
end
application =
{
content =
{
width = 320,
height = 480,
scale = "letterbox",
}
}
settings =
{
orientation =
{
-- Supported values for orientation:
-- portrait, portraitUpsideDown, landscapeLeft, landscapeRight
default = "portrait",
supported = { "portrait", },
},
--
-- Android section
--
android =
{
usesPermissions =
{
"android.permission.INTERNET",
},
},
--
-- iOS section
--
iphone =
{
xcassets = "Images.xcassets",
plist =
{
UIStatusBarHidden = false,
UILaunchStoryboardName = "LaunchScreen",
},
},
--
-- Plugins section
--
plugins =
{
},
--
-- Project section
--
excludeFiles =
{
-- Exclude unnecessary files for each platform
all = { "Icon.png", "Icon-*dpi.png", "Images.xcassets", },
android = { "LaunchScreen.storyboardc", },
},
}
Error:
21:26:07.020 Solar2D Simulator 2021.3636 (Jan 30 2021 17:51:50)
21:26:07.020
21:26:07.020
21:26:07.020 Copyright © 2009-2021 C o r o n a L a b s I n c .
21:26:07.020 Version: 3.0.0
21:26:07.020 Build: 2021.3636
21:26:07.020 Platform: iPhone / x64 / 10.0 / Intel® HD Graphics 620 / 4.6.0 - Build 26.20.100.7986 / 2021.3636 / en_IN | IN | en_IN | en
21:26:07.020 Loading project from: C:path
21:26:07.020 Project sandbox folder: C:\path/Corona Simulator\Sandbox\mypp-7C87A9713C5E69181379F514EAC80247\Documents
21:26:07.979 ERROR: Runtime error
21:26:07.979 D:\a\corona\corona\platform\resources\init.lua:82: addEventListener: listener cannot be nil: nil
21:26:07.979 stack traceback:
21:26:07.979 [C]: in function ‘error’
21:26:07.979 D:\a\corona\corona\platform\resources\init.lua:82: in function ‘getOrCreateTable’
21:26:07.979 D:\a\corona\corona\platform\resources\init.lua:114: in function ‘addEventListener’
21:26:07.979 D:\a\corona\corona\platform\resources\init.lua:268: in function ‘addEventListener’
21:26:07.979 D:\a\corona\corona\platform\resources\init.lua:430: in function ‘addEventListener’
21:26:07.979 C:\path\main.lua:31: in main chunk
I understand the return true
is incorrect, but that is just to see if it works. When I run just the first button, there is no problem. In the real app, there will be a composer.gotoScene
.
Also, the first button (nextButton
) is visible just where I want it, but the second one (myButton
) just isn’t visible. The text and everything else is perfect.
Where am I going wrong ?
Thank You