Hello
You probably want to simplify and clean your code, so you need to make files like “main.lua” and “menu.lua” for your game and interface
put this to your main.lua:
[lua]local menu = require(“menu”) – We call our menu.lua file
local physics = require(“physics”) – We call physics to use in this file
physics.start() --Start gravity
physics.setGravity(0,10) – Set X and Y of gravity force
_W = display.contentWidth – Declare variable to store display.contentWidth
_H = display.contentHeight – Same
local ball = display.newCircle(0,0,30) – We create ball with radius 30
ball.x = _W/2; ball.y = -50 – Allight it to X and Y
physics.addBody(ball, “dynamic”) – Make it respont to physics
local function show_menu() – We make function, that will fire upon given circumstances
if ball.y >= _H then – if ball.y fall of screen bounds then
print(“off”) – this for debug
ball:removeSelf() – Ball will remove itself
menu.show_menu() – We call menu.lua with menu. and then write what function we want
end
end
timer.performWithDelay(1000, show_menu, 0) – Set a system timer that will monitor
– our show_menu every second, 0 is infinity times[/lua]
and this to menu.lua:
[lua]module(…, package.seeall)
_W = display.contentWidth
_H = display.contentHeight
local group = display.newGroup() – We create a group that will store our Rect and Button
group.alpha = 0 – this will make group invisible, but its still present on screen
group.x = _W/2 - 100
group.y = _H + 100
local menu = display.newRect(0,0,150,200) – Rect for our menu, its simply white
group:insert(menu) – We insert menu into the group
local button = display.newText(“BUTTON”, 30, 70, native.systemFont,20) – Make some button into menu
button:setTextColor(255,0,0) – make it red
group:insert(button)
local function touch_button(event) – We create touch event, you can call it everything you want
if event.phase == “ended” then – if event ended than what will fire?
print(“button touched”) – for debug, you can make it everything you need
end
end
button:addEventListener(“touch”, touch_button) – We added listener to button, so we can use it now
function show_menu() – Make function to show menu
transition.to(group, {time=2000, x = _W/2-100, y = _H/2, alpha = 1}) – This will transit group to given coordinates
–and make it visible with alpha=0, time=2000 is 2 seconds
print(“menu show”)
end[/lua]
this will give you example of physics, functions and transitions
good luck [import]uid: 16142 topic_id: 12340 reply_id: 45634[/import]