Firstly, I have to say I love this app! I started out with zero coding experience and have loved guessing, browsing, cut/pasting my way forward and have so far managed to solve all the issues I have encountered, albeit minor no doubt! But have now hit my first problem that has totally stumped me.
I’m trying to create a basic piece of code that prints text on screen, but only when the right key is touched. The basic idea of the Code is below
function setup() displayMode(FULLSCREEN) function touched(touch) showKeyboard() end end function keyboard(key) if string.byte(key) == 97 then Text:draw() end end
function Text:draw() fontSize(55) font("AmericanTypewriter-Bold") fill(233, 170, 6, 255) text("hello",500,350) end
My problem is that the minute I have it as part of an if function it causes the text to flicker on the screen. I can only assume that because the draw function tries to run 60 fps it runs the if function 60 times and once ‘97’ (a) has been pressed it holds that in the keyboardBuffer and every time the draw function runs it prints the text on screen, causing it to flicker? If i press key ‘97’ often enough it finally stops flickering… Assuming this is because it has printed it so many times on screen.
If insert similar code, but without the if, it doesn’t flicker. In my mind i need to clear the keyboardBuffer straight after Text:draw()? Is this possible, or any other suggestions?