Add support for Parallax Scrolling

This commit is contained in:
Darren Eberly
2021-03-31 20:26:55 -04:00
parent 9acda39a5d
commit 136af7692f
3 changed files with 19 additions and 2 deletions

View File

@@ -56,6 +56,7 @@ class Layer:
visible: bool
coordinates: OrderedPair = OrderedPair(0, 0)
parallax_factor: OrderedPair = OrderedPair(1, 1)
id: Optional[int] = None
size: Optional[Size] = None
@@ -195,6 +196,8 @@ class RawLayer(TypedDict):
objects: List[tiled_object.RawTiledObject]
offsetx: float
offsety: float
parallaxx: float
parallaxy: float
opacity: float
properties: List[properties_.RawProperty]
startx: int
@@ -350,6 +353,11 @@ def _get_common_attributes(raw_layer: RawLayer) -> Layer:
if raw_layer.get("properties") is not None:
common_attributes.properties = properties_.cast(raw_layer["properties"])
if raw_layer.get("parallaxx") is not None:
common_attributes.parallax_factor = OrderedPair(
raw_layer["parallaxx"], raw_layer["parallaxy"]
)
return common_attributes

View File

@@ -10,6 +10,7 @@ EXPECTED = [
id=1,
size=common_types.Size(8, 6),
offset=common_types.OrderedPair(1, 3),
parallax_factor=common_types.OrderedPair(1.4, 1.3),
properties={
"test": "test property",
},
@@ -81,6 +82,7 @@ EXPECTED = [
opacity=1,
visible=True,
id=4,
parallax_factor=common_types.OrderedPair(2.3, 1.2),
layers=[
layer.ObjectLayer(
name="Object Layer 1",
@@ -115,6 +117,7 @@ EXPECTED = [
opacity=1,
visible=True,
id=5,
parallax_factor=common_types.OrderedPair(1.5, 1.2),
image=Path("../../images/tile_04.png"),
),
]

View File

@@ -10,6 +10,8 @@
"offsetx":1,
"offsety":3,
"opacity":1,
"parallaxx":1.4,
"parallaxy":1.3,
"properties":[
{
"name":"test",
@@ -49,6 +51,8 @@
}],
"name":"Group 1",
"opacity":1,
"parallaxx":2.3,
"parallaxy":1.2,
"type":"group",
"visible":true,
"x":0,
@@ -70,6 +74,8 @@
"image":"..\/..\/images\/tile_04.png",
"name":"Image Layer 2",
"opacity":1,
"parallaxx":1.5,
"parallaxy":1.2,
"type":"imagelayer",
"visible":true,
"x":0,
@@ -79,7 +85,7 @@
"nextobjectid":3,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.4.1",
"tiledversion":"1.5.0",
"tileheight":32,
"tilesets":[
{
@@ -88,6 +94,6 @@
}],
"tilewidth":32,
"type":"map",
"version":1.4,
"version":1.5,
"width":8
}