Skip to content

Commit cabfd5e

Browse files
authored
FlxSkewedSprite: bigger hd grass graphics (#312)
* bigger hd grass graphics * fix flash
1 parent 061ad1e commit cabfd5e

File tree

5 files changed

+48
-42
lines changed

5 files changed

+48
-42
lines changed

Effects/FlxSkewedSprite/Project.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!-- ____________________________ Window Settings ___________________________ -->
1717

1818
<!--These window settings apply to all targets-->
19-
<window width="300" height="200" fps="60" background="#000000" hardware="true" vsync="false" />
19+
<window width="600" height="200" fps="60" background="#000000" hardware="true" vsync="false" />
2020

2121
<!--HTML5-specific-->
2222
<window if="html5" resizable="false" />
18.1 KB
Loading
+24-28
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
11
package;
22

3-
import flixel.addons.effects.FlxSkewedSprite;
43
import flixel.FlxG;
4+
import flixel.addons.effects.FlxSkewedSprite;
55

66
/**
77
* @author Zaphod
88
*/
99
class Grass extends FlxSkewedSprite
1010
{
11-
public var maxSkew:Float = 30;
12-
public var minSkew:Float = -30;
13-
public var skewSpeed:Float = 15;
14-
15-
var _skewDirection:Int = 1;
16-
17-
public function new(X:Float = 0, Y:Float = 0, Frame:Int = 0, StartSkew:Float = 0)
11+
static public inline var SKEW_MAX = 10;
12+
static public inline var SKEW_MIN = -30;
13+
static public inline var SKEW_FREQ = 1.3;
14+
15+
var time:Float;
16+
17+
public function new(x = 0.0, y = 0.0, frame = 0, timeOffset = 0.0)
1818
{
19-
super(X, Y);
20-
21-
loadGraphic("assets/grass.png", true, 300, 28);
22-
animation.frameIndex = Frame;
23-
19+
this.time = timeOffset * SKEW_FREQ;
20+
super(x, y);
21+
22+
if (frame < 0)
23+
loadGraphic("assets/grass.png");
24+
else
25+
{
26+
loadGraphic("assets/grass.png", true, 600, 56);
27+
animation.frameIndex = frame;
28+
}
29+
30+
origin.set(0, height);
2431
antialiasing = true;
25-
skew.x = StartSkew;
2632
}
27-
33+
2834
override public function update(elapsed:Float):Void
2935
{
3036
super.update(elapsed);
31-
32-
skew.x += _skewDirection * skewSpeed * elapsed;
33-
34-
if (skew.x > maxSkew)
35-
{
36-
skew.x = maxSkew;
37-
_skewDirection = -1;
38-
}
39-
else if (skew.x < minSkew)
40-
{
41-
skew.x = minSkew;
42-
_skewDirection = 1;
43-
}
37+
time += elapsed;
38+
39+
skew.x = SKEW_MIN + (Math.cos(time / SKEW_FREQ * Math.PI) + 1) / 2 * (SKEW_MAX - SKEW_MIN);
4440
}
4541
}

Effects/FlxSkewedSprite/source/Main.hx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class Main extends Sprite
88
public function new()
99
{
1010
super();
11-
addChild(new FlxGame(300, 200, PlayState));
11+
addChild(new FlxGame(0, 0, PlayState));
1212
}
1313
}
+22-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package;
22

33
import flixel.FlxG;
4+
import flixel.FlxSprite;
45
import flixel.FlxState;
56
import flixel.util.FlxColor;
67

@@ -12,18 +13,27 @@ class PlayState extends FlxState
1213
override public function create():Void
1314
{
1415
FlxG.mouse.visible = false;
15-
16+
1617
// Sky-colored background
17-
FlxG.cameras.bgColor = FlxColor.CYAN;
18-
19-
var grassY:Int = FlxG.height - 28;
20-
21-
var grass1:Grass = new Grass(0, grassY, 0, 0);
22-
var grass2:Grass = new Grass(0, grassY, 1, -5);
23-
var grass3:Grass = new Grass(0, grassY, 2, 5);
24-
25-
add(grass1);
26-
add(grass2);
27-
add(grass3);
18+
FlxG.cameras.bgColor = 0xFF4D9BD3;
19+
20+
var bottom = new FlxSprite();
21+
bottom.makeGraphic(FlxG.width, 5, 0xFF161b3a);
22+
bottom.y = FlxG.height - bottom.height;
23+
add(bottom);
24+
25+
var grass:Grass;
26+
27+
// add(grass = new Grass(0, 0, -1, 0));
28+
// grass.y = FlxG.height - grass.height;
29+
30+
add(grass = new Grass(0, 0, 0, 0));
31+
grass.y = bottom.y - grass.height;
32+
33+
add(grass = new Grass(0, 0, 1, -0.2));
34+
grass.y = bottom.y - grass.height;
35+
36+
add(grass = new Grass(0, 0, 2, 0.2));
37+
grass.y = bottom.y - grass.height;
2838
}
2939
}

0 commit comments

Comments
 (0)