englercj / phaser-tiled

A tilemap implementation for phaser focusing on large complex maps built with the Tiled Editor.
MIT License
290 stars 31 forks source link

Just got Arcade Physics to work #57

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hey guys, so I got arcade physics to work.

In Phaser-Tiled, under the Tile.prototype method

add:

    if(this.layer.name == 'Collision'){

            //this.visible = false;
            game.physics.enable(this, Phaser.Physics.ARCADE);
            this.body.immovable = true;

    }

Assuming your layer name is Collision

then, simply add this to your update method:

game.physics.arcade.collide(pSprite, mymap.children[7].children);  

Where pSprite represents your player sprite. and the index 7 represents what layer index your Collision layer is under.

I tested the regular stock Phaser tile renderer with arcade physics and this plugin still performs better. I know this is a hacky way of doing it, but it works. And AFAIK setting the tiles to immovable helps with performance too as it doesn't have to check for velocities so that's nice.

englercj commented 8 years ago

I feel like you must not be using the latest version of this pllugin, newer versions purposefully do not create Tile objects at all. I don't think this can work with the latest version, nor do I recommend this as the way going forward.

We just need to add the proper convert methods to the physics.js file.

englercj commented 8 years ago

I'm going to close this, since we have an issue to track building Arcade support already (#19).

ghost commented 8 years ago

Yeah, I'm using the older version cause the newest one drops my frames to like 20fps for some reason (From 60). So I just stick with the old one :P. I was going to make an issue about it but everything in my console is fine and I don't see any errors so I don't really know what to report. I did check the Phaser debug, and it just showed high rendering usage

I tried 2.4.4, 2.4.5 and 2.4.6. I found 2.4.3 and the old Phaser tiled plugin has the best FPS? Maybe it's just my game... not sure

englercj commented 8 years ago

Can you share your project so I can try to track down why that is? All the improvements in v2 were to decrease memory and CPU usage. I can't imagine the FPS dropping like that just from upgrading.

I'd really like to figure out the problem there.