Jump to content

player position when world is taller than screen


terebentina
 Share

Recommended Posts

Hi,

 

I am totally new to Phaser so this might be a silly question. I have the following code, mostly copy&pasted from one of the examples. I made the world taller than the actual canvas height. 

When I add the 'dude' player to the game, it's added somewhere above the screen, instead of where it should be:

game.add.sprite(game.world.centerX, game.world.height - 10, 'dude');

The player is horizontally centered, as it should but somewhere out of the screen. If you run the code below, the player will fall and fall from somewhere off screen above and it will eventually appear after 1-2 seconds of falling.

 

What am I doing wrong?

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create});function preload() {	game.load.spritesheet('dude', 'assets/img/dude.png', 32, 48);}function create() {	//  Make the world larger than the actual canvas	game.world.setBounds(0, 0, 800, 2000);	game.stage.backgroundColor = '#169AC5';	game.camera.y = game.world.height - 150;	var player = game.add.sprite(game.world.centerX, game.world.height - 10, 'dude');	player.anchor.setTo(0.5, 0.5);	//  Player physics properties. Give the little guy a slight bounce.	player.body.bounce.y = 0.2;	player.body.gravity.y = 6;	player.body.collideWorldBounds = true;}
Link to comment
Share on other sites

Hi,

 

I have tested your code, and can confirm, there is something very weird going on.

 

I think you have found a bug. As far as I can tell the player sprite is placed correctly initially, but then moved by something in the engine.

 

Using parts of your code, removing the movement aspect.. I have found weird behavior too:

 

Here is my (easier to see) test, that shows something is weird, when you use collideWorldBounds AND move the camera (even if you move it from y=0 to y=0!).

 

 

If somebody wants to debug what is happening here, here is my code showing the (possible the same) bug:

 

Or (look at it here):

http://janpeter.net/alien/test.html

 

http://janpeter.net/alien/test_nobug.html

 

The ONLY difference is the comments before the line "game.camera.y = 0;" - no other difference.

(So what are the sprites doing?)

 

Code and Screenshots follow:

 

 

 

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8" />
<title> bug </tile>
        <script src="phaser.js"></script>
    </head>
    <body>
 
    <script type="text/javascript">
 
      var game = new Phaser.Game(1024, 768, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render});
 
function preload() {
game.load.spritesheet('dude', 'data/cloud1.png', 32, 48);
}
 
function update() {
 
}
 
var s1, s2, s3;
 
function create() {
game.world.setBounds(0, 0, 800, 800);
 
s1 = game.add.sprite(110, 550, 'dude');
s2 = game.add.sprite(220, 560, 'dude');
s3 = game.add.sprite(330, 570, 'dude');
 
s1.body.collideWorldBounds = true;
s2.body.collideWorldBounds = true;
s3.body.collideWorldBounds = true;
 
game.camera.y = 0;
 
        }
 
        function render() {
            game.debug.renderSpriteInfo(s1, 32, 032);
game.debug.renderSpriteInfo(s2, 32, 232);
game.debug.renderSpriteInfo(s3, 32, 432);
game.debug.renderCameraInfo(game.camera, 32, 632);
        }
    </script>
    <div id="info"> </div>
 
    </body>
</html>

 

 

Run this, look at where the sprites are (compared to where they should be..) .. then uncomment game.camera.y = 0 .. and look where the sprites are now.

Unexplainable to me (okay, I have not debugged it yet..)

 

I am using crome. here are my results:

 

with cam-line:

 

bug.png

 

without cam-line:

nobug.png

Link to comment
Share on other sites

I gave it a shot yesterday but I don't have enough knowledge about the engine to indicate what's going on.

To me it seemed as if the game had a problem putting the player outside of the the actual word size (800, 600).

 

As soon as it's y coordinate gets >600 during creation it gets created at y=600.

 

I really just messed around setting the bounds to (0, 0, 800, 650);

But I could not figure out what's going on :/

Link to comment
Share on other sites

Good to know I am not crazy. I will try to not move the camera until someone figures out the problem...who knows, with a little experience it might be me :)

Should I report this as a bug in github or are the devs looking at this forum too?

The dev's comment on this forum constantly, but you should add the issue over github any way :) 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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