Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can't tell if this is your only mistake, but this is ONE mistake. If this is what you say you were doing:</p> <pre><code>spriteBatch.begin(); drawBackground(); drawShip(); spriteBatch.setProjectionMatrix(camera.combined); spriteBatch.end(); </code></pre> <p>You wont see anything. When setProjectionMatrix is called inside a begin()/end() block. the current batch is flushed to the gpu. So, you are actually not drawing anything with the camera matrix. You should do this instead:</p> <pre><code> spriteBatch.setProjectionMatrix(camera.combined); spriteBatch.begin(); drawBackground(); drawShip(); spriteBatch.end(); </code></pre> <p>EDIT:</p> <p>If you don't call that line, spriteBatch uses its own default camera (which wont notice your camera.update() modifications, so that's not what you want).</p> <p>You should now pay more attention to the coordinates you are using. I'm not quite sure you really need the ppu conversion thing. To begin with, define everything in imaginary world coordinates, note that you'll see some stretching in your world.</p> <pre><code>public void drawShip(){ spriteBatch.draw(shipTexture,ship.getPosition().x,ship.getPosition().y, 10, 10); }//your ship is 10 units wide and tall! public void drawBackground(){ spriteBatch.draw(background, -10,0, 500, 100); } //your background is 500 units wide, and 100 units tall //camera setup camera = new OrthographicCamera(50, 50); //your camera will print to screen 50 units of your world </code></pre> <p>If you get to see a stretched world, try to understand how it's working (if you can't see anything, there is something wrong somewhere).</p> <p>EDIT 2</p> <p>I took a look at your code. First remove ppu's, as it obscures your code. You were setting your cam position to the ship.postion, while drawing at ship.position * ppu. Also your background was way too big (that's why you see it pixelated). You should see something reasonable with this. (someday you'll have to initialize your camera in another way to deal with stretching, but forget it until you understand how all works).</p> <pre><code>this.cam = new OrthographicCamera(CAMERA_WIDTH,CAMERA_HEIGHT); public void drawShip(){ spriteBatch.draw(shipTexture, ship.getPosition().x ,ship.getPosition().y, 10, 10); } public void drawBackground(){ spriteBatch.draw(background, -CAMERA_WIDTH/2, -CAMERA_HEIGHT/2, 100, 100); //let bg begin where camera starts. (0,0) } public void render(float delta){ ship.Move(delta); moverCamara(ship.getPosition().x, ship.getPosition().y); spriteBatch.setProjectionMatrix(cam.combined); spriteBatch.begin(); drawBackground(); drawShip(); spriteBatch.end(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload