Skip to content

badpx/ParticleAndroid

Repository files navigation

ParticleAndroid

===

A particle system for Android written in Java.

Demo Video Record:

DemoGIF

Introduction

Goals

We want to provide a lightweight particle system based on JAVA, for fast and easy integration into the Android project.

Features

  • Two emitter modes are supported: Gravity & Radius.
  • Create particle system from the plist format for cocos2d.
  • Embedded texture resource of the plist file(PNG/JPEG/BMP, but the TIFF format doesn't support yet).
  • Blend mode.

Get started

Integrate ParticleSystemView

The ParticleSystemView is a subclass of androd.view.View, It is responsible for managing the life cycle of particle emitters. It can be created directly or inflate from layout file:

Create ParticleSystemView By code

// Create ParticleSystemView by code:ParticleSystemViewparticleSystemView = newParticleSystemView(context); // Add it to your layoutrootView.addView(particleSystemView);

Create ParticleSystemView By xml

<!-- Add in a layout xml file --> <com.badpx.particleandroid.widget.ParticleSystemView android:id="@+id/particle_view"android:layout_width="match_parent"android:layout_height="match_parent"/>

Create Particle Emitter

A particle emitter must be a subclass of ParticleSystem, it can create by manual or plist file:

Create Particle Emitter By code

// Create particle emitter by manualpublicclassParticleExplosionextendsParticleSystem{publicParticleExplosion(){super()} publicParticleExplosion(intnumOfParticles){super(numOfParticles)} @Overrideprotectedvoidsetup(intnumberOfParticles){super.setup(numberOfParticles); // durationmDuration = -1f; mEmitterMode = EmitterMode.MODE_GRAVITY; // Gravity Mode: gravitymodeA.gravity = newPoint(0, 0); // Gravity Mode: speed of particlesmodeA.speed = 70; modeA.speedVar = 40; // Gravity Mode: radialmodeA.radialAccel = 0; modeA.radialAccelVar = 0; // Gravity Mode: tangentialmodeA.tangentialAccel = 0; modeA.tangentialAccelVar = 0; // anglemAngle = 90; mAngleVar = 360; mPosVar = newPoint(); // life of particlesmLife = 2.0f; mLifeVar = 1; // size, in pixelsmStartSize = 15.0f; mStartSizeVar = 10.0f; mEndSize = END_SIZE_EQUAL_TO_START_SIZE; // emits per secondmEmissionRate = mTotalParticles / mLife; // color of particlesmStartColor = Colour.argb(1.0f, 0.7f, 0.1f, 0.2f); mStartColorVar = Colour.argb(0f, 0.5f, 0.5f, 0.5f); mEndColorVar = Colour.argb(0f, 0.5f, 0.5f, 0.5f)} } // Create particle emitterParticleSystememitter = newParticleExplosion();

Create Particle Emitter By plist file

// Create particle emitter by plist fileParticleSystememitter = PListParticleSystemHelper.create(resources, plistPath/* Relative to assets directory */);

Setup emitter to ParticleSystemView

// Add one emitter to ParticleSystemViewparticleSystemView.addParticleSystem(emitter); // Start emittingemitter.startup();

Remove emitter

// Shutdown a emitteremitter.shutdown(); // Remove a emitter from ParticleSystemViewparticleSystemView.removeParticleSystem(emitter);

About

A particle system for Android written in Java.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages