Howdy, Stranger!

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

Can I memorize "camera()"?

edited April 2014 in Questions Posts: 3

poor spoken English...( * ̄▽ ̄)
Well, I'm creating a Aircraft Shooting Game.
I just used "sprite()" to make everything before, such as game background, my plane, enemies......
Actually it worked well, the new picture being "sprite()" would cover other pictures.
Now I use "camera()" to present a moving 3D background, then use "camera()" again to adjust the view to overlook my plane and enemies.
Background is ok, but after the second time I use "camera()", if a new picture is to cover other pictures(pictures are in the same zLevel), they will flicker.(>﹏<)
But it is too difficult to change every picture's zLevel now, so is there any way to "memorize" the "camera()"? (like using "pushMatrix()" and "popMatrix()")
Or other solutions are useful?



  • edited April 2014 Posts: 1,595

    @bombbomb I think what you're looking for is setContext(image) now possible with 3D objects from a camera, I'm not 100% that's what you want.

  • Posts: 3

    @Luatee Thanks for your help first~
    I just learned how to use the setContext(image) before I try to solve my problem with it, but when I tested out these codes

    function setup()
    function draw()
        background(0, 0, 0, 255)
    function createImage()
        myImage = image(1024,768)
        setContext( myImage )
        sprite("Planet Cute:Character Horn Girl",400,200,300)
        return myImage

    I found the character moved slower then I experted.
    why was that......

  • dave1707dave1707 Mod
    Posts: 8,739

    @bombbomb setContext should be used to create a static image only once. Then you display that image in draw along with any moving sprites. If your static image needs to change, you create that image once and then display it in draw. What you're doing above is creating that image every draw cycle which is what's slowing down the sprite.

  • dave1707dave1707 Mod
    Posts: 8,739

    @bombbomb Here's an example of what you might be trying to do.

    displayMode(FULLSCREEN)      function setup()     rectMode(CORNER)     myImage = image(1024,768)     -- create a random static background     setContext(myImage)     for z=1,20 do         c=color(math.random(255),math.random(255),math.random(255))         fill(c)         rect(math.random(WIDTH),math.random(HEIGHT),200,200)     end     setContext()     a=1 end function draw()     background(0, 0, 0, 255)     sprite(myImage,WIDTH/2,HEIGHT/2)    -- draw static background     a=a+3     sprite("Planet Cute:Character Horn Girl",400,a)    -- draw sprite end
  • Posts: 3

    @dave1707 Thanks(* ̄3 ̄)╭
    your code helps me learn setContext() better, and now i don't think setContext() can solve my previous problem.T-T
    so let me make my previous problem easier to understand with an example...

    function setup()
    function draw()
        background(40, 40, 50)
        sprite("Planet Cute:Character Horn Girl",0,0,400)
        sprite("Planet Cute:Brown Block",512,384,400)

    something strange happen when the character goes through the block. Σ(っ °Д °;)っ
    i know i can put a zLevel() to solve it, but it is too difficult to make it in my program.(there are more then one hundred pictures to be sprite every frame, i can't currect all their zLevel.)
    Besides, i can't delete the perspective() and camera() because i need a 3D background.
    so...what should i do(@_@;)

  • Jmv38Jmv38 Mod
    Posts: 3,297

    @bombbomb your problem is that the 2 sprites have exactly the same z value, so randomly one will be above the other. You can simply set the z value in translate:


    try this, and it is ok. Or try with +100 to have the boy in front.

Sign In or Register to comment.