Discord
Login
Community
DARK THEME

Disable Anti-Aliasing

In my current project, I wanted a low-res feel, so I opted to just draw to an Image, then display that to the screen for a pixel-perfect representation of older games. All of the sprites I draw have no anti-aliasing, but whenever I want to draw a shape (like image.drawLine(5,5,25,20,"#fff")) the anti-aliasing is still there. The image.setPixelated(true) only seems to work for sprites/images, but not for shapes. Is there any way I can disable the anti-aliasing entirely?

To my knowledge, line drawing always works with anti-aliasing (lines without this technique look very bad - if they are not vertical or horizontal).

You can draw a line yourself - create a function to draw a line where you place pixels with image.setRGB ()

Or make false pixels - you draw a pattern (line) on an Image type object, and then you draw this object on the screen.

If you are not afraid of rotating, zooming, copying and complicating the code - you can use something like this.

init = function()
  image = new Image( 50, 50 )
  image.clear()
  image.setColor( '#FFFFFF')
  image.setPixelated( 0 )
  image.setLineWidth( 1 )
  image.drawLine(25,1,25,49)
  posX = 0
  screen.setScale( 2, 2 )
  angle = 0 
  pixelX = 2
  pixelY = 10
  fi = fakePixelImage( pixelX, pixelY, 10, 10, 2, "#FF00FF")   
end
fakePixelImage = function( pixelX, pixelY, sizeX, sizeY, space, color )
  local image = new Image( pixelX * ( sizeX + space) , pixelY*( sizeY+space) ) 
  print( pixelX * ( sizeX + space) +' ' + pixelY*( sizeY+space) )
  image.clear()
  image.setColor( color )
  for loopY = 0 to pixelY - 1 
    for loopX = 0 to pixelX - 1
      image.fillRect(  loopX * ( sizeX + space) , loopY*( sizeY+space) , sizeX, sizeY )
    end
  end
  return image
end

update = function()
  posX += 0.01
  angle += 0.1
end

draw = function()
  screen.clear()
  screen.setDrawRotation( angle )
  screen.drawImage( image, 50, 0, 100, 100 )
  screen.drawImage( fi , -50, 0, fi.width, fi.height )
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community