#include "HelloWorld.h" USING_NS_CC; bool HelloWorld::init() { if ( !Scene::init() ) return false; // Init graphics object m_graphics.init( this ); this->scheduleUpdate(); return true; } void HelloWorld::update( float dt ) { // Get stage size auto size = Director::getInstance()->getVisibleSize(); int width = size.width; int height = size.height; // Clear the old lines & fills m_graphics.clear(); m_graphics.lineStyle( 1, 0x0000FFFF ); m_graphics.beginFill( 0x0000FF7F ); // Timer for animation static float t = 0.0f; // Flag to use moveTo(x,y) for the first node bool bFirst = true; // Remember start coordinate for closing the shape float firstX, firstY; float x1 = 0; float x2 = width; float y1 = height - 100; // Current draw coordinate float _x, _y; for ( _x = x1; _x < x2; _x += 15.0f ) { _y = (int)(y1 + sinf( (_x)*0.05f + t ) * (cos( t + _x * 0.007f ) * 15.0f)); if ( bFirst == false ) m_graphics.lineTo( _x, _y ); else { firstX = _x; firstY = _y; m_graphics.moveTo( _x, _y ); bFirst = false; } } m_graphics.lineTo( x2, _y ); m_graphics.lineTo( x2, height ); m_graphics.lineTo( x1, height ); m_graphics.lineTo( firstX, firstY - 1 ); // Fill polygon m_graphics.endFill(); t += 0.06f; } ///////////////////////////////// Scene* HelloWorld::createScene() { return HelloWorld::create(); }