Added body mode property to TileMap to select between static and kinematic physics bodies. Kinematic allow use of TileMaps for moving platforms for example.

Updated 2D Platformer demo to use kinematic TileMaps for moving platforms, in doing so discovered that the tileset was messed up and not converting properly, so fixed that too.
And in order to fix the tileset I need to activate snapping for collision polygon vertices.
This commit is contained in:
Carl Olsson 2015-02-13 20:49:21 +10:00
parent d0ea475405
commit 9d182e93a3
9 changed files with 339 additions and 223 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -1,77 +1,56 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resource_file type="PackedScene" subresource_count="4" version="1.0" version_name="Godot Engine v1.0.3917-beta1">
<ext_resource path="res://moving_platform.*" type="Texture"></ext_resource>
<ext_resource path="res://moving_platform.*" type="Script"></ext_resource>
<resource type="ConvexPolygonShape2D" path="local://1">
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> -88, 24, -88, -24, 88, -24, 88, 24 </vector2_array>
</resource>
<resource_file type="PackedScene" subresource_count="3" version="1.0" version_name="Godot Engine v1.0.stable.custom_build">
<ext_resource path="res://moving_platform.gd" type="Script"></ext_resource>
<ext_resource path="res://tileset.xml" type="TileSet"></ext_resource>
<main_resource>
<dictionary name="_bundled" shared="false">
<string> "names" </string>
<string_array len="46">
<string_array len="28">
<string> "moving_platform" </string>
<string> "Node2D" </string>
<string> "_import_path" </string>
<string> "visibility/visible" </string>
<string> "visibility/opacity" </string>
<string> "visibility/self_opacity" </string>
<string> "visibility/on_top" </string>
<string> "transform/pos" </string>
<string> "transform/rot" </string>
<string> "transform/scale" </string>
<string> "z/z" </string>
<string> "z/relative" </string>
<string> "script/script" </string>
<string> "__meta__" </string>
<string> "motion" </string>
<string> "cycle" </string>
<string> "platform" </string>
<string> "RigidBody2D" </string>
<string> "shape_count" </string>
<string> "shapes/0/shape" </string>
<string> "shapes/0/transform" </string>
<string> "shapes/0/trigger" </string>
<string> "TileMap" </string>
<string> "mode" </string>
<string> "mass" </string>
<string> "friction" </string>
<string> "bounce" </string>
<string> "custom_integrator" </string>
<string> "continuous_cd" </string>
<string> "contacts_reported" </string>
<string> "contact_monitor" </string>
<string> "active" </string>
<string> "can_sleep" </string>
<string> "velocity/linear" </string>
<string> "velocity/angular" </string>
<string> "Sprite" </string>
<string> "texture" </string>
<string> "centered" </string>
<string> "offset" </string>
<string> "flip_h" </string>
<string> "flip_v" </string>
<string> "vframes" </string>
<string> "hframes" </string>
<string> "frame" </string>
<string> "modulate" </string>
<string> "region" </string>
<string> "region_rect" </string>
<string> "CollisionPolygon2D" </string>
<string> "build_mode" </string>
<string> "polygon" </string>
<string> "tile_set" </string>
<string> "cell/size" </string>
<string> "cell/quadrant_size" </string>
<string> "cell/custom_transform" </string>
<string> "cell/half_offset" </string>
<string> "collision/body_mode" </string>
<string> "collision/friction" </string>
<string> "collision/bounce" </string>
<string> "collision/layers" </string>
<string> "tile_data" </string>
</string_array>
<string> "version" </string>
<int> 1 </int>
<string> "conn_count" </string>
<int> 0 </int>
<string> "node_count" </string>
<int> 4 </int>
<int> 2 </int>
<string> "variants" </string>
<array len="17" shared="false">
<node_path> "" </node_path>
<bool> True </bool>
<real> 1 </real>
<vector2> 0, 0 </vector2>
<real> 0 </real>
<vector2> 1, 1 </vector2>
<resource resource_type="Script" path="res://moving_platform.*"> </resource>
<int> 0 </int>
<resource resource_type="Script" path="res://moving_platform.gd"> </resource>
<dictionary shared="false">
<string> "__editor_plugin_states__" </string>
<dictionary shared="false">
@ -92,16 +71,22 @@
<string> "pixel_snap" </string>
<bool> False </bool>
<string> "zoom" </string>
<real> 1.360373 </real>
<real> 1.850616 </real>
<string> "use_snap" </string>
<bool> True </bool>
<string> "ofs" </string>
<vector2> -210.652, -172.81 </vector2>
<vector2> -406.735, -157.32 </vector2>
<string> "snap" </string>
<int> 32 </int>
</dictionary>
<string> "3D" </string>
<dictionary shared="false">
<string> "deflight_rot_y" </string>
<real> 0.628319 </real>
<string> "zfar" </string>
<real> 500 </real>
<string> "fov" </string>
<real> 400 </real>
<real> 179 </real>
<string> "viewports" </string>
<array len="4" shared="false">
<dictionary shared="false">
@ -111,10 +96,12 @@
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "listener" </string>
<bool> True </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
@ -125,10 +112,12 @@
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<string> "listener" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
@ -139,10 +128,12 @@
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<string> "listener" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
@ -153,10 +144,12 @@
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<string> "listener" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
@ -165,12 +158,18 @@
<int> 1 </int>
<string> "default_light" </string>
<bool> True </bool>
<string> "ambient_light_color" </string>
<color> 0.15, 0.15, 0.15, 1 </color>
<string> "show_grid" </string>
<bool> True </bool>
<string> "show_origin" </string>
<bool> True </bool>
<string> "znear" </string>
<real> 0.1 </real>
<string> "default_srgb" </string>
<bool> False </bool>
<string> "deflight_rot_x" </string>
<real> 0.942478 </real>
</dictionary>
</dictionary>
<string> "__editor_run_settings__" </string>
@ -183,19 +182,17 @@
<string> "__editor_plugin_screen__" </string>
<string> "2D" </string>
</dictionary>
<vector2> -96, -32 </vector2>
<resource resource_type="TileSet" path="res://tileset.xml"> </resource>
<vector2> 64, 64 </vector2>
<int> 16 </int>
<matrix32> 1, 0, 0, 1, 0, 0 </matrix32>
<int> 2 </int>
<int> 1 </int>
<resource resource_type="Shape2D" path="local://1"> </resource>
<matrix32> 1, -0, 0, 1, 0, 0 </matrix32>
<bool> False </bool>
<int> 3 </int>
<int> 0 </int>
<resource resource_type="Texture" path="res://moving_platform.*"> </resource>
<color> 1, 1, 1, 1 </color>
<rect2> 0, 0, 0, 0 </rect2>
<vector2_array len="4"> -88, -24, 88, -24, 88, 24, -88, 24 </vector2_array>
<int_array len="6"> 0, 536870927, 1, 536870926, 2, 15 </int_array>
</array>
<string> "nodes" </string>
<int_array len="150"> -1, -1, 1, 0, -1, 11, 2, 0, 3, 1, 4, 1, 5, 0, 6, 2, 7, 3, 8, 4, 9, 5, 10, 6, 11, 2, 12, 1, 0, 0, 0, 14, 13, -1, 23, 2, 0, 3, 1, 4, 1, 5, 0, 6, 2, 7, 3, 8, 4, 15, 7, 16, 8, 17, 9, 18, 10, 19, 11, 20, 1, 21, 1, 22, 3, 23, 10, 24, 10, 25, 12, 26, 10, 27, 0, 28, 0, 29, 2, 30, 3, 0, 1, 0, 31, 31, -1, 18, 2, 0, 3, 1, 4, 1, 5, 0, 6, 2, 7, 3, 8, 4, 32, 13, 33, 0, 34, 2, 35, 10, 36, 10, 37, 7, 38, 7, 39, 12, 40, 14, 41, 10, 42, 15, 0, 1, 0, 43, 43, -1, 9, 2, 0, 3, 1, 4, 1, 5, 0, 6, 2, 7, 3, 8, 4, 44, 12, 45, 16, 0 </int_array>
<int_array len="80"> -1, -1, 1, 0, -1, 13, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 1, 11, 7, 12, 8, 13, 3, 14, 2, 0, 0, 0, 16, 15, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 9, 7, 4, 8, 5, 9, 6, 10, 1, 17, 6, 18, 10, 19, 11, 20, 12, 21, 13, 22, 14, 23, 15, 24, 2, 25, 4, 26, 15, 27, 16, 0 </int_array>
<string> "conns" </string>
<int_array len="0"> </int_array>
</dictionary>

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -1,134 +1,191 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resource_file type="TileSet" subresource_count="12" version="0.99" version_name="Godot Engine v0.99.3037-pre-beta">
<resource_file type="TileSet" subresource_count="14" version="1.0" version_name="Godot Engine v1.0.stable.custom_build">
<ext_resource path="res://tiles_demo.png" type="Texture"></ext_resource>
<resource type="ConvexPolygonShape2D" path="local://0">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> 0, 8, 64, 8, 64, 64, 0, 64 </vector2_array>
<resource name="script/script"></resource>
</resource>
<resource type="ConvexPolygonShape2D" path="local://1">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> 0, 64, 0, 8, 56, 8, 56, 64 </vector2_array>
<resource name="script/script"></resource>
<vector2_array name="points" len="4"> -32, -24, 32, -24, 32, 32, -32, 32 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://2">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> 0, 64, 0, 0, 56, 0, 56, 64 </vector2_array>
<resource name="script/script"></resource>
<vector2_array name="points" len="4"> -32, 32, -32, -24, 24, -24, 24, 32 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://3">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> 0, 64, 0, 0, 56, 0, 56, 64 </vector2_array>
<resource name="script/script"></resource>
<vector2_array name="points" len="4"> -32, 32, -32, -32, 24, -32, 24, 32 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://4">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="5"> 0, 64, 0, 0, 56, 0, 64, 8, 64, 64 </vector2_array>
<resource name="script/script"></resource>
<vector2_array name="points" len="4"> -64, 32, -64, -32, -8, -32, -8, 32 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://5">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> 0, 64, 0, 8, 64, 8, 64, 64 </vector2_array>
<resource name="script/script"></resource>
<vector2_array name="points" len="5"> -32, 32, -32, -32, 24, -32, 32, -24, 32, 32 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://6">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> 0, 64, 0, 8, 64, 8, 64, 64 </vector2_array>
<resource name="script/script"></resource>
<vector2_array name="points" len="4"> -32, 32, -32, -24, 32, -24, 32, 32 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://7">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> 0, 0, 64, 0, 64, 64, 0, 64 </vector2_array>
<resource name="script/script"></resource>
<vector2_array name="points" len="4"> -32, 32, -32, -24, 32, -24, 32, 32 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://8">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> 0, 8, 64, 72, 64, 128, 0, 128 </vector2_array>
<resource name="script/script"></resource>
<vector2_array name="points" len="4"> -32, -32, 32, -32, 32, 32, -32, 32 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://9">
<string name="resource/name"> "" </string>
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> 0, 64, 0, 0, 56, 0, 56, 64 </vector2_array>
<resource name="script/script"></resource>
<vector2_array name="points" len="4"> -32, -56, 32, 8, 32, 64, -32, 64 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://10">
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> -32, 32, -32, -32, 24, -32, 24, 32 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://11">
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> -32, -24, 32, -24, 32, 24, -32, 24 </vector2_array>
</resource>
<resource type="ConvexPolygonShape2D" path="local://12">
<real name="custom_solver_bias"> 0 </real>
<vector2_array name="points" len="4"> -32, -24, 24, -24, 24, 24, -32, 24 </vector2_array>
</resource>
<main_resource>
<string name="resource/name"> "" </string>
<string name="0/name"> "floor" </string>
<resource name="0/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="0/offset"> 0, 0 </vector2>
<vector2 name="0/tex_offset"> 0, 0 </vector2>
<vector2 name="0/shape_offset"> 32, 32 </vector2>
<rect2 name="0/region"> 0, 0, 64, 64 </rect2>
<resource name="0/shape" resource_type="ConvexPolygonShape2D" path="local://0"> </resource>
<array name="0/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://1"> </resource>
</array>
<string name="1/name"> "edge" </string>
<resource name="1/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="1/offset"> 0, 0 </vector2>
<vector2 name="1/tex_offset"> 0, 0 </vector2>
<vector2 name="1/shape_offset"> 32, 32 </vector2>
<rect2 name="1/region"> 64, 0, 64, 64 </rect2>
<resource name="1/shape" resource_type="ConvexPolygonShape2D" path="local://1"> </resource>
<array name="1/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://2"> </resource>
</array>
<string name="2/name"> "wall" </string>
<resource name="2/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="2/offset"> 0, 0 </vector2>
<vector2 name="2/tex_offset"> 0, 0 </vector2>
<vector2 name="2/shape_offset"> 32, 32 </vector2>
<rect2 name="2/region"> 64, 64, 64, 64 </rect2>
<resource name="2/shape" resource_type="ConvexPolygonShape2D" path="local://2"> </resource>
<array name="2/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://3"> </resource>
</array>
<string name="3/name"> "wall_deco" </string>
<resource name="3/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="3/offset"> 0, 0 </vector2>
<vector2 name="3/tex_offset"> 0, 0 </vector2>
<vector2 name="3/shape_offset"> 64, 32 </vector2>
<rect2 name="3/region"> 320, 128, 128, 64 </rect2>
<resource name="3/shape" resource_type="ConvexPolygonShape2D" path="local://3"> </resource>
<array name="3/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://4"> </resource>
</array>
<string name="4/name"> "corner" </string>
<resource name="4/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="4/offset"> 0, 0 </vector2>
<vector2 name="4/tex_offset"> 0, 0 </vector2>
<vector2 name="4/shape_offset"> 32, 32 </vector2>
<rect2 name="4/region"> 64, 128, 64, 64 </rect2>
<resource name="4/shape" resource_type="ConvexPolygonShape2D" path="local://4"> </resource>
<array name="4/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://5"> </resource>
</array>
<string name="5/name"> "flowers" </string>
<resource name="5/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="5/offset"> 0, 0 </vector2>
<vector2 name="5/tex_offset"> 0, 0 </vector2>
<vector2 name="5/shape_offset"> 32, 32 </vector2>
<rect2 name="5/region"> 192, 192, 64, 64 </rect2>
<resource name="5/shape" resource_type="ConvexPolygonShape2D" path="local://5"> </resource>
<array name="5/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://6"> </resource>
</array>
<string name="6/name"> "tree_base" </string>
<resource name="6/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="6/offset"> 0, 0 </vector2>
<vector2 name="6/tex_offset"> 0, 0 </vector2>
<vector2 name="6/shape_offset"> 32, 32 </vector2>
<rect2 name="6/region"> 256, 192, 64, 64 </rect2>
<resource name="6/shape" resource_type="ConvexPolygonShape2D" path="local://6"> </resource>
<array name="6/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://7"> </resource>
</array>
<string name="7/name"> "tree_mid" </string>
<resource name="7/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="7/offset"> 0, 0 </vector2>
<vector2 name="7/tex_offset"> 0, 0 </vector2>
<vector2 name="7/shape_offset"> 0, 0 </vector2>
<rect2 name="7/region"> 256, 128, 64, 64 </rect2>
<resource name="7/shape"></resource> <string name="8/name"> "tree_mid 2" </string>
<array name="7/shapes" len="0" shared="false">
</array>
<string name="8/name"> "tree_mid 2" </string>
<resource name="8/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="8/offset"> 0, 0 </vector2>
<vector2 name="8/tex_offset"> 0, 0 </vector2>
<vector2 name="8/shape_offset"> 0, 0 </vector2>
<rect2 name="8/region"> 256, 64, 64, 64 </rect2>
<resource name="8/shape"></resource> <string name="9/name"> "tree_top" </string>
<array name="8/shapes" len="0" shared="false">
</array>
<string name="9/name"> "tree_top" </string>
<resource name="9/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="9/offset"> 0, 0 </vector2>
<vector2 name="9/tex_offset"> 0, 0 </vector2>
<vector2 name="9/shape_offset"> 0, 0 </vector2>
<rect2 name="9/region"> 256, 0, 64, 64 </rect2>
<resource name="9/shape"></resource> <string name="10/name"> "solid" </string>
<array name="9/shapes" len="0" shared="false">
</array>
<string name="10/name"> "solid" </string>
<resource name="10/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="10/offset"> 0, 0 </vector2>
<vector2 name="10/tex_offset"> 0, 0 </vector2>
<vector2 name="10/shape_offset"> 0, 0 </vector2>
<rect2 name="10/region"> 0, 64, 64, 64 </rect2>
<resource name="10/shape"></resource> <string name="11/name"> "ceiling" </string>
<array name="10/shapes" len="0" shared="false">
</array>
<string name="11/name"> "ceiling" </string>
<resource name="11/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="11/offset"> 0, 0 </vector2>
<vector2 name="11/tex_offset"> 0, 0 </vector2>
<vector2 name="11/shape_offset"> 32, 32 </vector2>
<rect2 name="11/region"> 384, 64, 64, 64 </rect2>
<resource name="11/shape" resource_type="ConvexPolygonShape2D" path="local://7"> </resource>
<array name="11/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://8"> </resource>
</array>
<string name="12/name"> "ramp" </string>
<resource name="12/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="12/offset"> 0, 0 </vector2>
<vector2 name="12/tex_offset"> 0, 0 </vector2>
<vector2 name="12/shape_offset"> 32, 64 </vector2>
<rect2 name="12/region"> 128, 128, 64, 128 </rect2>
<resource name="12/shape" resource_type="ConvexPolygonShape2D" path="local://8"> </resource>
<array name="12/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://9"> </resource>
</array>
<string name="13/name"> "ceiling2wall" </string>
<resource name="13/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="13/offset"> 0, 0 </vector2>
<vector2 name="13/tex_offset"> 0, 0 </vector2>
<vector2 name="13/shape_offset"> 32, 32 </vector2>
<rect2 name="13/region"> 448, 64, 64, 64 </rect2>
<resource name="13/shape" resource_type="ConvexPolygonShape2D" path="local://9"> </resource>
<resource name="script/script"></resource>
<array name="13/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://10"> </resource>
</array>
<string name="14/name"> "platform_floor" </string>
<resource name="14/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="14/tex_offset"> 0, 0 </vector2>
<vector2 name="14/shape_offset"> 32, 32 </vector2>
<rect2 name="14/region"> 128, 0, 64, 64 </rect2>
<array name="14/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://11"> </resource>
</array>
<string name="15/name"> "platform_edge" </string>
<resource name="15/texture" resource_type="Texture" path="res://tiles_demo.png"> </resource>
<vector2 name="15/tex_offset"> 0, 0 </vector2>
<vector2 name="15/shape_offset"> 32, 32 </vector2>
<rect2 name="15/region"> 192, 0, 64, 64 </rect2>
<array name="15/shapes" len="1" shared="false">
<resource resource_type="Shape2D" path="local://12"> </resource>
</array>
</main_resource>
</resource_file>

File diff suppressed because one or more lines are too long

View File

@ -28,7 +28,7 @@
/*************************************************************************/
#include "tile_map.h"
#include "io/marshalls.h"
#include "servers/physics_2d_server.h"
void TileMap::_notification(int p_what) {
switch(p_what) {
@ -62,7 +62,7 @@ void TileMap::_update_quadrant_space(const RID& p_space) {
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
Quadrant &q=E->get();
Physics2DServer::get_singleton()->body_set_space(q.static_body,p_space);
Physics2DServer::get_singleton()->body_set_space(q.body,p_space);
}
}
@ -79,7 +79,7 @@ void TileMap::_update_quadrant_transform() {
Matrix32 xform;
xform.set_origin( q.pos );
xform = global_transform * xform;
Physics2DServer::get_singleton()->body_set_state(q.static_body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
Physics2DServer::get_singleton()->body_set_state(q.body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
}
}
@ -178,7 +178,7 @@ void TileMap::_update_dirty_quadrants() {
Quadrant &q = *dirty_quadrant_list.first()->self();
vs->canvas_item_clear(q.canvas_item);
ps->body_clear_shapes(q.static_body);
ps->body_clear_shapes(q.body);
int shape_idx=0;
for(int i=0;i<q.cells.size();i++) {
@ -259,8 +259,8 @@ void TileMap::_update_dirty_quadrants() {
}
ps->body_add_shape(q.static_body,shape->get_rid(),xform);
ps->body_set_shape_metadata(q.static_body,shape_idx++,Vector2(E->key().x,E->key().y));
ps->body_add_shape(q.body,shape->get_rid(),xform);
ps->body_set_shape_metadata(q.body,shape_idx++,Vector2(E->key().x,E->key().y));
}
}
@ -339,19 +339,19 @@ Map<TileMap::PosKey,TileMap::Quadrant>::Element *TileMap::_create_quadrant(const
q.canvas_item = VisualServer::get_singleton()->canvas_item_create();
VisualServer::get_singleton()->canvas_item_set_parent( q.canvas_item, get_canvas_item() );
VisualServer::get_singleton()->canvas_item_set_transform( q.canvas_item, xform );
q.static_body=Physics2DServer::get_singleton()->body_create(Physics2DServer::BODY_MODE_STATIC);
Physics2DServer::get_singleton()->body_attach_object_instance_ID(q.static_body,get_instance_ID());
Physics2DServer::get_singleton()->body_set_layer_mask(q.static_body,collision_layer);
Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_FRICTION,friction);
Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_BOUNCE,bounce);
q.body=Physics2DServer::get_singleton()->body_create(body_mode);
Physics2DServer::get_singleton()->body_attach_object_instance_ID(q.body,get_instance_ID());
Physics2DServer::get_singleton()->body_set_layer_mask(q.body,collision_layer);
Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_FRICTION,friction);
Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_BOUNCE,bounce);
if (is_inside_tree()) {
xform = get_global_transform() * xform;
RID space = get_world_2d()->get_space();
Physics2DServer::get_singleton()->body_set_space(q.static_body,space);
Physics2DServer::get_singleton()->body_set_space(q.body,space);
}
Physics2DServer::get_singleton()->body_set_state(q.static_body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
Physics2DServer::get_singleton()->body_set_state(q.body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
rect_cache_dirty=true;
quadrant_order_dirty=true;
@ -361,7 +361,7 @@ Map<TileMap::PosKey,TileMap::Quadrant>::Element *TileMap::_create_quadrant(const
void TileMap::_erase_quadrant(Map<PosKey,Quadrant>::Element *Q) {
Quadrant &q=Q->get();
Physics2DServer::get_singleton()->free(q.static_body);
Physics2DServer::get_singleton()->free(q.body);
VisualServer::get_singleton()->free(q.canvas_item);
if (q.dirty_list.in_list())
dirty_quadrant_list.remove(&q.dirty_list);
@ -586,17 +586,29 @@ void TileMap::set_collision_layer_mask(uint32_t p_layer) {
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
Quadrant &q=E->get();
Physics2DServer::get_singleton()->body_set_layer_mask(q.static_body,collision_layer);
Physics2DServer::get_singleton()->body_set_layer_mask(q.body,collision_layer);
}
}
Physics2DServer::BodyMode TileMap::get_collision_body_mode() const{
return body_mode;
}
void TileMap::set_collision_body_mode(Physics2DServer::BodyMode p_body_mode) {
_clear_quadrants();
body_mode=p_body_mode;
_recreate_quadrants();
}
void TileMap::set_collision_friction(float p_friction) {
friction=p_friction;
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
Quadrant &q=E->get();
Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_FRICTION,p_friction);
Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_FRICTION,p_friction);
}
}
@ -612,7 +624,7 @@ void TileMap::set_collision_bounce(float p_bounce){
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
Quadrant &q=E->get();
Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_BOUNCE,p_bounce);
Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_BOUNCE,p_bounce);
}
}
@ -807,6 +819,9 @@ void TileMap::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_collision_layer_mask","mask"),&TileMap::set_collision_layer_mask);
ObjectTypeDB::bind_method(_MD("get_collision_layer_mask"),&TileMap::get_collision_layer_mask);
ObjectTypeDB::bind_method(_MD("set_collision_body_mode","body_mode"),&TileMap::set_collision_body_mode);
ObjectTypeDB::bind_method(_MD("get_collision_body_mode"),&TileMap::get_collision_body_mode);
ObjectTypeDB::bind_method(_MD("set_collision_friction","value"),&TileMap::set_collision_friction);
ObjectTypeDB::bind_method(_MD("get_collision_friction"),&TileMap::get_collision_friction);
@ -837,6 +852,7 @@ void TileMap::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/quadrant_size",PROPERTY_HINT_RANGE,"1,128,1"),_SCS("set_quadrant_size"),_SCS("get_quadrant_size"));
ADD_PROPERTY( PropertyInfo(Variant::MATRIX32,"cell/custom_transform"),_SCS("set_custom_transform"),_SCS("get_custom_transform"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/half_offset",PROPERTY_HINT_ENUM,"Offset X,Offset Y,Disabled"),_SCS("set_half_offset"),_SCS("get_half_offset"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"collision/body_mode",PROPERTY_HINT_ENUM,"Static,Kinematic"),_SCS("set_collision_body_mode"),_SCS("get_collision_body_mode"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_friction"),_SCS("get_collision_friction"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_bounce"),_SCS("get_collision_bounce"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"collision/layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_collision_layer_mask"),_SCS("get_collision_layer_mask"));
@ -870,6 +886,7 @@ TileMap::TileMap() {
bounce=0;
mode=MODE_SQUARE;
half_offset=HALF_OFFSET_DISABLED;
body_mode=Physics2DServer::BODY_MODE_STATIC;
fp_adjust=0.01;
fp_adjust=0.01;

View File

@ -33,6 +33,7 @@
#include "scene/resources/tile_set.h"
#include "self_list.h"
#include "vset.h"
#include "servers/physics_2d_server.h"
class TileMap : public Node2D {
@ -60,6 +61,7 @@ private:
Mode mode;
Matrix32 custom_transform;
HalfOffset half_offset;
Physics2DServer::BodyMode body_mode;
union PosKey {
@ -97,14 +99,14 @@ private:
Vector2 pos;
RID canvas_item;
RID static_body;
RID body;
SelfList<Quadrant> dirty_list;
VSet<PosKey> cells;
void operator=(const Quadrant& q) { pos=q.pos; canvas_item=q.canvas_item; static_body=q.static_body; cells=q.cells; }
Quadrant(const Quadrant& q) : dirty_list(this) { pos=q.pos; canvas_item=q.canvas_item; static_body=q.static_body; cells=q.cells;}
void operator=(const Quadrant& q) { pos=q.pos; canvas_item=q.canvas_item; body=q.body; cells=q.cells; }
Quadrant(const Quadrant& q) : dirty_list(this) { pos=q.pos; canvas_item=q.canvas_item; body=q.body; cells=q.cells;}
Quadrant() : dirty_list(this) {}
};
@ -177,6 +179,9 @@ public:
void set_collision_layer_mask(uint32_t p_layer);
uint32_t get_collision_layer_mask() const;
void set_collision_body_mode(Physics2DServer::BodyMode p_body_mode);
Physics2DServer::BodyMode get_collision_body_mode() const;
void set_collision_friction(float p_friction);
float get_collision_friction() const;

View File

@ -31,6 +31,8 @@
#include "os/file_access.h"
#include "tools/editor/editor_settings.h"
#include "scene/3d/camera.h"
#include "canvas_item_editor_plugin.h"
void CollisionPolygonEditor::_notification(int p_what) {
switch(p_what) {
@ -71,14 +73,14 @@ void CollisionPolygonEditor::_node_removed(Node *p_node) {
Vector2 CollisionPolygonEditor::snap_point(const Vector2& p_point) const {
return p_point;
/*
if (canvas_item_editor->is_snap_active()) {
if (CanvasItemEditor::get_singleton()->is_snap_active()) {
return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap());
return p_point.snapped(Vector2(1,1)*CanvasItemEditor::get_singleton()->get_snap());
} else {
return p_point;
} ??? */
}
}
void CollisionPolygonEditor::_menu_option(int p_option) {
@ -148,7 +150,7 @@ bool CollisionPolygonEditor::forward_spatial_input_event(Camera* p_camera,const
Vector2 cpoint(spoint.x,spoint.y);
//cpoint=snap_point(cpoint); snap?
cpoint=snap_point(cpoint);
Vector<Vector2> poly = node->get_polygon();
@ -362,7 +364,7 @@ bool CollisionPolygonEditor::forward_spatial_input_event(Camera* p_camera,const
Vector2 cpoint(spoint.x,spoint.y);
//cpoint=snap_point(cpoint);
cpoint=snap_point(cpoint);
edited_point_pos = cpoint;
_polygon_draw();