GithubHelp home page GithubHelp logo

jordo / ccwaternode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from man-in-black382/ccwaternode

0.0 0.0 0.0 8.84 MB

Cocos2D water node

Objective-C 30.65% HTML 61.21% CSS 0.24% C 3.41% C++ 0.12% MATLAB 0.04% Java 0.03% M 4.29%

ccwaternode's Introduction

Cocos2D water node

This great article (http://gamedevelopment.tutsplus.com/tutorials/make-a-splash-with-dynamic-2d-water-effects--gamedev-236) inspired me to make a CCNode that will simulate water behaviour. Water consists of springs which obeys Hooke's law. Splahses consists of particles that are drawn as metaballs.

Add CCWaterNode.h and CCWaterNode.m to your project. Then create water node and add it to CCPhysicsNode, because it has physics body for collision detection. By default water's collision type is set to "Water", but you can change it.

_water = [CCWaterNode waterNodeWithWidth:200 height:200
                                     tension:0.25 dampening:0.06 spread:0.1
                                       color:[CCColor colorWithRed:0.0 green:0.5 blue:1.0 alpha:0.8]
                                  dropsFrame:[CCSpriteFrame frameWithImageNamed: @"ccbResources/ccbParticleFire.png"]];
    
_water.positionInPoints = ccp(0, 0);
[_physicsNode addChild: _water];

Note, that you'll need to provide a sprite frame for the drops which looks like this: Alt text

In this sample project we're creating small red balls that fall on water surface. When ball hits the water, collision is detected and we're making the splash:

-(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair Ball:(CCNode *)nodeA Water:(CCNode *)nodeB
{
    [_water splash:nodeA.positionInPoints.x radius: nodeA.contentSizeInPoints.width / 2 speed: nodeA.physicsBody.velocity.y];
    [nodeA removeFromParentAndCleanup:YES];
    return NO;
}

Screenshots

For the sake of performance in simulator, water node is small Alt text

This two screenshots demonstrate how interpolation property affects the water: Alt text

Alt text

ccwaternode's People

Contributors

man-in-black382 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.