Code Monkey home page Code Monkey logo

liquidkit's Introduction

LiquidKit

A small library for creating liquid for use with SpriteKit on iOS and OS X.

alt text

Purpose

This library is a good option for people who are using SpriteKit on iOS and want to have a small amount of liquid simulation going on in their scene. It's not a fast implementation, because it's implemented using a combination of several built-in CoreImage filters (the only option for SpriteKit on iOS, because SpriteKit effect filters must be CIFilters, and on iOS, it's not currently possible to implement a custom low-level CIFilter).

Note: If you need something fast, but you're using SpriteKit, you can now use SKShader instead of CIFilters. The introduction of this in the latest SpriteKit (at the time this was written), makes this library less relevant.

The library is also an option on OS X for people who are using SpriteKit and do not want to implement a custom low-level CIFilter.

Status

  • Capable of creating 2D liquids for use in SpriteKit.
  • Currently, the liquid effect is applied to the entire area encompassed by the LiquidNode (including empty space). In SpriteKit, an EffectNode's effect is applied to the smallest rectangle that can be drawn to encompass all of it's children. This means that if you have a single liquid particle in each corner of the screen, the filter algorithm will run for the entire screen, even though there isn't much liquid to affect. This can be optimized by only running the filter on clumps of nodes that are close enough for their blurs to interact (including single nodes). This is currently in progress.

Known Issues

  • LQKSolidColorEffect: Designating a liquid to be white causes it to be black.
  • The more space between the LiquidNode's children, the slower the simulation will be. This could be optimized as noted in Status.
  • If any nodes (liquid particles or other nodes you want the effect applied to) fall off of the screen, your simulation will lag and SpriteKit will delete the entire LiquidNode in protest. This stems from the above issue. You should probably be deleting liquid particles after a certain amount of time (seconds), which should solve the problem for most.

Usage

The following code sample shows the process of creating a liquid using LiquidKit. In this example, liquidNode can be added to a SpriteKit scene to display the liquid.

#import <LiquidKit/LiquidKit.h>
...

  /* Create a texturing strategy for the liquid -- built-in, or on your own */
  LQKSolidColorEffect *solidEffect = [[LQKSolidColorEffect alloc] initWithColor:[NSColor magentaColor] withIndex:100 withWidth:256];
  
  /* Create a liquid filter with the liquid texturing effect */
  LQKCILiquidFilter *filter = [[LQKCILiquidFilter alloc] initWithBlurRadius:30 withLiquidEffect:solidEffect];
  
  /* Create a liquid node with the liquid filter */
  SKNode *liquidNode = [[LQKLiquidNode alloc] initWithBlurRadius:30 withLiquidFilter:filter];
  
  /* Create a particle factory that can produce optimized particles of a given size */
  LQKLiquidParticleFactory *liquidParticleFactory = [[LQKLiquidParticleFactory alloc] initWithRadius:15];
  
  /* Spawn a single bead of liquid */
  SKNode *particleNode = [liquidParticleFactory createLiquidParticle];
  particleNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
  particleNode.physicsBody.density = 50;
  
  /* Add the particle to the liquid so it will adopt its visual properties */
  [liquidNode addChild:particleNode];

...

liquidkit's People

Contributors

kevinhartman avatar

Watchers

 avatar  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.