Commit 01ac0095 authored by Viktor Lidholt's avatar Viktor Lidholt

Updates startled in game demo to use drawAtlas

parent 0d7156fc
...@@ -562,49 +562,43 @@ class Laser extends Sprite { ...@@ -562,49 +562,43 @@ class Laser extends Sprite {
// Background starfield // Background starfield
class StarField extends Node { class StarField extends Node {
Image _image;
int _numStars; int _numStars;
List<Point> _starPositions; List<Point> _starPositions;
List<double> _starScales; List<double> _starScales;
List<double> _opacity; List<Rect> _rects;
List<Texture> _textures; List<Color> _colors;
Paint _paint = new Paint()
..setFilterQuality(sky.FilterQuality.low)
..isAntiAlias = false
..setTransferMode(sky.TransferMode.plus);
StarField(SpriteSheet spriteSheet, this._numStars) { StarField(SpriteSheet spriteSheet, this._numStars) {
_starPositions = []; _starPositions = [];
_starScales = []; _starScales = [];
_opacity = []; _colors = [];
_textures = []; _rects = [];
for (int i = 0; i < _numStars; i++) { for (int i = 0; i < _numStars; i++) {
_starPositions.add(new Point(_rand.nextDouble() * _gameSizeWidth, _rand.nextDouble() * _gameSizeHeight)); _starPositions.add(new Point(_rand.nextDouble() * _gameSizeWidth, _rand.nextDouble() * _gameSizeHeight));
_starScales.add(_rand.nextDouble()); _starScales.add(_rand.nextDouble());
_opacity.add(_rand.nextDouble() * 0.5 + 0.5); _colors.add(new Color.fromARGB((255.0 * (_rand.nextDouble() * 0.5 + 0.5)).toInt(), 255, 255, 255));
_textures.add(spriteSheet["star_${_rand.nextInt(2)}.png"]); _rects.add(spriteSheet["star_${_rand.nextInt(2)}.png"].frame);
} }
_image = spriteSheet.image;
} }
void paint(PaintingCanvas canvas) { void paint(PaintingCanvas canvas) {
// Setup paint object for opacity and transfer mode // Create a transform for each star
Paint paint = new Paint(); List<sky.RSTransform> transforms = [];
paint.setTransferMode(sky.TransferMode.plus);
double baseScaleX = 64.0 / _textures[0].size.width;
double baseScaleY = 64.0 / _textures[0].size.height;
// Draw each star
for (int i = 0; i < _numStars; i++) { for (int i = 0; i < _numStars; i++) {
Point pos = _starPositions[i]; sky.RSTransform transform = new sky.RSTransform(_starScales[i], 0.0, _starPositions[i].x, _starPositions[i].y);
double scale = _starScales[i]; transforms.add(transform);
paint.color = new Color.fromARGB((255.0*_opacity[i]).toInt(), 255, 255, 255);
canvas.save();
canvas.translate(pos.x, pos.y);
canvas.scale(baseScaleX * scale, baseScaleY * scale);
canvas.drawImageRect(_textures[i].image, _textures[i].frame, _textures[i].spriteSourceSize, paint);
canvas.restore();
} }
// Draw the stars
canvas.drawAtlas(_image, transforms, _rects, _colors, sky.TransferMode.modulate, null, _paint);
} }
void move(double dx, double dy) { void move(double dx, double dy) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment