Howdy, Stranger!

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

game camera

I have been searching for a while but can't find anything, how do you get the camera(in the game) to focus on certain things and is there a way to make the canvas, room, level, or whatever you call it bigger or are you limited to do only what it gives you.

Comments

  • dave1707dave1707 Mod
    edited February 19 Posts: 5,987

    The camera statement has arguments for where the camera is and what it's looking at. To move the camera to look at different thing, just change the x,y,z values for the look at variables. You can also change how big or small the view is by changing the perspective parameters. Look in the built in reference for the camera information.

  • Posts: 1,991

    @sadnessIsIimited do you mean for 2D or 3D? As @dave1707 says, use camera for 3D, but for 2D, use translate rotate and scale

  • So what function would I use that in I'm still having trouble with this
    And where would I put translate

  • I am trying to make this a parameter and then once I make the player I am going to make the camera focus on that

  • dave1707dave1707 Mod
    Posts: 5,987

    @sadnessIsIimited I copied this from another discussion where I gave this as an example. Is this close to what you're trying to do. I keep the main character in the center of the screen and the background and other objects get moved around the screen. Also, the playing area is a lot bigger than the screen size.

    displayMode(FULLSCREEN)
    
    function setup()  
        spTab={"Platformer Art:Coin","Planet Cute:Key",
                "Small World:Flag","Small World:Heart","SpaceCute:Star"}
        tab={}
        for z=1,100 do
            table.insert(tab,vec3(math.random(-20,20),
                        math.random(-20,20),math.random(5)))       
        end
        dx,dy=0,0
        xval,yval=0,0
    end
    
    function draw()
        background(142, 228, 101, 91)
        for a,b in pairs(tab) do
            sprite(spTab[b.z],b.x*100+dx,b.y*100+dy)
        end  
        sprite("Platformer Art:Guy Standing",WIDTH/2+23,HEIGHT/2-20)  
        sprite("Cargo Bot:Command Left",75,HEIGHT/2,50,50)
        sprite("Cargo Bot:Command Left",WIDTH-75,HEIGHT/2,-50,50)
        sprite("Cargo Bot:Command Grab",WIDTH/2,HEIGHT-75,50,-50)
        sprite("Cargo Bot:Command Grab",WIDTH/2,75,50,50)
        dx=dx+xval
        dy=dy+yval
    end
    
    function touched(t)
        if t.state==BEGAN then
            if t.x<200 then
                xval=2
            elseif t.x>WIDTH-200 then
                xval=-2
            elseif t.y<200 then
                yval=2
            elseif t.y>HEIGHT-200 then
                yval=-2
            end
        elseif t.state==ENDED then
            xval,yval=0,0
        end
    end
    
Sign In or Register to comment.