Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Dealing with images created in a project

edited February 2015 in Questions Posts: 277

Hi there,

I'm experimenting with images created inside a project.

In short, I'm trying the create a background image from scratch, then create another image which contains little sprites, then overlay the latter on top of the former in order to create one last image (which therefore contains both the background image and the sprites).

I do it like this:

bg = image(400,400)
littleSprites = image(400,400)
finalImage = image(400,400)

setContext(bg)
sprite(aLarge-ishImage,0,0)
setContext()

setContext(littleSprites)
for i = 1,5 do
    sprite(Littlesprite..i,math.random(0,400),math.random(0,400))
end
setContext()

setContext(finalImage)
sprite(bg,0,0)
sprite(littleSprites,0,0)
setImage()

Now, I can't seem to get what I need, but instead, only the littleSprites image on a white background. Could this be because when creating an image, Codea creates a white image, and not a transparent one?

Thanks!

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 7,604

    @Rodolphe


    function setup() bg = image(400,400) littleSprites = image(400,400) finalImage = image(400,400) setContext(bg) sprite("Cargo Bot:Startup Screen",0,0) setContext() setContext(littleSprites) for i=1,5 do sprite("Cargo Bot:Condition Blue",math.random(0,400),math.random(0,400)) end setContext() setContext(finalImage) sprite(bg,200,200) sprite(littleSprites,200,200) setContext() end function draw() background(0) sprite(finalImage,200,200) end
  • Posts: 1,976

    Codea creates transparent images, not white images. However, you're drawing the sprites at 0, 0. I think you mean to draw them at 200, 200 because the default spriteMode is CENTER. Also, did you mean to say for i in 1, 5 do? (proper syntax is for i = 1, 5 do)

  • Posts: 277

    Oh thank you so much @dave1707 and @SkyTheCoder, this had been bugging me for an hour :D

  • dave1707dave1707 Mod
    Posts: 7,604

    @Rodolphe If you don't need the other images, you can do everything with just the one image.


    function setup() finalImage = image(400,400) setContext(finalImage) sprite("Cargo Bot:Startup Screen",0,0) for i=1,5 do sprite("Cargo Bot:Condition Blue",math.random(0,400),math.random(0,400)) end setContext() end function draw() background(0) sprite(finalImage,200,200) end
  • Posts: 277

    Oh yes, but the two images are actually done at different times during gameplay, then put together.

  • dave1707dave1707 Mod
    Posts: 7,604

    @Rodolphe You can still just use one image. Create image1 with the background you want, then later on create the foreground images onto image1.

  • Posts: 277

    Oh of course, that would save memory for sure... Thanks !

Sign In or Register to comment.