0
누구나 코나에 대한이 루아 코드의 논리 결함을 볼 수 있습니까?Corona SDK 표시 그룹 문제 -이 코드의 오류는 어디에 있습니까?
개념은 새로운 "확장 된"표시 객체 (예 : MyGroup : new (...))를 작성한 다음 부모의 위치에 대한 백분율을 사용하여이 객체에 삽입 할 수 있습니다. 픽셀 수를 사용하십시오).
문제 - 문제는 그려지는 물체가 대략적인 지점에 있지만 대략 조금 밖에 나오지 않습니다. 나는 그것이 아마도 "self : insert (displayO)"라인의 부모에서 바뀌는 좌표로 인한 것이라고 생각합니다.
main.lua
------------------------------------------------------------------------------
-- HELPERS
------------------------------------------------------------------------------
function rpadString (str, len, char)
if char == nil then char = ' ' end
return (str .. string.rep(char, len - #str))
end
function drawBorder(obj)
local b = obj.contentBounds
local myRectangle = display.newRect(b.xMin, b.yMin, obj.contentWidth, obj.contentHeight)
-- print ("Rect X,Y,Width,Height: ", b.xMin, b.yMin, obj.contentWidth, obj.contentHeight)
myRectangle.strokeWidth = 1
myRectangle:setFillColor(140, 140, 140, 1)
if obj.gcGroupName then
-- Group
myRectangle:setStrokeColor(100, 250, 180)
myRectangle.strokeWidth = 1
else
-- Image/Rect
myRectangle:setStrokeColor(250, 180, 180)
myRectangle.strokeWidth = 2
end
end
function dumpDisplayObjects(doParent, level)
drawBorder(doParent)
if doParent.numChildren then
for i=doParent.numChildren,1,-1 do
local doChild = doParent[i]
dumpDisplayObjects(doChild, level + 1)
end
end
end
------------------------------------------------------------------------------
-- MAIN
------------------------------------------------------------------------------
require "MyGroup"
print "RUNNING ........................................."
display.setStatusBar(display.HiddenStatusBar)
-- Create Toolbar Area at Bottom
local mainGroup = MyGroup:new("Main Group", 0, 0, display.contentWidth, display.contentHeight)
local toolbarArea = MyGroup:new("Inventory", 0,0,0,0)
mainGroup:GcInsertLRTB(toolbarArea, 0, 100, 80, 100, "Inventory") -- Percentages Used
-- Draw Rectangle 1
local toolbarAreaImage = display.newImage("toolbarArea_button.png", 0, 0)
toolbarArea:GcInsertLRTB(toolbarAreaImage, 0, 20, 0, 100, "Inventory Button")
-- -- Setup Toolbar Group
-- local toolbarAreaToolbar = MyGroup:new("InventoryToolbar", 0, 0, 1, 1)
-- toolbarArea:GcInsertLRTB(toolbarAreaToolbar, 20, 100, 0, 100, "Toolbar")
-- --
-- -- Draw Rectangle 2
-- local rect2 = display.newRoundedRect(0, 0, 1000, 1000, 5)
-- rect2.strokeWidth = 1
-- rect2:setStrokeColor(140, 140, 140)
-- rect2:setFillColor(140, 140, 140, 100)
-- toolbarAreaToolbar:GcInsertLRTB(rect2, 0, 100, 0, 100, "Rect2")
-- Debug Display
dumpDisplayObjects(toolbarArea, 1)
MyGroup.lua
MyGroup = {}
function MyGroup:new(name, left, top, targetWidth, targetHeight)
-- Inherit from Group
myGroup = display.newGroup()
-- Work Around (Dummy Display Object Insertion) (See Note 1)
myGroup.dummyDO = display.newCircle(myGroup, 10, 10, 1)
myGroup.dummyDO:setFillColor(1,1,1,1)
myGroup.dummyDO.debugComment = "Dummy Display Object"
myGroup:insert(myGroup.dummyDO)
myGroup.myGroupName = name
myGroup.debugComment = name
myGroup.targetWidth = targetWidth
myGroup.targetHeight = targetHeight
myGroup.x = left
myGroup.y = top
function myGroup:GcInsertLRTB(displayO, leftP, rightP, topP, bottomP, debugComment)
self:insert(displayO) -- <=== DOES THIS UPSET THINGS FOR THE PARENT???
-- Remove Work Around Dummy Display Object (See Note 1)
if self.dummyDO then
self.dummyDO:removeSelf()
self.dummyDO = nil
end
displayO:setReferencePoint(display.TopLeftReferencePoint)
displayO.x = leftP * 0.01 * self.targetWidth
displayO.y = (topP * 0.01) * self.targetHeight
-- Scale Display Object (or set target's if adding another MyGroup)
if not displayO.myGroupName then
-- Not a MyGroup
local xScale = (self.targetWidth * (rightP - leftP)/100)/displayO.width
local yScale = (self.targetHeight * (bottomP - topP)/100)/displayO.height
displayO:scale(xScale, yScale)
else
-- Inserted object is a MyGroup
displayO.targetWidth = self.targetWidth * (rightP - leftP)/100
displayO.targetHeight = self.targetHeight * (bottomP - topP)/100
displayO:scale(1,1) -- TODO: Probably don't need this
end
end
return myGroup
end
-- Class Variables
-- Class Methods
return MyGroup
방금이 코드를 사용하여 toolbarArea_button.png 자산을 대체하는 새 프로젝트를 만들었습니다. 문제가 무엇인지 알 수 없지만 더 명확하고 더 많은 것을 만들 수 있습니까? 정확한 예가 무엇입니까? (주석이 달린 코드를 제거하여 시작하십시오. 문제의 원인이 무엇인지는 확실하지 않습니다.) – aaronjbaptiste
개념에 결함이 있다고 생각하기 시작 했습니까? 그룹 중 하나가 변경되면 백분율을 기준으로 개체를 재설정하는 트리거 이벤트가 발생하지 않습니다. 어떻게 생각해? 아마도 pixcel 거리를 통해 코로나 설정을 고수해야할까요? – Greg