- override
Paints this node to the canvas.
Subclasses, such as Sprite
, override this method to do the actual painting of the node. To do custom
drawing override this method and make calls to the canvas
object. All drawing is done in the node's local
coordinate system, relative to the node's position. If you want to make the drawing relative to the node's
bounding box's origin, override NodeWithSize
and call the applyTransformForPivot method before making calls for
drawing.
void paint(Canvas canvas) {
canvas.save();
applyTransformForPivot(canvas);
// Do painting here
canvas.restore();
}
Source
@override void paint(Canvas canvas) { if (opacity == 0.0) return; List<RSTransform> transforms = <RSTransform>[]; List<Rect> rects = <Rect>[]; List<Color> colors = <Color>[]; _paint.transferMode = transferMode; for (_Particle particle in _particles) { // Rect Rect rect = texture.frame; rects.add(rect); // Transform double scos; double ssin; if (rotateToMovement) { double extraRotation = GameMath.atan2(particle.dir[1], particle.dir[0]); scos = math.cos(convertDegrees2Radians(particle.rotation) + extraRotation) * particle.size; ssin = math.sin(convertDegrees2Radians(particle.rotation) + extraRotation) * particle.size; } else if (particle.rotation != 0.0) { scos = math.cos(convertDegrees2Radians(particle.rotation)) * particle.size; ssin = math.sin(convertDegrees2Radians(particle.rotation)) * particle.size; } else { scos = particle.size; ssin = 0.0; } double ax = rect.width / 2; double ay = rect.height / 2; double tx = particle.pos[0] + -scos * ax + ssin * ay; double ty = particle.pos[1] + -ssin * ax - scos * ay; RSTransform transform = new RSTransform(scos, ssin, tx, ty); transforms.add(transform); // Color if (particle.simpleColorSequence != null) { Color particleColor = new Color.fromARGB( (particle.simpleColorSequence[0] * opacity).toInt().clamp(0, 255), particle.simpleColorSequence[1].toInt().clamp(0, 255), particle.simpleColorSequence[2].toInt().clamp(0, 255), particle.simpleColorSequence[3].toInt().clamp(0, 255)); colors.add(particleColor); } else { Color particleColor; if (particle.colorSequence != null) { particleColor = particle.colorSequence.colorAtPosition(particle.colorPos); } else { particleColor = colorSequence.colorAtPosition(particle.colorPos); } if (opacity != 1.0) { particleColor = particleColor.withAlpha((particleColor.alpha * opacity).toInt().clamp(0, 255)); } colors.add(particleColor); } } canvas.drawAtlas(texture.image, transforms, rects, colors, TransferMode.modulate, null, _paint); }