How cut sprites from big image?

Hi guys, sorry for stupid questions , but yesterday evening I thought about this technic :“I have some npc’s positioned in big sprite with some pixels between them. And I want randomly chose one piece of big image and use that piece like single image” . I have some experience in modding mobile games and I remember that technic uses in animation (for example) . I imagine make some “railing” to divorce sprites from whole image. Maybe only cut sprite from image to store in memory . All in all I want know your opinions

P.s I think it needs 2d table
P.s.s sorry for my English

I don’t ask you about coding , but maybe you can give me link to another similar post/piece of code

@lupino8211 what you’re looking for is either a shader (which is harder, I do not recommend it), or setContext(img).

Say your big image is 1600x800 and you want to display 8 different 400x400 images you would do something like this

local img = image(400,400)
setContext(img)
--this draws the top left of the big image
sprite(bigimg,800,0)
setContext()

So what is happening is you’re just drawing to that one image that is 400x400, but when doing this your coordinates now default around 0,0 which is the bottom left of your 400x400 picture, meaning you’ll have to work out the position of the big sprite based around that 0,0 coordinate.

You can make a table of positions for the bigimg and increment through the table to create animation or just store several images in one big sprite, the possibilities are endless (not literally).

@lupnio8211 - have a look at the built in reference, Graphics section, the image.copy function

--copies the part of this image from (50,60) to (50+200,60+300)
--puts it in a new image
image2=image1.copy(50,60,200,300)

Big thanks for replying . I expect more complicated construction

@lupino8211 That question has been asked before. See the link below for an example.

http://codea.io/talk/discussion/5375/how-do-i-load-a-small-image-in-big-picture/p1

@dave1707 thanks a lot