-
Notifications
You must be signed in to change notification settings - Fork 0
/
layoutTool.lua
54 lines (40 loc) · 1.67 KB
/
layoutTool.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-----------------------------------------------------------------------------------------
--
-- layoutTool.lua
--
-- This is a developer tool for the Mars app that just displays the (x, y) coordinates
-- of touch locations within the shipPlan map image.
-----------------------------------------------------------------------------------------
-- Get local reference to the game globals
local game = globalGame
-- Create the act object
local act = game.newAct()
------------------------- Start of Activity --------------------------------
-- Act variables
local shipGroup -- display group centered on ship
local coordText -- display object for coordinate display
-- Handle touch event on the map
local function touchMap( event )
-- Get tap position in shipGroup coords and display in coordText
local x, y = shipGroup:contentToLocal( event.x, event.y )
coordText.text = string.format( "(%d, %d)", x, y )
return true
end
-- Init the act
function act:init()
-- Display group for ship elements (centered on ship)
shipGroup = act:newGroup()
shipGroup.x = act.xCenter
shipGroup.y = act.yCenter
-- Map background with touch listener
local map = act:newImage( "shipPlan2.png", { folder = "media/mainAct", parent = shipGroup, width = act.width, x = 0, y = 0 } )
map:addEventListener( "touch", touchMap )
-- Text display for coordinates
coordText = display.newText( act.group, "", act.xMin + 2, act.yMin + 15, native.systemFont, 16 )
coordText.anchorX = 0
coordText.anchorY = 0
coordText:setFillColor( 1 ) -- white
end
------------------------- End of Activity --------------------------------
-- Corona needs the scene object returned from the act file
return act.scene