How do i load a small image in big picture

i put some small image to a big one, how do i load small image? codea can not set source rect

I’m sorry, I don’t understand. Do you mean you used setContext() to put a smaller image on top of another, and you want to know how to use the result? If so, it’s like this:

function setup()
    img = readImage("Cargo Bot:Codea Icon")
    setContext(img)
    sprite("Platform Art:Fence", 50, 50)
    setContext()
end

function draw()
    background(255)
    sprite(img, WIDTH / 2, HEIGHT / 2)
end

thank you.
i means a large image file contains many small images, i want to load a small one, only part of the big picture

Using setContext as Sky pointed out above, draw the big image at normal size inside the setContext() area and set the position relative to where the small image lies.

The variable img above needs to be image(width,height) where width and height is the size of the smaller image. Have fun.

Or the image:copy method:

bigImg="Platformer Art:Block Special"
smallImg=readImage(bigImg,100,100):copy(0,0,50,50)

@zhaoweikid I think this might be what you’re after. The image is made up of 4 sprites. Tap on one of the sprites to load it into a second image.


displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    spriteMode(CORNER)
    img1=image(202,342)
    setContext(img1)
    background(255)
    sprite("Planet Cute:Character Boy",0,0)
    sprite("Planet Cute:Character Horn Girl",101,0)
    sprite("Planet Cute:Gem Blue",0,171)
    sprite("Planet Cute:Heart",101,171)
    setContext()
    img2=image(200,300)
end

function draw()
    background(40,40,50)
    sprite(img1,100,200)
    sprite(img2,500,200,300)
end

function touched(t)  
    if t.x>100 and t.x<201 and t.y>200 and t.y<371 then
        img2=img1:copy(1,1,101,171)
    end
    if t.x>201 and t.x<301 and t.y>200 and t.y<371 then
        img2=img1:copy(102,1,101,171)
    end
    if t.x>100 and t.x<201 and t.y>371 and t.y<542 then
        img2=img1:copy(1,172,101,171)
    end
    if t.x>201 and t.x<301 and t.y>371 and t.y<542 then
        img2=img1:copy(102,172,101,171)
    end
end

thanks, image:copy is very good