Howdy, Stranger!

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

Making field move around character

edited July 2014 in Questions Posts: 134

So for a game i want to have a character (maybe a circle for now) based in the middle of the screen, and all around it the screen moves. So instead of moving the circle, you're moving the everything around the circle in the direction opposite of whatever vector you moved to...how would I go about making a feature like this?

Comments

  • Posts: 1,976

    Just translate drawing away from the player's position.

    translate(-player.x, -player.y)
    

    (Note: for drawing the player, first you have to do resetMatrix() or translate(pkayer.x, player.y) to put it back in the center)

  • Posts: 134

    Sky you're a champion at this..I have a few more nooby questions if you don't mind

  • Posts: 135

    I'm also confused with this. @SkyTheCoder could you give an example program?

  • Posts: 425

    Here's an example of what I think @SkyTheCoder meant

    function setup()
        player=vec2(WIDTH/2,HEIGHT/2)--position of the player in the world
        origin=vec2(WIDTH/2,HEIGHT/2)--position the player will be drawn at
        print("tilt to move")
    end
    
    function draw()
        player = player-vec2(Gravity.x,Gravity.y)*10--move the player
        background(0)
        pushMatrix()--save the current transformation
        translate(player.x-origin.x,player.y-origin.y)--move screen in the opposite direction to player
        spriteMode(CENTER)
        sprite("SpaceCute:Background",origin.x,origin.y,WIDTH)--draw the ground
        popMatrix()--reset the transformation
        sprite("Planet Cute:Character Boy",origin.x,origin.y)--draw the player in the middle of the screen
    end
    
Sign In or Register to comment.