Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sprites have colored borders

in Bugs Posts: 716

I first noticed this with a scaled sprite that I was using in Space Invaders, but it happens with unscaled sprites as well. The scaled one has a red border all around. The unscaled one has a red border on the white squares and a white border on the red squares. Most peculiar. Thanks for all you do!

function setup()
    map4 = image(4,4)
    for x = 1,4 do
        for y = 1,4 do
            if (x+y)%2 == 0 then
                c = color(255,0,0)
            else
                c = color(255,255,255)
            end
            map4:set(x,y,c)
        end
    end
    map128 = image(128,128)
    for x = 1,128 do
        xx = x//32
        for y = 1,128 do
            yy = y//32
            if (xx +yy)%2 == 0 then
                c = color(255,0,0)
            else
                c = color(255,255,255)
            end
            map128:set(x,y,c)
        end
    end
end

function draw()
    background(200,200,200)
    pushMatrix()
    pushStyle()
    spriteMode(CORNER)
    translate(WIDTH/4,HEIGHT/2)
    sprite(map128,0,0)
    translate(WIDTH/4,0)
    scale(32)
    sprite(map4,0,0)
    popStyle()
    popMatrix()
end

Comments

  • Posts: 791

    For the scaled one - add noSmooth() to the start of the draw function. It'll switch off the antialiasing (which is creating the red border I suspect)

    For the other one, try running the for x and for y between 0 and 127 instead of 1 and 128 to resolve. I think it is to do with the origin of the image being 0,0 or 1,1 in terms of the image:set call (I can't remember which way round). It's caused me no end of hassle with sprite sheets as it also affects the image:copy function.

  • Posts: 716

    images are 1-based, according to the docs, so istm the 128 is correct. i'll fiddle tho, and will try nosmooth too. thanks.

  • Posts: 716

    hmm, 0,127 does the trick. now i wonder what the truth is.

  • Posts: 716

    the 4x4's coloring tells me bottom left is 1,1. am i missing something?

  • dave1707dave1707 Mod
    Posts: 8,561

    Image “get” goes from 1 to the image size. Outside of that range and you’ll get an error message. Image “set” doesn’t seem to matter. There’s no error message if you use 0 or go beyond the image size.

  • Posts: 716

    yes

  • Posts: 716

    OK, the scale 1 one has a bug in the mod. :) noSmooth makes the other go away.

  • dave1707dave1707 Mod
    edited August 22 Posts: 8,561

    @RonJeffries I’m not following what you mean in your above post by “bug in the mod”. Also, by scale 1, do you mean comment out the scale(32) line. I commented out the scale(32) and put noSmooth() above spriteMode(CORNER). When I run it, I see both sprites. One is normal size and the other one is really small and barely visible. It’s to the right bottom of the visible sprite about 1/2 inch away. If I’m totally off about what you mean, explain more.

    PS. OK, I think I know what you mean by “bug in mod”. Do you mean the %2 in the line if (xx +yy)%2 == 0 which cause the small white/red line to the right and top of the square. If that’s what you mean, it’s not a bug but bad coding. Look at the code below which doesn’t have that problem. You need to do the for loops from 0 to127, not 1 to 128. You then need the x+1 and y+1 in the map128:set line.

    If I’m still wrong about what you’re saying, let me know.

    displayMode(FULLSCREEN)   
    
    function setup()
        map128 = image(128,128)
        for x = 0,127 do
            xx = x//32
            for y = 0,127 do
                yy = y//32
                if (xx+yy)%2 == 0 then
                    c = color(255,0,0)
                else
                    c = color(255,255,255)
                end
                map128:set(x+1,y+1,c)
            end
        end
    end
    
    function draw()
        background(200,200,200)
        noSmooth()
        sprite(map128,400,500)
    end
    
  • Posts: 716

    i meant a bug in my code, in the / and % stuff.

Sign In or Register to comment.