I have a small program that does very little right now (most of it just dummy code), but it’s been very aggravating and I don’t know what’s going on.
The program has several tabs (where each tab represents one “command”), implements one class per tab, and each tab has its own xyz:setup() and xyz:draw() methods. The Main tab’s setup() fn has an array of one instance of each tab. When a command is executed, the instance corresponding to it is retrieved from the array and assigned to variable “currentCommand”, and then currentCommand:setup() is run, which does the expected thing, plus sets a variable “done” to false. (This technique is used in a lot of the Codea examples.) currentCommand.draw() looks like:
function commandX:draw
if done then return
commandX:draw()
done = true
end
Assume CommandA is the first command that runs: it’s supposed to clear the canvas and draw a word on the canvas. CommandB just clears the canvas. So if I haven’t lost you by now, when the user runs a new command, the result should be that the canvas gets overdrawn once per command and that’s all. (The ultimate goal is each command draws a boring graph, nothing animated.)
It can’t get much simpler. Yet when commandA runs, it does create its image on the canvas, but then it flickers like it’s getting redrawn. When commandB runs, it doesn’t clear the screen, and A’s output still flickers. Switching back and forth does nothing except that occasionally A’s output freezes, but the next switch starts it flickering again.
So the question is: why is nothing getting cleared? Why is it flickering? I’ve tried various displayMode() and background() settings, it doesn’t seem to matter. Surely the methods, although having the same names setup() and draw(), aren’t getting automatically executed? I put a print statement in the draw() method, and it does look like it’s getting executed only once (controlled by variable “done”), so what’s causing the flickering? What am I’m overlooking or not understanding? Thanks.