【发布时间】:2014-02-20 20:51:46
【问题描述】:
我有这段代码可以使用 display.newCircle 在屏幕上画一条线。它工作得很好但是 当我画得更多时,它会更不稳定并泄漏内存。 我怎样才能保持这个优化。 问题仅在设备上。 这是代码
local background = display.newRect( 0, 0, 480, 800 )
local lines = {};
local i = 1;
local strokeWidth = 20;
local R = 150;
local G = 100;
local B = 50;
local function drawALine(event)
if event.phase == "began" then
elseif event.phase == "moved" then
lines[i] = display.newCircle(event.x, event.y, strokeWidth, strokeWidth);
lines[i]:setFillColor( R,G,B );
elseif event.phase == "ended" then
end
end
Runtime:addEventListener("touch", drawALine)
有什么帮助吗?
【问题讨论】:
-
不稳定是什么意思?
-
这是你的 main.lua 吗?你不使用场景或 createScene 事件?
-
不,它不是 main.lua,我使用导演类从一个场景切换到另一个场景我已经添加到这样的组中
lines[i] = display.newCircle(paintGroup, event.x, event.y, strokeWidth, strokeWidth);但这不会改变任何东西 -
不稳定是指我的应用在绘制一段时间后没有响应。
-
请考虑用信息扩展您的问题,而不是放入 cmets,这有助于提出更好的问题,人们不必阅读无数 cmets。