I get a wierd error i havent seen anywhere

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Blitzer1001
Prole
Posts: 5
Joined: Wed Jul 27, 2022 12:26 pm

I get a wierd error i havent seen anywhere

Post by Blitzer1001 »

so this is my code:

function love.load()
love.window.setMode(1920, 1080, {resizable=false, fullscreen=true, vsync=false, minwidth=1920, minheight=1080})
harmony = {}
harmony.sprite = love.image.newImageData("Sprites/Harmony.png")
harmony.bg = love.image.newImageData("Sprites/HarmonyBg.png")
end

function love.update(dt)
if love.keyboard.isDown("escape") then
love.event.quit()
end
end

function love.draw()
love.graphics.draw(harmony.bg, 0, 0)
love.graphics.draw(harmony.sprite, 860, -920)
end

i have been getting this error message:
main.lua:15: bad argument #1 to 'draw' (Drawable expected, got ImageData)

Can somebody help me? i am stuck!
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: I get a wierd error i havent seen anywhere

Post by pgimeno »

Well, the error code says it all - ImageData is not drawable. Drawable derivatives are (as of this writing): Canvas, Framebuffer, Image, Mesh, ParticleSystem, SpriteBatch, Text, Texture and Video. As you can see, ImageData is none of these.

Try making an image out of the imagedata, or loading the files into Image instances rather than into ImageData instances:

Code: Select all

harmony.spritedata = love.image.newImageData("Sprites/Harmony.png")
harmony.bgdata = love.image.newImageData("Sprites/HarmonyBg.png")

harmony.sprite = love.graphics.newImage(harmony.spritedata)
harmony.bg = love.graphics.newImage(harmony.bgdata)
-or-

Code: Select all

harmony.sprite = love.graphics.newImage("Sprites/Harmony.png")
harmony.bg = love.graphics.newImage("Sprites/HarmonyBg.png")
depending on whether you're going to need the image data later.
Blitzer1001
Prole
Posts: 5
Joined: Wed Jul 27, 2022 12:26 pm

Re: I get a wierd error i havent seen anywhere

Post by Blitzer1001 »

thanks for solving my problem, pgimeno! it really blocked development!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest