Coder Social home page Coder Social logo

confettiwithspriteview's Introduction

ConfettiWithSpriteView

A SwiftUI confetti modifier created by SpriteKit.

Preview

Installation

In Xcode go to File -> Swift Packages -> Add Package Dependency and paste in the repo's url:

https://github.com/VIkill33/ConfettiWithSpriteView.git

Or you can download the code of this repo, then Add Local... in Xcode, and open the folder of the repo.

Usage

  • Import this package after you installed by import ConfettiWithSpriteKit
  • Use the modifier like(check it out in DemoAPP inside this package)
struct ContentView: View {
    
    @State private var startConfetti = false
    
    var body: some View {
        ZStack {
            Button("Start/Stop") {
                startConfetti.toggle()
            }
            .confetti(start: $startConfetti)
        }
    }
}

When you change the passed var startConfetti to true, confetti will play above your modified view(confetti will NOT handle touch events and will pass them to views underit), and false will stop emitting more confetti.

The var need to be changed to false then true to retrigger the confetti.

Parameters

You can custom colors and images of confetti.

All descriptions about parameters were written in comment in source code:

    /// - Parameters:
    ///   - start: A binding to a boolean value that controls the emission of confetti.
    ///   - angle: The angle at which the confetti will be emitted, measured in radians. Default is pi/2 (90 degrees).
    ///   - colors: An array of `UIColor` values representing the colors of the confetti. Default includes red, green, system teal, yellow, orange, and purple.
    ///   - size: The size of each confetti piece. Default is 25x25 points.
    ///   - scale: The initial scale of the confetti particles. Default is 0.3.
    ///   - numToEmitRange: A closed range of integers specifying the number of particles to emit. Default range is 10 to 20.
    ///   - images: An array of `UIImage` objects representing the images for the confetti. Default includes a ribbon image.

How does it work

It use SKEmitterNode in SpriteKit to emit particles, which are ribbons in this package defaultly. Particles of SKEmitterNode behave similarly to CAEmitterLayer's. This repo is also an example about how to create SKEmitterNodes programmaticaly.

confettiwithspriteview's People

Contributors

vikill33 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.