Jump to content

Pan image and lock camera to boundary


afuriousengine
 Share

Recommended Posts

Looking for help with a problem I'm having.

 

I'm trying to set up an interface where a user can pan a viewport around a larger image (viewport is x by y pixels, image is 4x by 4y pixels). I've somehow been about to set bounds so that I can't move the camera past 0,0 into the negatives, but I haven't been able to figure out how to lock it the other way. This is what I've got for code:

 

Thanks!

 

 

var game      = new Phaser.Game( w, h, Phaser.AUTO, 'viewport' );

 

preload:

    this.game.load.image( 'map', 'images/map/map3.png' );
    this.game.load.image( 'sprites', 'images/spritesheet.png' );
 
    boundsPoint   = new Phaser.Point( 0, 0 );
    viewRect      = new Phaser.Rectangle( 0, 0, game.width, game.height );
 
create:
    game.world.setBounds( 0, 0, map.width, map.height );
    map = this.game.add.image( 0, 0, 'map' ); //this.game.world.centerX, this.game.world.centerY, 'map' );
 
update:
      gameDelta.x = game.input.x;
      gameDelta.y = game.input.y;
 
      // Attempt to bound image
 
      moveY = ( gamePosition.y - gameDelta.y )/25;
      moveX = ( gamePosition.x - gameDelta.x )/25;
 
 
      game.camera.x += moveX;
      game.camera.y += moveY;
 
 
 
Link to comment
Share on other sites

Duh:

 

game.world.setBounds( 0, 0, map.width, map.height );
    map = this.game.add.image( 0, 0, 'map' ); //this.game.world.centerX, this.game.world.centerY, 'map' );
 
should be:
 
map = this.game.add.image( 0, 0, 'map' ); //this.game.world.centerX, this.game.world.centerY, 'map' );
    game.world.setBounds( 0, 0, map.width, map.height );
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...