I can't get noSmooth() to work on my Spritely art [ANSWERED]

Every time I draw some scaled pixel art, it comes out blurry. When I put on noSmooth(), it stays blurry. Is there a way to get it so the the image is pixelated when scaled?
Thanks!

silly question - you’re doing nosmooth() before you draw the sprite, right? And it’s not scaled way up (there’s a way to keep it square pixels, but I don’t recall the exact sequence…)

If you find that code, please let me know.
Thanks!

Can somebody please help? I would like this really soon.

I find that noSmooth() does get reversed by some calls, but if you have it right before the sprite statement, it should work.

Thanks, but even when I tried using smooth() instead, it was still blurry. The only way I can think of right now is to wright a function that somehow multiplies the pixels when scaled. I would like to get some help from @Simeon.

Yeah - I know I’ve done it (I remember saying “oh, good, you can scale things without a blur”), but heck if I can reproduce that.

Maybe use rect()s? Yeah, meh. Hmm - I wonder if it was scaling an image() that worked. If I stumble across it again, I’ll post.

Are you talking about sprite(image)? Works for me. Maybe post your code

function draw()
    background(0, 0, 0)
    img = image(3,3)
    img:set(2,2,255,255,255,255)
    spriteMode(CORNER)
    noSmooth()
    sprite(img,0,0,WIDTH,HEIGHT)
end

@ruilov - I’m scaling the image. Thanks @Bortels in advance for if you do find what you did.

Scaling also works fine for me

function draw()
    background(0, 0, 0)
    img = image(3,3)
    img:set(2,2,255,255,255,255)
    noSmooth()
    spriteMode(CORNER)
    scale(50)
    sprite(img,0,0,10,10)
end

@ruilov - Make a multi pixels and color image with spritely and do what you just did.

I really need help with this.

@Zoyt the invaders in Sprite Invaders are scaled up sprites from Spritely. Do they look right for you?

@Zoyt modify my example above to show how it doesnt work.

Here is an example-




-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
end

function drawHi()
--Spritely
local spritely = image(8, 8)
spritely:set(1,8,255,0,0,255)
spritely:set(1,7,255,128,0,255)
spritely:set(1,6,255,255,0,255)
spritely:set(1,5,128,255,0,255)
spritely:set(1,4,0,255,255,255)
spritely:set(1,3,0,0,255,255)
spritely:set(1,2,128,0,255,255)
spritely:set(1,1,255,0,255,255)
spritely:set(2,5,255,0,128,255)
spritely:set(3,5,171,79,77,255)
spritely:set(4,8,127,127,127,255)
spritely:set(4,7,192,192,192,255)
spritely:set(4,6,255,255,255,255)
spritely:set(4,5,255,0,0,255)
spritely:set(4,4,255,128,0,255)
spritely:set(4,3,255,255,0,255)
spritely:set(4,2,128,255,0,255)
spritely:set(4,1,0,255,255,255)
spritely:set(6,6,0,255,255,255)
spritely:set(6,4,255,0,255,255)
spritely:set(6,3,171,79,77,255)
spritely:set(6,2,127,127,127,255)
spritely:set(6,1,255,0,0,255)
return spritely
end

hi = drawHi()

-- This function gets called once every frame
function draw()
    -- This sets the background color to black
    background(0, 0, 0)
    scale(10)
    sprite(hi, CurrentTouch.x/10, CurrentTouch.y/10)
    -- Do your drawing here
end

From your example, nosmooth() seems to work only if it is in the draw() loop anywhere before the sprite is drawn.

It doesn’t work in setup() and it doesn’t work after the sprite is drawn

Seems like the default into the draw() loop is smooth

Yes. When the draw loop is entered both the matrix and style stacks are reset to default states. This ensures that you can’t easily push hundreds of transforms onto the stack with an unbalanced pushMatrix().

Ah. I’ll try it and let you know when I get a chance.

Let me get the code and I’ll post an example program I made.