Skip to content

Commit a0ad1cd

Browse files
committed
move packages, add openfl sample
1 parent 772696c commit a0ad1cd

24 files changed

+101
-22
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
assets
21
bin
2+
assets_gs

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# parallax
2-
WIP parallax. Openfl for now. Could be agnostic later.
2+
This can be used in a constrained parallax background. This could be used for 2d side-scrolling parallax but I haven't tested it yet.
3+
Openfl for now. Could be agnostic later.
34

45
# TODO
56
✅ simple bg scrolling
67
✅ make it configurable
78
✅ use xml config
89
✅ add parallax layer
10+
✅ sample (openfl)
911
- [ ] zoom
10-
- [ ] sample
1112
- [ ] agnostic

assets/data/parallax.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<data id="test" camX="1000" camY="250" width="4000" height="1500">
3+
<layers>
4+
<layer id="sky" depth="0">
5+
<sprite img="_11_background" />
6+
<sprite img="_11_background" x="2048" />
7+
</layer>
8+
<layer id="distant-clouds" depth="0.1">
9+
<sprite img="_09_distant_clouds1" />
10+
<sprite img="_09_distant_clouds1" x="2048" />
11+
<sprite img="_10_distant_clouds" x="300" />
12+
</layer>
13+
<layer id="clouds" depth="0.2">
14+
<sprite img="_08_clouds" x="400" />
15+
</layer>
16+
<layer id="big-clouds" depth="0.28">
17+
<sprite img="_07_huge_clouds" />
18+
<sprite img="_07_huge_clouds" x="2048" />
19+
</layer>
20+
<layer id="hills" depth="0.45">
21+
<sprite img="_06_hill2" />
22+
<sprite img="_06_hill2" x="2048" />
23+
</layer>
24+
<layer id="hills2" depth="0.5">
25+
<sprite img="_05_hill1" />
26+
<sprite img="_05_hill1" x="2048" />
27+
</layer>
28+
<layer id="brushes" depth="0.7">
29+
<sprite img="_04_bushes" />
30+
<sprite img="_04_bushes" x="2048" />
31+
</layer>
32+
<layer id="distant-trees" depth="0.75">
33+
<sprite img="_03_distant_trees" />
34+
<sprite img="_03_distant_trees" x="2048" />
35+
</layer>
36+
<layer id="trees" depth="0.95">
37+
<sprite img="_02_trees and bushes" />
38+
<sprite img="_02_trees and bushes" x="2048" />
39+
</layer>
40+
<layer id="ground" depth="1">
41+
<sprite img="_01_ground" />
42+
<sprite img="_01_ground" x="2048" />
43+
</layer>
44+
</layers>
45+
</data>

assets/img/_01_ground.png

82.5 KB
Loading

assets/img/_02_trees and bushes.png

129 KB
Loading

assets/img/_03_distant_trees.png

59.1 KB
Loading

assets/img/_04_bushes.png

31.2 KB
Loading

assets/img/_05_hill1.png

24.8 KB
Loading

assets/img/_06_hill2.png

27.1 KB
Loading

assets/img/_07_huge_clouds.png

69.1 KB
Loading

assets/img/_08_clouds.png

18.5 KB
Loading

assets/img/_09_distant_clouds1.png

17.8 KB
Loading

assets/img/_10_distant_clouds.png

20.2 KB
Loading

assets/img/_11_background.png

17.2 KB
Loading

assets/img/license.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CC0 game assets from Liz Molnar - RavenTale Studio: https://raventale.itch.io/parallax-background

parallax.hxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
<class path="C:\HaxeToolkit\haxe\lib\openfl\9,1,0\src" />
2020
<class path="C:\HaxeToolkit\haxe\lib\lime\7,9,0\src" />
2121
<class path="C:\HaxeToolkit\haxe\lib\actuate\1,8,9\src" />
22-
<class path="src" />
22+
<class path="sample" />
2323
<class path="bin\html5\haxe" />
2424
</classpaths>
2525
<!-- Build options -->
2626
<build>
27-
<option directives="openfl=9.1.0&#xA;lime=7.9.0&#xA;actuate=1.8.9&#xA;ANDROID_SETUP=true&#xA;ANDROID_NDK_ROOT=C:\Development\Android\NDK\android-ndk-r15c&#xA;howlerjs&#xA;lime-webgl&#xA;lime-dom&#xA;lime-howlerjs&#xA;lime-html5&#xA;openfl-disable-handle-error&#xA;HL_PATH=C:\Development\hl-1.10.0-win&#xA;tools=7.9.0&#xA;ANDROID_SDK=C:\Development\Android\SDK\platforms\android-26&#xA;lime-canvas&#xA;no-compilation&#xA;openfl-html5&#xA;JAVA_HOME=C:\Program Files (x86)\java\jdk1.8.0&#xA;HXCPP_COMPILE_CACHE=E:\hxcpp\cache&#xA;fdb&#xA;html5&#xA;web&#xA;html5" />
27+
<option directives="openfl=9.1.0&#xA;lime=7.9.0&#xA;actuate=1.8.9&#xA;ANDROID_SETUP=true&#xA;ANDROID_NDK_ROOT=C:\Development\Android\NDK\android-ndk-r15c&#xA;howlerjs&#xA;lime-webgl&#xA;lime-dom&#xA;lime-howlerjs&#xA;lime-html5&#xA;openfl-disable-handle-error&#xA;HL_PATH=C:\Development\hl-1.10.0-win&#xA;gs&#xA;tools=7.9.0&#xA;ANDROID_SDK=C:\Development\Android\SDK\platforms\android-26&#xA;lime-canvas&#xA;no-compilation&#xA;openfl-html5&#xA;JAVA_HOME=C:\Program Files (x86)\java\jdk1.8.0&#xA;HXCPP_COMPILE_CACHE=E:\hxcpp\cache&#xA;fdb&#xA;html5&#xA;web&#xA;html5" />
2828
<option flashStrict="False" />
2929
<option noInlineOnDebug="False" />
3030
<option mainClass="ApplicationMain" />

src/parallax/Parallax.hx renamed to parallax/Parallax.hx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ class Parallax
1919
public var id:String;
2020
/**
2121
* Main layer that allows to retrieve the bounds (width and height) of the parallax world
22+
* optional
2223
*/
2324
public var world:String;
2425
/**
2526
* Set manually the width of the parallax world or use variable `world`
27+
* optional
2628
*/
2729
public var width:Float;
2830
/**
2931
* Set manually the height of the parallax world or use variable `world`
32+
* optional
3033
*/
3134
public var height:Float;
3235
/**
@@ -37,7 +40,7 @@ class Parallax
3740
public var camera:ParallaxCamera;
3841

3942
public var speed:Int;
40-
43+
4144
public function new(id:String, world:String, cameraX:Float, cameraY:Float, speed:Int = 1 )
4245
{
4346
this.id = id;
@@ -146,7 +149,7 @@ class Parallax
146149
world.width = Std.parseFloat(_xml.att.width);
147150
if (_xml.has.height)
148151
world.height = Std.parseFloat(_xml.att.height);
149-
152+
150153
if (world.layers == null)
151154
world.layers = [];
152155

src/parallax/ParallaxCamera.hx renamed to parallax/ParallaxCamera.hx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ class ParallaxCamera
2424
public var maxZoom:Float;
2525
public var deltaZoom:Float;
2626

27+
/**
28+
*
29+
* @param x starting position of the camera
30+
* @param y starting position of the camera
31+
* @param width
32+
* @param height
33+
* @param zoom
34+
*/
2735
public function new(x:Float, y:Float, width:Float = 1920, height:Float = 1080, zoom:Float = 1)
2836
{
2937
this.originX = x;
File renamed without changes.

src/parallax/ParallaxLayer.hx renamed to parallax/ParallaxLayer.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using parallax.ParallaxHelper;
44

55
/**
66
* ...
7-
* @author Ludovic Bas - www.loudoweb.fr
7+
* @author Ludovic Bas - www.lugludum.com
88
*/
99
class ParallaxLayer
1010
{

src/parallax/ParallaxSprite.hx renamed to parallax/ParallaxSprite.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using parallax.ParallaxHelper;
44

55
/**
66
* ...
7-
* @author Ludovic Bas - www.loudoweb.fr
7+
* @author Ludovic Bas - www.lugludum.com
88
*/
99
class ParallaxSprite
1010
{

parallax/engines/OpenflHelper.hx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package parallax.engines;
2+
import openfl.display.DisplayObject;
3+
import parallax.Parallax;
4+
import parallax.ParallaxLayer;
5+
6+
/**
7+
* ...
8+
* @author Ludovic Bas - www.lugludum.com
9+
* TODO could use typedef of whatever to be used with any engines and not just openfl
10+
*/
11+
class OpenflHelper
12+
{
13+
inline public static function setWorldBounds(parallax:Parallax, layer:ParallaxLayer, container:DisplayObject ):Void
14+
{
15+
if (parallax.world != "" && layer.id == parallax.world)
16+
{
17+
parallax.width = container.width;
18+
parallax.height = container.height;
19+
parallax.world = "";//reset to avoid setting again with other image
20+
}
21+
}
22+
}

project.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@
66
<meta title="parallax" package="parallax" version="0.0.1" company="loudoweb" />
77

88
<!-- output -->
9-
<app main="Main" file="parallax" path="bin" />
9+
<app main="sample.OpenflSample" file="parallax" path="bin" />
1010

1111
<window background="#000000" fps="30" />
1212
<window width="0" height="0" unless="mobile" />
1313
<window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />
1414

1515
<!-- classpath, haxe libs -->
16-
<source path="src" />
16+
<source path="sample" />
1717
<haxelib name="openfl" />
1818
<haxelib name="actuate" />
1919

2020
<!-- assets -->
21-
<assets path="assets/img" rename="img" />
22-
<assets path="assets/data" rename="" />
21+
<assets path="assets/img" rename="img" unless="gs" />
22+
<assets path="assets/data" rename="" unless="gs" />
23+
24+
<assets path="assets_gs/img" rename="img" if="gs" />
25+
<assets path="assets_gs/data" rename="" if="gs" />
2326

2427
<!-- optimize output
2528
<haxeflag name="-dce full" /> -->

src/Main.hx renamed to sample/OpenflSample.hx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package;
1+
package sample;
22

33
import haxe.xml.Access;
44
import motion.Actuate;
@@ -12,12 +12,13 @@ import openfl.events.MouseEvent;
1212
import openfl.geom.Point;
1313
import parallax.Parallax;
1414
import parallax.ParallaxLayer;
15+
import parallax.engines.OpenflHelper;
1516

1617
/**
1718
* ...
18-
* @author Ludovic Bas - www.loudoweb.fr
19+
* @author Ludovic Bas - www.lugludum.com
1920
*/
20-
class Main extends Sprite
21+
class OpenflSample extends Sprite
2122
{
2223
var bgPos:Point;
2324
var imagePivot:Point;
@@ -58,12 +59,7 @@ class Main extends Sprite
5859
spr.x = sprite.originX;
5960
spr.y = sprite.originY;
6061
container.addChild(spr);
61-
if (parallax.world != "" && layer.id == parallax.world)
62-
{
63-
parallax.width = container.width;
64-
parallax.height = container.height;
65-
parallax.world = "";//reset to avoid setting again with other image
66-
}
62+
OpenflHelper.setWorldBounds(parallax, layer, spr);
6763
}
6864
}
6965

0 commit comments

Comments
 (0)