Exemplo n.º 1
0
void ActionEllipse::update(float dt)
{  //t [0, 1]
	
	if (_target){
		float x = getEllipsePositionX(dt);
		float y = getEllipsePositionY(dt);
		Point newPosition = _config.center + Point(x, y);
		//由于我们画计算出的椭圆你做值是以原点为中心的,所以需要加上我们设定的中心点坐标
		_target->setPosition(_config.center + Point(x, y));

		if (dt <= 0.5){
			_target->setLocalZOrder(_config.zOrder.first);
		}
		else{
			_target->setLocalZOrder(_config.zOrder.second);
		}

#if 0
		CCDrawNode *node = CCDrawNode::create();
		node->drawDot(newPosition, 0.5f, ccc4f(17, 128,18, 60));
		_target->getParent()->addChild(node);
#endif

	}



}
// DrawNodeTest
DrawNodeTest::DrawNodeTest()
{
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCDrawNode *draw = CCDrawNode::create();
    addChild(draw, 10);
    
    // Draw 10 circles
    for( int i=0; i < 10; i++)
    {
        draw->drawDot(ccp(s.width/2, s.height/2), 10*(10-i), ccc4f(CCRAScutOM_0_1(), CCRAScutOM_0_1(), CCRAScutOM_0_1(), 1));
    }
    
    // Draw polygons
    CCPoint points[] = { CCPoint(s.height/4,0), CCPoint(s.width,s.height/5), CCPoint(s.width/3*2,s.height) };
    draw->drawPolygon(points, sizeof(points)/sizeof(points[0]), ccc4f(1,0,0,0.5), 4, ccc4f(0,0,1,1));
    
    // star poly (triggers buggs)
    {
        const float o=80;
        const float w=20;
        const float h=50;
        CCPoint star[] = {
            CCPoint(o+w,o-h), CCPoint(o+w*2, o),						// lower spike
            CCPoint(o + w*2 + h, o+w ), CCPoint(o + w*2, o+w*2),		// right spike
            //				{o +w, o+w*2+h}, {o,o+w*2},					// top spike
            //				{o -h, o+w}, {o,o},							// left spike
        };
        
        draw->drawPolygon(star, sizeof(star)/sizeof(star[0]), ccc4f(1,0,0,0.5), 1, ccc4f(0,0,1,1));
    }
    
    // star poly (doesn't trigger bug... order is important un tesselation is supported.
    {
        const float o=180;
        const float w=20;
        const float h=50;
        CCPoint star[] = {
            CCPoint(o,o), CCPoint(o+w,o-h), CCPoint(o+w*2, o),		// lower spike
            CCPoint(o + w*2 + h, o+w ), CCPoint(o + w*2, o+w*2),	// right spike
            CCPoint(o +w, o+w*2+h), CCPoint(o,o+w*2),				// top spike
            CCPoint(o -h, o+w),                                     // left spike
        };
        
        draw->drawPolygon(star, sizeof(star)/sizeof(star[0]), ccc4f(1,0,0,0.5), 1, ccc4f(0,0,1,1));
    }
    
    
    // Draw segment
    draw->drawSegment(ccp(20,s.height), ccp(20,s.height/2), 10, ccc4f(0, 1, 0, 1));

    draw->drawSegment(ccp(10,s.height/2), ccp(s.width/2, s.height/2), 40, ccc4f(1, 0, 1, 0.5));
}
Exemplo n.º 3
0
MathUtilTest::MathUtilTest(void)
{

	CCPoint a = ccp(339.95, 117.1);
	CCPoint b = ccp(411.15, 190.1);
	CCPoint c = ccp(325.05, 273.8);
	CCPoint d = ccp(253.95, 200.7);
	CCPoint p = ccp(310, 250);

	CCDrawNode* node = CCDrawNode::create();
	node->drawDot(a, 5, ColorUtil::getColor4F(0xFF, 0x00, 0x00, 0xFF));
	node->drawDot(b, 5, ColorUtil::getColor4F(0xFF, 0x00, 0x00, 0xFF));
	node->drawDot(c, 5, ColorUtil::getColor4F(0xFF, 0x00, 0x00, 0xFF));
	node->drawDot(d, 5, ColorUtil::getColor4F(0xFF, 0x00, 0x00, 0xFF));
	node->drawDot(p, 5, ColorUtil::getColor4F(0xFF, 0xCC, 0x00, 0xFF));

	this->addChild(node);

	//CCLOG("%d", MathUtil::isInsideTriangle(a, b, c, p));
	CCLOG("%d", MathUtil::isInsideSquare(a, b, c, d, p));

}
Exemplo n.º 4
0
    virtual bool init()
    {
        if ( CCNode::init() == false ) {
            return false;
        }
        
        objSize_    = CCSizeMake(120, 120);

        CCDrawNode* pTestDraw   = CCDrawNode::create();
        pTestDraw->drawDot(ccp(0,0), objSize_.width * 0.5f, ccc4FFromccc4B(ccc4(128, 0, 0, 230)));
        
        addChild(pTestDraw);
        
        return true;
    }
Exemplo n.º 5
0
    virtual bool init()
    {
        if ( CCNode::init() == false ) {
            return false;
        }
        
        objSize_    = CCSizeMake(60, 60);

        //  テスト描画用
        {
            CCDrawNode* pTestDraw  = CCDrawNode::create();
            pTestDraw->drawDot(ccp(0,0), objSize_.width * 0.5f, ccc4FFromccc4B(ccc4(255, 255, 255, 128)));
            addChild(pTestDraw);
        }

        return true;
    }
bool BackgroundManager::init()
{
	if ( !CCNode::init() )
    {
        return false;
    }

	setContentSize(CCSizeMake(SCREEN_SIZE.width * 1.2f, SCREEN_SIZE.height * 1.2f));

	CCDrawNode* star = CCDrawNode::create();
	addChild(star);

	for(int i = 0; i < MAX_STARS; ++i)
	{
		CCPoint position = ccp(CCRANDOM_0_1() * SCREEN_SIZE.width * 1.2f, CCRANDOM_0_1() * SCREEN_SIZE.height * 1.2f);
		float alpha = 0.25f + CCRANDOM_0_1() * 0.75f;
		star->drawDot(position, 1, ccc4f(1, 1, 1, alpha));
	}

	return true;
}