Step 2

Step2

Make sure you enable Key Navigation in General of Project Properties. It enables InputDevice API (keyboard, game controller etc). It is available in Kwik 4.0.7

Overview.

By last chapter “Step1”, a simple app has been created. Let’s add InputDevice navigation, Controllers list on page3 and key assigment table on page4

page1

page2

setting(page3)

setup(page4)

each page needs an external code for button navigation. Set the button layer names

for page1

kInputDevices:setButton(layer.btn1)
kInputDevices:setButton(layer.btn2)
kInputDevices:setButton(layer.Settings)
kInputDevices:setButton(layer.NaviBtn)

page2, the sentence of ‘read to me’ comes with the following code

kInputDevices:setReadmeSentence(layer.b_helloEn, true)
-- true for each word, false speaker icon only

Be aware helloEn layer has prefix ‘ b_ ‘. It is an identification of multi language layer

page3 shows the list of controllers connected. Use controllersTableUI.lua

controllersTable:init(sceneGroup, layer.Rect1.x, layer.Rect1.y,layer.Rect1.width, layer.Rect1.height )
controllersTable:close()

page4 shows and edits the key assignment of controllers. Use

keyAssignTableUI.lua

keyAssignTable:willShow()
keyAssignTable:init(sceneGroup, layer.Rect1.x, layer.Rect1.y+100,layer.Rect1.width, layer.Rect1.height)
keyAssignTable:willHide()
keyAssignTable:didHide()

extlib/tv

you can find the following lua files in extlib/tv folder if you want to customize the look&feel * controllersTable * extlib/tv/controllersTableUI.lua





you also find kOnkeyListener.lua that is the core module to handle key or joystick axis event for navigating buttons and currently supports 2-way direction(up or down) only.

To change the color or text font, edit the lua codes in controllersTableUI.lua or keyAssignTableUI.lua.

local _headerColor     = { 0.42, 0.42, 0.42, 0.9 }
local _headerLabel     = "current controllers"
local _backgroundColor = { 0.8, 0.8, 0.8, 0.3 }
local _rowColor        = { 1, 1, 1, 0.05 }
local _fontSize        = 20*768/320*2
local _rowHeight       = 50*768/320

External codes

Add the following external code to each page. kwik panel > Project Page > Add External Code.

page1

After buttons and actions * assets/extCode/page_1_buttons.lua

kInputDevices:setButton(layer.btn1)
kInputDevices:setButton(layer.btn2)
kInputDevices:setButton(layer.Settings)
kInputDevices:setButton(layer.NaviBtn)

page2

After buttons and actions * assets/extCode/page_2_buttons.lua

kInputDevices:setReadmeSentence(layer.b_helloEn, true) 
-- true for each word, false speaker icon only

kInputDevices:setButton(layer.layer.Kwik_Icon_276_2)
kInputDevices:setButton(layer.backEn)

See sample project file for Kwik_Icon. It has set as physics body

settings

After buttons and actions * assets/extCode/page_3_buttons.lua * assets/extCode/page_3_table_init.lua

kInputDevices:setButton(layer.Back)
kInputDevices:setButton(layer.languages)
kInputDevices:setButton(layer.controllers)
kInputDevices:setButton(layer.keyAssign)

Disposal * assets/extCode/page_3_table_close.lua

controllersTable:close()

settings - language and controller button

button “language” action * assets/extCode/page_3_lang.lua

kInputDevices:setButton(layer.enBtn)
kInputDevices:setButton(layer.jpBtn)

hiding the table * assets/extCode/page_3_table_hide.lua

controllersTable:setAlpha(0)

button “controllers” action * assets/extCode/page_3_table_show.lua

controllersTable:setAlpha(1)

setup

After buttons and actions * assets/extCode/page_4_buttons.lua

kInputDevices:setButton(layer.Back)
kInputDevices:setButton(layer.Edit)

initiating the table * assets/extCode/page_4_table_init.lua

keyAssignTable:willShow()
if keyAssignTable:init(sceneGroup, layer.Rect1.x, layer.Rect1.y+100,layer.Rect1.width, layer.Rect1.height) then
  print("")
  keyAssignTable:didShow()
else
  kInputDevices:setButton(layer.Back)
  kInputDevices:setButton(layer.Edit)
end

Disposal * assets/extCode/page_4_table_close.lua

  keyAssignTable:willHide()
  keyAssignTable:didHide()

setup - edit button

button “Edit” * assets/extCode/page_4_table_edit.lua


Icons and Launch images etc

Copy these png files to ./build folders

android(FireTV) - assets/tvAsset/Default-Landscape-assets/Default-Landscape.png - assets/tvAsset/tvosLaunch-assets/Banner-xhdpi.png

tvos(appleTV) - assets/tvAsset/tvosLaunch-assets/Icon-tvOS-Launch.png - assets/tvAsset/tvosLaunch-assets/Icon-tvOS-TopShelf.png

Windows

OSX

Done. Publish and Build for device with Corona Simulator.