How to draw a Sprite on the screen

I know quite a lot of Lua syntax. I program RBX Lua, so yeah. I tried creating a Sprite on the screen but it won’t work. Here’s what I tried. It’s not the exact same code, but it’s a little overview. I used the draw event and the touch event in my other script. But it just won’t work!

Block = class()

function Block.init()
sprite(“image blah”,50,50,50,50)

first off, it’s Block:init (colon not full stop), but that’s not the problem with the sprite

We need to see more code before we can help you, eg what exactly is “image blah”?

I tap on the Sprite statement and select my Sprite from my assets folder. So it appears as: “Project:lol” lol is the name of my Sprite I added to the folder. Here’s my current code that doesn’t work:

function block:draw()



@Coder1500 - did you mean Block:draw()

ie capital B? Lua is case sensitive

No it’s not. I got this app yesterday and nothing at all is working. I kinda wonder if there are bugs on your side. I can’t even change the color of the background. background = color(4,4,255) I can’t draw any sprites even outside of functions and classes!

@Coder1500 - I can pretty much guarantee in advance that the bugs are all on your side.

For example, if you read the reference it’s

background = color(4,4,255) 

Have you read any of the many tutorials that show you how to draw in Codea?

Go here:

Download “Codea for beginners”, and look at the top of page 21.

And please read the rest of the book, too. Just because you’ve used Lua before doesn’t make you a Codea programmer. There is a lot to learn.

If the sprite file does not exist, the size is too big, …it won’t work

i got background to work by using it in a draw function. I’ll try sprites later. Thanks guys!!

What is the maximum size a Sprite can be for it to be uploaded?

Max size for a texture is 2048 X 2048:

But you can draw the sprite larger than its texture size, and it will still look pretty good with smoothing on (or pixelated with smoothing off)

Some of the info on the above page is a little out-of-date (eg you have for a while been able to have vertex textures)

Thanks :slight_smile: