Drawing star objects: is texturing a meshRect or coloring the vertices better?

Currently I’m wondering about the benefits and downsides to using either method. I’m not satisfied with any of my attempts at this point, so you could set me off in either direction for the next couple iterations.

What I like about coloring vertices: I can color the middle vertices to be white. Could put some perspective. Easy for me to prototype in Codea

What I like about using addRect and setRectTexture: way less vortexes dont have to personally fine tune the mesh because it’s just taking X,y,w,h and turning that into 2 triangles, could make the image look really nice

I don’t know how either will impact performance… That shouldn’t be a problem since I don’t plan to draw too many stars max atm anyway, but maybe when I start all the other stuff in the game it could be something to consider

I doubt you’ll have any problem with rects, but it’s worth getting used to doing it with vertices because that’s what you’ll need as your projects get more complex.

I doubt you’ll have any problem with rects, but it’s worth getting used to doing it with vertices because that’s what you’ll need as your projects get more complex.

We can’t say that without knowing more about the project. If it’s 3D, sure, vertices are going to come up, but for 2D, rects could be the way to go, it depends.

I’d say the principal advantage of rects, is that if you need lots of stars moving around onscreen at once, rects are by far the fastest way to do this, because you can put them all on a single mesh. The fewer :draw() calls you have, the better. You could also put all of your vector stars onto one mesh too, but it would be more work moving each star around, compared to just using setRect. How many triangles are you drawing your stars with? You could do a 5-pointed star with 4 triangles I think? (with no overlapping).

I wouldn’t see a need for a single mesh until you have a lot of stars, in most cases, individual meshes are ok - and this avoids all the problems of moving vertices around on a single mesh

@xThomas Here’s something I had. Not sure what you can use from this if anything.

displayMode(FULLSCREEN)

function setup()
    starTab={}
    for z=1,200 do
        table.insert(starTab,star(
            math.random(20,WIDTH-20),math.random(20,HEIGHT-20),math.random(3,15)))
    end
end

function draw()
    background(0)
    for a,b in pairs(starTab) do
        b:draw()
    end
end

star=class()

function star:init(x,y,size)
    self.x=x
    self.y=y
    self.r=math.random(72)
    local m=mesh()
    m.vertices={
        vec2(0.0,1.245)*size,vec2(.809,-1.2449)*size,vec2(-.5,-.2938)*size,
        vec2(.309,.2939)*size,vec2(1.309,.2939)*size,vec2(.5,-.2938)*size,
        vec2(0.0,-.6571)*size,vec2(-.809,-1.2449)*size,vec2(-.50,-.2938)*size,
        vec2(-.5,-.2938)*size,vec2(-1.309,.2939)*size,vec2(-.309,.2939)*size}
    m:setColors(255,0,0) 
    local r=math.random(255)
    local g=math.random(255)
    local b=math.random(255)
    for z=1,12 do
        m:color(z,r,g,b)
    end
    self.s=m  
end

function star:draw()
    pushMatrix()
    translate(self.x,self.y)
    rotate(self.r)
    self.s:draw() 
    popMatrix()
end