navigate on a big 2d scene

edited December 2013 in Library Questions

Hi all, i was wondering how to move a camera over a 2D scene bigger than canvas. I should use the P3D camera, ok, but would be a good way to create and draw on a very big PImage and then move it? Thank you all.

Answers

  • Dragging a PImage is a lot easier than moving the camera view.

    Just define the default image position, along with a variable that will move the image for you:

    PImage p;
    
    void setup() {
      size(500, 500);
      p = loadImage("example.png");
    }
    
    void draw() {
      background(200);
      image(p, mouseX - p.width/2, mouseY - p.height/2);
    }
    

    -- MenteCode

  • how is the 2d scene being generated? tiles?

    it's usually better to just render the bit of the screen that's visible rather than keep an enormous picture in memory and only show a bit of it. but it depends what you're doing.

  • I would create a scene bigger than the canavas using Fisica library, to show the interaction of objects so generated in a big space, but looking at a specific area at time. In other cases, maybe would be usefull render everything inside a PGraphics and then translate it, instead of all the objects. But i don't know if i can put the Fisica object directly inside it.

  • I just discovered that is possible to render the Fisica object directly inside the a PGraphics like that: "world. draw(PGraphics name)". A problem is that if you try to interact with a object with the mouse their position is referred to the true coordinate in the usual canvas, and if the scales are different can be a problem.

Sign In or Register to comment.