Jump to content

P2.js + Camera in Panda Editor Debug mode


khleug35
 Share

Recommended Posts

Hello

I using Panda2 + P2.js to develop my next project, When I add Camera function to Panda Editor Debug mode.

the sprite bound is not displaying correctly ?? 

https://imgur.com/a/lUYxKd2

I3b2wmV.png

 

My full code:

    backgroundColor: '#272727',
    
    init: function() {
        this.world = new game.Physics();
        
        this.world.on('beginContact', function(data) {
           
        });
        this.world.on('impact', function(data) {
           
        });
        this.world.on('postStep', function(data) {
        
        });
        this.container = new game.Container();
        this.container.addTo(this.stage);
        
        var ratio = this.world.ratio;
        var wallShape, wallBody;
        // Left wall
        wallShape = new p2.Box({ width: 2, height: game.height / ratio });
        wallBody = new game.Body({
            position: [-1, game.height / 2 / ratio]
        });
       
             .......... //same width Panda2 P2.js "Main" Example

        this.mouseBody = new game.Body();
        this.mouseBody.addTo(this.world);
        this.player2 = new game.Player(game.width / 2, game.height / 2);
        
         //Add Camera Function
        this.camera = new game.Camera(this.player2.sprite);
        this.camera.setPosition(this.player2.sprite);
        this.camera.addTo(this.container);
       
    },
    
  
    
    addConstraint: function(x, y, player) {
        this.mousemove(x, y);
        
        .......... //same width Panda2 P2.js Player class Example
    },
    
    mousemove: function(x, y) {
        this.mouseBody.position[0] = x / this.world.ratio;
        this.mouseBody.position[1] = y / this.world.ratio;
    },
    
    mouseup: function() {
        .......... //same width Panda2 P2.js Player class Example
    }
});

game.createClass('Player', {
    init: function(x, y) {
        .......... //same width Panda2 P2.js Player class Example
    }
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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