Sprite help

Why is this not working? This is my code


StartMenu = class()

function StartMenu:init(x)
    self.x = x
    ironManM1 = readImage("Documents:iron man Mk1")
    ironManM2 = readImage("Documents:iron man Mk2")
    x = WIDTH/2
    y = HEIGHT/2
end

function StartMenu:draw()
    sprite(ironManM1, 100, 100)
end

function StartMenu:touched(touch)
    
end

function setup()
   
end

function draw()
    StartMenu:draw()
end

function touched(touch)
    
end

The formatting makes it a little hard to tell, but it looks as if you’ve defined a class, but not created an instance of that class.

So, if you had…

StartMenu = class()

function StartMenu:init(x) 
    self.x = x 
    self.img = "Documents:iron man Mk1"
end

function StartMenu:draw() 
    sprite(self.img, x, HEIGHT / 2) 
end

function setup()
  sm = StartMenu(WIDTH / 2)
end

function draw() 
   sm:draw() 
end

You should see an image at mid-screen.

Does that help?

@JHRA Here’s your code modified to run.

StartMenu = class()

function StartMenu:init(x1,y1,x2,y2)
    self.x1 = x1
    self.y1 = y1
    self.x2 = x2
    self.y2 = y2
    ironManM1 = readImage("Planet Cute:Character Cat Girl")
    ironManM2 = readImage("Planet Cute:Character Princess Girl")
end

function StartMenu:draw()
    sprite(ironManM1, self.x1, self.y1)
    sprite(ironManM2, self.x2, self.y2)
end

function StartMenu:touched(touch)

end

function setup()
    s=StartMenu(100,100,200,200)
end

function draw()
    s:draw()
end

function touched(touch)

end

Thank you!

Accident

This is getting a bit long to post in full, I suggest putting it in a gist

When you do post code, put ~~~ on an empty line before and after the code, to format it properly.