Skip to content

Commit 136af76

Browse files
committed
Add support for Parallax Scrolling
1 parent 9acda39 commit 136af76

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

pytiled_parser/layer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Layer:
5656
visible: bool
5757

5858
coordinates: OrderedPair = OrderedPair(0, 0)
59+
parallax_factor: OrderedPair = OrderedPair(1, 1)
5960

6061
id: Optional[int] = None
6162
size: Optional[Size] = None
@@ -195,6 +196,8 @@ class RawLayer(TypedDict):
195196
objects: List[tiled_object.RawTiledObject]
196197
offsetx: float
197198
offsety: float
199+
parallaxx: float
200+
parallaxy: float
198201
opacity: float
199202
properties: List[properties_.RawProperty]
200203
startx: int
@@ -350,6 +353,11 @@ def _get_common_attributes(raw_layer: RawLayer) -> Layer:
350353
if raw_layer.get("properties") is not None:
351354
common_attributes.properties = properties_.cast(raw_layer["properties"])
352355

356+
if raw_layer.get("parallaxx") is not None:
357+
common_attributes.parallax_factor = OrderedPair(
358+
raw_layer["parallaxx"], raw_layer["parallaxy"]
359+
)
360+
353361
return common_attributes
354362

355363

tests/test_data/layer_tests/all_layer_types/expected.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
id=1,
1111
size=common_types.Size(8, 6),
1212
offset=common_types.OrderedPair(1, 3),
13+
parallax_factor=common_types.OrderedPair(1.4, 1.3),
1314
properties={
1415
"test": "test property",
1516
},
@@ -81,6 +82,7 @@
8182
opacity=1,
8283
visible=True,
8384
id=4,
85+
parallax_factor=common_types.OrderedPair(2.3, 1.2),
8486
layers=[
8587
layer.ObjectLayer(
8688
name="Object Layer 1",
@@ -115,6 +117,7 @@
115117
opacity=1,
116118
visible=True,
117119
id=5,
120+
parallax_factor=common_types.OrderedPair(1.5, 1.2),
118121
image=Path("../../images/tile_04.png"),
119122
),
120123
]

tests/test_data/layer_tests/all_layer_types/map.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"offsetx":1,
1111
"offsety":3,
1212
"opacity":1,
13+
"parallaxx":1.4,
14+
"parallaxy":1.3,
1315
"properties":[
1416
{
1517
"name":"test",
@@ -49,6 +51,8 @@
4951
}],
5052
"name":"Group 1",
5153
"opacity":1,
54+
"parallaxx":2.3,
55+
"parallaxy":1.2,
5256
"type":"group",
5357
"visible":true,
5458
"x":0,
@@ -70,6 +74,8 @@
7074
"image":"..\/..\/images\/tile_04.png",
7175
"name":"Image Layer 2",
7276
"opacity":1,
77+
"parallaxx":1.5,
78+
"parallaxy":1.2,
7379
"type":"imagelayer",
7480
"visible":true,
7581
"x":0,
@@ -79,7 +85,7 @@
7985
"nextobjectid":3,
8086
"orientation":"orthogonal",
8187
"renderorder":"right-down",
82-
"tiledversion":"1.4.1",
88+
"tiledversion":"1.5.0",
8389
"tileheight":32,
8490
"tilesets":[
8591
{
@@ -88,6 +94,6 @@
8894
}],
8995
"tilewidth":32,
9096
"type":"map",
91-
"version":1.4,
97+
"version":1.5,
9298
"width":8
9399
}

0 commit comments

Comments
 (0)