All Projects → hexus → Phaser Arcade Slopes

hexus / Phaser Arcade Slopes

Licence: other
📐 A Phaser CE plugin that brings sloped tile collision handling to the Arcade Physics engine

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Phaser Arcade Slopes

Phaser Tilemap Plus
Tilemap animations, physics, events and custom property enhancements for Tiled JSON map files
Stars: ✭ 44 (-64.52%)
Mutual labels:  phaser, collision, tilemap
FyWorld
FyWorld - Base-Building / Simulation Game & Tutorial in Unity
Stars: ✭ 207 (+66.94%)
Mutual labels:  tile, tilemap
grid-engine
An exceptional plugin for grid-based features in the Phaser 3 framework.
Stars: ✭ 124 (+0%)
Mutual labels:  tile, phaser
UnityHexagonLibrary2d
A library to manage 2D hexagonal tiles in Unity.
Stars: ✭ 58 (-53.23%)
Mutual labels:  tile, tilemap
Phaser3 Tilemap Pack
Phaser 3 Project Template with Webpack, Tilemap, and Asset Pack
Stars: ✭ 87 (-29.84%)
Mutual labels:  phaser, tilemap
Litiengine
LITIENGINE 🕹 The pure 2D java game engine.
Stars: ✭ 384 (+209.68%)
Mutual labels:  tile, tilemap
AsLib
🎨: RPG map maker (paint tool)
Stars: ✭ 82 (-33.87%)
Mutual labels:  tile, tilemap
Pyxeledit Map Importer
Parser for maps generated by the editor PyxelEdit
Stars: ✭ 32 (-74.19%)
Mutual labels:  tile, tilemap
Tiledmapview
Tiled map loader for Android , based on the pyramid model, supports a variety of projections, including Web Mercator projection, latitude and longitude projection and custom projection; supports locating, adding layers and overlays. Android瓦片地图加载控件,基于金字塔模型,支持多种投影,包括Web墨卡托投影,经纬度直投及自定义投影等;支持定位,添加图层和覆盖物。
Stars: ✭ 45 (-63.71%)
Mutual labels:  tile, tilemap
Phaser Ce
Phaser CE is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
Stars: ✭ 1,186 (+856.45%)
Mutual labels:  phaser
Spatial Collision Datastructures
Benchmark of various spatial data structures for collision detection.
Stars: ✭ 96 (-22.58%)
Mutual labels:  collision
Creature godot
2D Skeletal Animation Creature Runtime for Godot Engine
Stars: ✭ 70 (-43.55%)
Mutual labels:  tile
Gowog
Gowog, Golang based Web multiplayer Online Game
Stars: ✭ 75 (-39.52%)
Mutual labels:  phaser
Badsanta
BadSanta - Multiplayer HTML5 Game (http://santa.qake.se)
Stars: ✭ 97 (-21.77%)
Mutual labels:  phaser
Games
一个基于Phaser的小游戏集合
Stars: ✭ 1,167 (+841.13%)
Mutual labels:  phaser
Laravel Dashboard Chart Tile
Create all the charts you want for your laravel dashboard
Stars: ✭ 102 (-17.74%)
Mutual labels:  tile
Easygameframeworkopen
基于Typescript的渐进式通用游戏前端开发框架
Stars: ✭ 65 (-47.58%)
Mutual labels:  phaser
Phaser Boilerplate
Phaser ES6 Boilerplate
Stars: ✭ 56 (-54.84%)
Mutual labels:  phaser
Phaser Spine
A plugin for Phaser 2 that adds Spine support
Stars: ✭ 111 (-10.48%)
Mutual labels:  phaser
Tiles And Such
Archives of tilelable images/wallpapers
Stars: ✭ 101 (-18.55%)
Mutual labels:  tile

Phaser Arcade Slopes Plugin

Arcade Slopes brings sloped tile collision handling to Phaser's Arcade Physics engine.

Demo

Check out the demo!

Phaser Arcade Slopes

Features

  • 24 new tile types 🎉
  • SAT collision handling 👌
  • Unobtrusive and cooperative integration with Arcade Physics ✌️
  • Supports sprites 🚀, groups 👥, particle emitters ✨ and circular physics bodies ⚪️

Compatibility

Phaser Version Arcade Slopes Version
v2.4.1 - v2.4.8 v0.1.0
v2.5.0 - v2.10.1 v0.1.1 - v0.3.1
v3.x hexus/phaser-slopes

Installation

Grab a copy of the latest release from the dist directory in this repository and include it after Phaser.

<script src="phaser.min.js"></script>
<script src="phaser-arcade-slopes.min.js"></script>

Usage

Enabling the plugin

Enable the plugin in the create() method of your Phaser state.

game.plugins.add(Phaser.Plugin.ArcadeSlopes);

Mapping tiles

The plugin provides a couple of built in tile slope mappings:

After you've created a tilemap with a collision layer, you'll need to convert that layer to work with Arcade Slopes.

// Create the tilemap and make it aware of the tileset it uses
map = game.add.tilemap('tilemap');
map.addTilesetImage('collision', 'arcade-slopes-32');
map.setCollisionBetween(1, 38);

// Create the collision layer from the tilemap
ground = map.createLayer('collision');

// Convert the collision layer to work with Arcade Slopes
game.slopes.convertTilemapLayer(ground, 'arcadeslopes');

In the case that the first tile ID of the collision tileset in your tilemap is not 1 (the default), you can provide a third argument to specify it. The arguments provided to the setCollisionBetween() method may need to be adjusted as well.

map.setCollisionBetween(16, 53);
game.slopes.convertTilemapLayer(ground, 'ninja', 16);

Please note: Tile GIDs in maps exported from Tiled are always one more than the ID shown in the GUI. Arcade Slopes expects the above parameter to match the first GID as specified in the Tiled map data.

Enabling physics bodies

Now you need to enable slopes for any game entities you want to collide against the tilemap.

game.physics.arcade.enable(player);

game.slopes.enable(player);
game.slopes.enable(emitter);

You don't need to do anything special for circular physics bodies, just the usual sprite.body.setCircle(radius).

Make sure you call game.slopes.enable(object) after making any changes to the size or shape of the physics body.

Collision

Now you can collide your sprite against the tilemap in the update() method of your Phaser state, as you normally would, using Arcade Physics. Voila!

// Collide the player with the collision layer
game.physics.arcade.collide(player, ground);

// Collide the particles with the collision layer
game.physics.arcade.collide(emitter, ground);

Debug rendering

To debug your collision layer, set its debug property to true.

This will overlay the collision shapes of each tile when the layer is rendered.

ground.debug = true;

Extras

Minimum Y offset

This feature separates rectangular physics bodies on the Y axis only, in the right situations.

// Prefer the minimum Y offset for this physics body
player.body.slopes.preferY = true;

// Prefer the minimum Y offset globally
game.slopes.preferY = true;

If you're making a platformer, your player has drag on the X axis, and you don't want it to slide down slopes, this should solve your problem.

Collision pulling

To attempt to keep objects on a surface, you can use collision pulling.

This will pull physics bodies into a collision by a set velocity, if it matches the set direction.

// Pull the player into downwards collisions with a velocity of 50
player.body.slopes.pullDown = 50;

Here are the available properties for collision pulling:

body.slopes.pullUp
body.slopes.pullDown
body.slopes.pullLeft
body.slopes.pullRight
body.slopes.pullTopLeft
body.slopes.pullTopRight
body.slopes.pullBottomLeft
body.slopes.pullBottomRight

Building

If you want to build the plugin yourself from source, clone the repository and run NPM and Gulp like so.

npm install
gulp build

There's also a watch task that builds the plugin whenever you make changes to the source.

gulp watch

Thanks

My thanks go out to those who made this Plugin possible.

And to contributors who have been generous with their time, talents and support:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].