2014-03-13 3 views
2

화면에 새 개체를 생성하는 클래스를 만들려고합니다. 이건 내 클래스입니다코로나 SDK가있는 모듈 식 클래스

local box = box.new("First", 0, 62) -- Spawn a Box on the Screen on X = 0, Y = 62 

: 나는

내 목표 this tutorial을 다음 있어요 뭔가 연결이 수행했다 단지 level1.lua에 require ("box")을 수행하여 지금까지

box.lua 

local box = {} 
local box_mt = {__index = box } -- metatable 

function box.new (nome, x, y) 
    local newbox = { 
     local nome = display.newImageRect("images/box.png", 210, 70) 
     newbox.x = x 
     newbox.y = y 
    } 
    return setmetatable(newbox, box_mt) 
} 
end 

을 내 게임이 충돌합니다

This is the error 
Failed to parse error message: error loading module 'level1' from file '/Users/mc309bza/Desktop/Corona/Platform/level1.lua': 
    /Users/mc309bza/Desktop/Corona/Platform/level1.lua:28: syntax error near 'function' 

아이디어가 있습니까? 감사!

+0

28 행은 무엇입니까? – lhf

+0

또한'local nome ='은 구문 오류입니다. 로컬 테이블 필드가 없습니다. – lhf

답변

0

테이블 닫는 괄호는 잘못된 위치에 있습니다. 사용

local newbox = {} 
local nome = display.newImageRect("images/box.png", 210, 70) 
newbox.x = x 
newbox.y = y 

당신이 newbox 후이 가까운 }를 제거하는 것을 잊지 마십시오. 그러나 자동화 된 상자를 만들려는 의도가 있다면 display.newImageRect가 이미 클래스이므로 함수를 대신 사용해야합니다. 함수를 사용하십시오 :

function myNewBox(x, y) 
    local nome = display.newImageRect("images/box.png", 210, 70) 
    nome.x = x 
    nome.y = y 
    ... other nome settings ... 
    return nome 
end