Codea 2.3 Beta

@Simeon Is there a reason why spriteMode doesn’t work before setup() anymore. It works before setup() in version 1.5 . Run this and the sprite doesn’t fill the square. Uncomment the spriteMode in setup() and it fills the square. Also, image set and image get require an integer. You can’t set or get the half values for the retina display.

spriteMode(CORNER)

function setup()
    --spriteMode(CORNER)          -- uncomment this line
    img=image(200,200)
    setContext(img)
    fill(255,0,0)
    rect(0,0,200,200)
    setContext()
end

function draw()
    background(40, 40, 50)
    sprite(img,0,0)
    stroke(255)
    strokeWidth(2)
    noFill()
    rect(0,0,200,200)
end

@dave1707 - Found this thread from a while ago.

@Andrew_Stacey - Thanks, that works perfectly. I just assumed that @Loopspace was already in on the latest beta.

@Saturn031000 Thanks for the update. Apparently I missed it or I don’t remember seeing it.

HI @TechDojo, @AndrewStacey,

I noted the problem with the 3D library and resolved it with the following code:


function __discreteNormal(a,o,...)
    local n = select("#",...)   -- arg.n
    local na,nb
    na = vec3(0,0,0)
    for k=2,n do
        nb = (select(k,...) - a):cross(select(k-1,...) - a)   -- (arg[k] - a):cross(arg[k-1] - a)
        na = na + nb/nb:lenSqr()
    end
        na = na:normalize()
    if na:dot(a-o) < 0 then
        na = -na
    end
    return na
end

Hope that helps.

Bri_G

@Bri_G one for the profilers, I think, as to whether select is faster than creating a table.

(I appear to be able to read the beta thread now. Thank you to whoever enabled it. And thank you to @Andrew_Stacey for alerting me to the issue with the 3D library.)

@LoopSpace i am getting confused. I though you were a new ID for @AndrewStacey? Are you both 2 different people? :-?

For some reason textSize() has been causing a crash; this used to be a bug, but I thought it had been fixed.

@FLCode Do you have a simple example of code that crashes.

@dave1707 there should be image rawSet and rawGet which access in pixels, instead of points. I’ll have to think about using how to re-enable spriteMode and other graphical style changes outside of setup.

@dave1707, unfortunately my code is about 2000 lines long, but the crash comes from textSize being called many times during draw().

Here’s how it’s being called:

tpt = {}
tpt.widths = {}
tpt.textwidth = function(text)
    ---[[
    if text and type(text) == "string" and #text > 0 then
        if type(tpt.widths[text]) == "string" then
            return tpt.widths[text]
        else
            --saveProjectTab("Log", "-- " .. type(text) .. " " .. text .. ": " .. table.concat({string.byte(tostring(text))}, ","))
            local x, y = textSize(text)
            --saveProjectTab("Log", "--textwidth")
            tpt.widths[text] = (x)
            return x or 10
        end
    end
    return 0
    --[=[
    --]]
    return 0
    --]=]
end

@Simeon The rawGet and rawSet commands work, but you just have to remember to use double the value because of the raw size.

@FLCode I’m not sure what your code is doing, but you said you call textSize many times with draw. So I set up this code that calls textSize and increases the size of str by 1 character per draw. I can run this and let it go with no problems. Apparently the max textSize is 19997. So I don’t think there’s a problem with testSize.

function setup()
    str="a"
end

function draw()
    background(40, 40, 50)
    w,h=textSize(str)
    text("Size  ".. w,WIDTH/2,HEIGHT/2)
    text("Length   "..string.len(str),WIDTH/2,HEIGHT/2-50)
    str=str.."a"
end

@dave1707 a more future proof way would be to use x * myImage.scale, y * myImage.scale (iPhone 6+ has a scale factor of 3x, for example).

@Simeon I didn’t see scale in the documents for image. I know about rawset and rawget for tables, but rawSet and rawGet for graphics are new to me. I’m just wondering how many other commands are available that don’t show in the docs and how can we find out about them.

Sorry @dave1707, I’ll log an issue on the tracker to add these.

Hi All,

Just a quick update on what I’ve found in my code so far. Most of the problems have been related to math.mod() or math.random(). An example is in LightDye’s thread and JMV38’s Loading wheel code here:

JMV38

where I changed the code:


self.light = math.mod(self.light + self.shift, 256)

to


self.light, temp = math.modf(self.light + self.shift, 256)

Which managed to resolve the problem.

By the way - I’ve seen several references to ‘the documents’ in this thread - which documents are they referring to?

Thanks,

Bri_G

@Bri_G The Docs I refer to are the build in documents (reference) or the link below.

http://twolivesleft.com/Codea/Reference/

@dave1707 Hasn’t it been moved to this link?

http://codea.io/reference/

I think it’s more recent because the saveText() and readText() functions are documented in this one, but not the other one.

@Saturn031000 Thanks. I’ll update my link to the new one.