This is a subset of my Hershey Font drawer, chopped down enough to show the bug without lots of extra.
In a nutshell, if you run this as it is, you get a “#” drawn on the screen (a bit offscreen), looks fine. If you comment that out and uncomment the “drawcharacter” subroutine call above, you get a horribly flickery screen. They both do, so far as I can tell, the exact same line draws - it’s just that one of them pulls the coordinates from a table, while the other is hardcoded. More importantly, perhaps, is that both set up and do their background and stroke stuff the same.
So - why is the “drawcharacter” version so flickery? Am I doing something lame, or am I just exposing something obscure?
PS. One other thing to mention in passing - when working with classes in separate tabs, it doesn’t always bring you to the error when you have one, so you end up having to search thru the tabs and source trying to find them. (And the font data is a couple hundred lines, so that becomes pretty slow…)
PPS. Things really dog down when you get close to 500 lines of code; almost unusable. I have an older ipad, maybe it’s just a memory issue. But - if you didn’t know, now you do.
Just loaded codify and I have been having a similar problem. I wrote simple program to draw an ellipse and it either doesn’t work, screen flickers showing the previous drawing, and sometimes I see weird background color effects. Same thing happens when I try drawing a rectangle.
Bortels - yeah that error issue is annoying for me too. I plan to make it highlight tabs which contain errors. There is a bug which is clearing the errors at the moment when you change a tab.
Bortels - just tried your code and found your bug.
You are overwriting the draw() function in your drawchar() code. Lua is global by default, which is a little tricky to get used to. So in your drawchar() you have the line:
draw = 1
This overwrites the global draw function and sets it to 1. Which causes the screen to stop drawing since Codea now no longer can see the draw function.
You’ll want to change this line to:
local draw = 1
Which will declare it as a locally scoped variable. This fixes the issue.
Add a background() to setup() and the background flickers constantly?
This was the first thing I tried with my first program. The background flickered constantly I assumed I was doing something wrong. I assume this app works for some people.
Codea is heavily inspired/influenced by Processing (http://processing.org). The Codea’s API and programming paradigm is very similar to Processing. Hence the setup(), draw(), and touched() special functions which are not common on other programming languages, even on other Lua IDEs/frameworks. For people who never heard/use Processing might have some problems in the beginning of using Codea. Unfortunately, there’s not enough explanation about this in Codea’s documentation. So, you need to learn it from Processing. Good luck!
Bortels, nice work on the font code, I took the data you posted the other day and wrote a function to draw a whole string and it works a treat. Do you mind if I post it back up?
Also on the iPad 2 I notice a bit of slowdown on the file containing the font data but it doesn’t get unusable, strangely I have much bigger files that have no slowdown at all so I’m wandering if it’s something to do with parsing all the commas and braces…?
Simeon - W00t! I love it when it’s my own bug - makes it easy to fix! Funny part is, the back of my mind has been saying “you really should go look at lua scope rules and make sure you have it right, instead of faking it”. I stared at that code for 2 full hours trying to spot that. Thanks!
vocieoftreason - go for it! I don’t put up anything on gist that I don’t hope and expect people to build on and hopefully re-share. I think Simeon is right about the “lot of numbers” theory - it’s a ton of numbers. I have been thinking of re-massaging the data to encode it as a packed string of characters, which will both make it much smaller, and should prevent the editor from wanting to do a dragable on each of them. But feel free to add and publish whatever you have; in the end, more code is good code, and we’ll be able to pick from the best bits.