Background Image

function setup()
    displayMode(FULLSCREEN)
    bg = image(1024,768)
    setContext(bg)
    displayMode(FULLSCREEN)
    fill(255, 0, 0, 255)
    rect(0,0,WIDTH/2,HEIGHT)
    fill(0, 255, 39, 255)
    rect(WIDTH/2,0,WIDTH/2,HEIGHT)
    setContext()
    saveImage('Documents:DualColour',bg)
end

function draw()
    background(sprite("Documents:DualColour"))
end

Am i just making this complicated for myself?
I want to create a background image (in this case an image thats half red, half greeen) and set it as, well the background, this seems like the correct approach though a little procrastinating voice (that might be right) tells me to just setContext(bg) and just subsequently draw on that, though i’m not sure if that ideas very good either

My only other problem is size. If i get a gigantic, lets say 4000x4000, image and set it as the background, will codea keeps the part of the background that isnt shown or will codea just clip it off? if codea will clip it (or shrink it) how can i stop this?

thanks in advance i love markdown

Is that code not working?

  1. 4096 x 4096 is the biggest image codea handles
  2. Get rid of the second displayMode, that’s not helpful.

@Dalorbi

I cleaned up your code a little to give you the red/green background. I added a circle that you can drag around the screen with your finger so you can see how it works with the background.


displayMode(FULLSCREEN)

function setup()
    bg = image(WIDTH,HEIGHT)
    setContext(bg)
    fill(255, 0, 0, 255)
    rect(0,0,WIDTH/2,HEIGHT)
    fill(0, 255, 0, 255)
    rect(WIDTH/2,0,WIDTH/2,HEIGHT)
end

function draw()
    sprite(bg,WIDTH/2,HEIGHT/2)
    fill(255)
    ellipse(CurrentTouch.x,CurrentTouch.y,50,50)  -- draw circle
end

thanks dave that works well

If you only need to create the image once, then you only need to run the stuff in setup once.

On the size issue, you’ll be limited to 4096 by 4096 for a single image on the ipad 3 - a limitation of openGL - see here
http://twolivesleft.com/Codea/Talk/discussion/comment/14331#Comment_14331

To get bigger images, you’ll need to do some tiling