Example #1
0
void RectCollider::addLayer(Layer* layer, int depth) {
    DrawNode* node = DrawNode::create();
    Vec2 origin = Vec2::ZERO;
    Vec2 dest = Vec2::ZERO;
    Vec2 cpos = Vec2::ZERO;
    if (NULL != this->behaviour) {
        BaseRenderAsset* pbra = (BaseRenderAsset*)this->behaviour->getAsset("anime");
        Transform transform = pbra->getTransform();
        cpos = transform.getPosition().vector2d;
        Size allSize = transform.getContentsScale().getAllScale();
        Size halfSize = transform.getContentsScale().getHalfScale();
        origin = Vec2(-1 * halfSize.width, -1 * halfSize.height);
        dest = Vec2(allSize.width, allSize.height);
    } else if (NULL != this->node) {
        cpos = this->node->position;
        Vec2 position = this->node->position;
        Scale* scale = this->node->scale;
        float width = scale->getHalfScale().width;
        float height = scale->getHalfScale().height;
        dest = Vec2(width, height);
    }
    node->drawRect(origin, dest, Color4F(0.0f, 1.0f, 0.0f, 0.5f));
    node->setPosition(cpos);
    layer->addChild(node, depth);
}
Example #2
0
/**
* その他UI
*/
void HelloWorld::addTalkOther(const std::string& str){
	Size size = Director::getInstance()->getVisibleSize();

	DrawNode* draw = DrawNode::create();

	int originalX = OTHER_TEXT_X;
	int originalY = size.height - (TEXT_H * (index + 1));

	int x = originalX - 10;
	int y = originalY - 60;
	int w = 300;
	int h = 60;

	Vec2 points[] = {
		Vec2(x, y),
		Vec2(x + w, y),
		Vec2(x + w, y + h),
		Vec2(x, y + h),
	};

	this->addChild(draw);
	draw->drawPolygon(points, 4, Color4F(0.5, 0, 0, 1), 1, Color4F(1, 0, 0, 1));

	auto text = Text::create(str, "fronts/arial.ttf", 40);
	text->setTextHorizontalAlignment(TextHAlignment::LEFT);
	text->setAnchorPoint(Point(0.0, 1.0));
	text->setPosition(Point(originalX, originalY));
	text->setColor(Color3B(255, 255, 0));
	this->addChild(text);
	index++;
}
bool LayerAnimationPractice04::init()
{
    if (!LayerColor::initWithColor(Color4B::GRAY))
    {
        return false;
    }
    
    Size winSize = Director::getInstance()->getWinSize();
    Button* pBtnTest = Button::create();
    pBtnTest->setTitleFontSize(40.0f);
    pBtnTest->setTitleColor(Color3B::BLACK);
    pBtnTest->setTitleText("Test");
    pBtnTest->setPosition(Vec2(winSize.width*0.5f, 40.0f));
    addChild(pBtnTest);
    pBtnTest->addClickEventListener(CC_CALLBACK_1(LayerAnimationPractice04::btnTestCallback, this));
    
    m_pNormalItem = NormalItem::create();
    m_pNormalItem->setPosition(winSize*0.5f+ITEM_SIZE);
    addChild(m_pNormalItem);
    
    for (int i=0; i<10; ++i)
    {
        DrawNode* pDrawNode = DrawNode::create();
        pDrawNode->drawRect(m_pNormalItem->getPosition()-Vec2(0.0f, i*ITEM_SIZE.height),
                            m_pNormalItem->getPosition()+ITEM_SIZE,
                            Color4F::RED);
        addChild(pDrawNode);
    }
    
    return true;
}
Example #4
0
void GameLayer::addMapBg()
{
    float width = _visibleSize.width;
    DrawNode *mapBg = DrawNode::create();
    mapBg->drawSolidRect( Vec2::ZERO , Vec2(width, width), Color4F(Color3B(190,173,158)));
    mapBg->setAnchorPoint(Vec2::ZERO);
    this->addChild(mapBg);
    
    Vec2 mapOrigin = mapBg->getPosition();
    float gap = width/33;
    float tileWidth = (width-5*gap)/4;
    
    g_tileSize = tileWidth;
    g_mapBg = mapBg;
    g_gap = gap;
    
    for(int i = 0; i < MAP_SIZE; i++)
    {
        for(int j = 0; j < MAP_SIZE; j++)
        {
            DrawNode* tileBg = DrawNode::create();
            tileBg->drawSolidRect(Vec2::ZERO, Vec2(tileWidth, tileWidth) , Color4F( Color3B(208,193,179) ));
            tileBg->setPositionX((j+1)*gap+ j*tileWidth);
            tileBg->setPositionY((i+1)*gap+ i*tileWidth);
            _map->setTilePos(3-i, j, tileBg->getPosition() + Vec2(g_tileSize/2 , g_tileSize/2));
            mapBg->addChild(tileBg);
        }
    }
    
    _map->initStart2();
}
Example #5
0
bool CardBase::ccTouchBegan(Touch* touch, Event* event)
{
	glLineWidth(16);
	ccDrawColor4B(255,0,0,255);
	Point vertices[] = { Point(0, 0), Point(50, 50), Point(100, 50), Point(100, 100) };
	ccDrawPoly(vertices, 4, true);

	//glLineWidth(16);
	//ccDrawColor4B(0, 255, 0, 255);
	//ccDrawCircle( VisibleRect::center(), 100, 0, 10, false);

	Size s = getbackGround()->getContentSize();

	DrawNode *draw = DrawNode::create();
	addChild(draw, 10);

	// Draw polygons
	Point points[] = { Point(s.height/4,0), Point(s.width,s.height/5), Point(s.width/3*2,s.height) };
	draw->drawPolygon(points, sizeof(points)/sizeof(points[0]), Color4F(1,0,0,0.5), 0, Color4F(0,0,0,0));

	// Draw segment
	//draw->drawSegment(ccp(20,s.height), ccp(20,s.height/2), 10, ccc4f(0, 1, 0, 0.5));

	//draw->drawSegment(ccp(10,s.height/2), ccp(s.width/2, s.height/2), 40, ccc4f(1, 0, 1, 0.5));

//	this->addChild(shadow);
//	addChild(shadow);

	CCLog("ccTouchBegan");
	return true;
}
Example #6
0
void MainGame::onTouchEnded(Touch* touch, Event* event)
{
    CCLOG("touch ended.");
    
    DrawNode* node = (cocos2d::DrawNode*) this->getChildByTag(100);
    node->clear();
}
static void DrawFatSegment(cpVect a, cpVect b, cpFloat r, cpSpaceDebugColor outline, cpSpaceDebugColor fill, cpDataPointer data)
{
    const Color4F outlineColor(outline.r, outline.g, outline.b, outline.a);
    DrawNode* drawNode = static_cast<DrawNode*>(data);
    drawNode->drawSegment(PhysicsHelper::cpv2point(a),
                          PhysicsHelper::cpv2point(b),
                          PhysicsHelper::cpfloat2float(r==0 ? 1 : r), outlineColor);
}
Example #8
0
void ITools::addUnderline(void* vv)
{
    Text* tt = (Text*)vv;
    Color4B color = tt->getTextColor();
    DrawNode* drawLine = DrawNode::create();
    drawLine->drawLine(Vec2(0,0), Vec2(tt->getContentSize().width,0), Color4F((float)color.r/255, (float)color.g/255, (float)color.b/255, (float)color.a/255));
    drawLine->setPosition(Vec2(0,2));
    tt->addChild(drawLine);
}
void CEAProgressBar::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) {
    this->removeAllChildren();
    DrawNode *pDN = DrawNode::create();
    this->addChild(pDN);
    Vec2 start = m_customRect.origin;
    Vec2 end = Vec2(start.x + m_customRect.size.width, start.y + m_customRect.size.height);
    Vec2 percentEnd = Vec2(start.x + m_customRect.size.width * m_percentage, start.y + m_customRect.size.height);
    pDN->drawRect(start, end, m_outlineColor);
    pDN->drawSolidRect(start, percentEnd, m_fillColor);
}
Example #10
0
void GameController::drawBorder(Node* a_node, Color4F a_color4f)
{
    float height = a_node->getContentSize().height;
    float width = a_node->getContentSize().width;
    
    DrawNode* pDrawNode = DrawNode::create();
    pDrawNode->drawRect( Vec2(0.0f, 0.0f), Vec2(width, height), a_color4f);
    
    a_node->addChild(pDrawNode, -1);
}
	void redraw()
	{
		drawNode->clear();
		vector<Unit>::iterator itor;
		for (itor = unitList.begin(); itor != unitList.end(); ++itor)
		{
			drawNode->drawCircle(itor->pos, 10, 360, 10, false, Color4F::BLUE);
			drawNode->drawLine(itor->pos, itor->pos + itor->velocity * 30, Color4F::GREEN);
		}
	}
Example #12
0
// 軌跡の描画
void BrushTrail::drawTrail( const Vec2& start, const Vec2& end )
{
	mCanvas->renderingBegin();
	
	DrawNode* drawNode { DrawNode::create() };
	drawNode->drawSegment( start, end, LINE_WIDTH, Color4F::WHITE );
	mCanvas->addRenderingTarget( drawNode );
	
	mCanvas->renderingEnd();
}
Example #13
0
	TouchPoint(const Vec2 &touchPoint, const Color3B &touchColor)
	{
		m_point = touchPoint;
		DrawNode* drawNode = DrawNode::create();
		auto s = Director::getInstance()->getWinSize();
		Color4F color(touchColor.r / 255.0f, touchColor.g / 255.0f, touchColor.b / 255.0f, 1.0f);
		drawNode->drawLine(Vec2(0, touchPoint.y), Vec2(s.width, touchPoint.y), color);
		drawNode->drawLine(Vec2(touchPoint.x, 0), Vec2(touchPoint.x, s.height), color);
		drawNode->drawDot(touchPoint, 3, color);
		addChild(drawNode);
	}
Example #14
0
void TestTouch::onTouchMoved(Touch* touch, Event* event)
{
	Point *locationInNode = &touch->getLocation();
	if (lastPoint != NULL)
	{
		DrawNode *draw = DrawNode::create();
		this->addChild(draw);	
		draw->drawSegment(Vec2(m_iLastPointX, m_iLastPointY), *locationInNode, 5, Color4F(0.5, 0.5, 0.5, 0.5));
	}
	CCLOG("TestTouch::onTouchMoved %p: %lf, %lf -->  %lf, %lf", lastPoint, m_iLastPointX, m_iLastPointY, locationInNode->x, locationInNode->y);
	m_iLastPointX = locationInNode->x;
	m_iLastPointY = locationInNode->y;
}
bool obj_dialoguer::init()  {
	if (UObject::init(obj_dialoguer::object_index)) {
		removeAllChildren();
		CC_SAFE_RELEASE_NULL(_writer);
		CC_SAFE_RELEASE_NULL(_face);
		_writer = obj_writer::create();
		CC_SAFE_RETAIN(_writer);
		_writer->setUndertaleFont(2); //generic dialog
		Size size(304 - 16, 80 - 5);

		setContentSize(size);
		DrawNode* box = DrawNode::create(3);
		box->drawSolidRect(Vec2(0, 0), size, Color4F::WHITE);
		box->drawSolidRect(Vec2(3, 3), size - Size(3, 3), Color4F::BLACK);
		//	box->drawRect(Vec2(0, 0), Vec2(304 - 16, 80 - 5), Color4F::WHITE);
		//box->setPosition(size / 2);
		box->setAnchorPoint(Vec2::ZERO);
		_writer->setAnchorPoint(Vec2::ZERO);
		addChild(box, -100);
		addChild(_writer, 100);
		_eventDispatcher->addCustomEventListener("obj_writer_halt", [this](EventCustom* e) {
			size_t halt = (size_t)e->getUserData();
		//	if (halt == 1) {
		//		this->nextDialogLine(); // key press
		//	}


		});
		_eventDispatcher->addCustomEventListener("face_change", [this](EventCustom* e) {
			size_t new_face = (size_t)e->getUserData();
			if (new_face != this->_face_index) {
				if (_face) removeChild(_face, true);
				addChild(_face = obj_face::create(new_face));
				_face->setEmotion(_emotion_index);
				reset();
				_face_index = new_face;
			}
		});
		_eventDispatcher->addCustomEventListener("emotion_change", [this](EventCustom* e) {
			size_t new_emotion = (size_t)e->getUserData();
			if (new_emotion != _emotion_index) {
				if (_face) _face->setEmotion((size_t)e->getUserData());
				_emotion_index = new_emotion;
			}
			
		});
		return true;
	}
	return false;
}
Example #16
0
DrawNode* DrawNode::create()
{
    DrawNode* pRet = new DrawNode();
    if (pRet && pRet->init())
    {
        pRet->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(pRet);
    }
    
    return pRet;
}
Example #17
0
DrawNode* DrawNode::create()
{
    DrawNode* ret = new (std::nothrow) DrawNode();
    if (ret && ret->init())
    {
        ret->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(ret);
    }
    
    return ret;
}
static void DrawPolygon(int count, const cpVect *verts, cpFloat r, cpSpaceDebugColor outline, cpSpaceDebugColor fill, cpDataPointer data)
{
    const Color4F fillColor(fill.r, fill.g, fill.b, fill.a);
    const Color4F outlineColor(outline.r, outline.g, outline.b, outline.a);
    DrawNode* drawNode = static_cast<DrawNode*>(data);
    int num = count;
    Vec2* seg = new (std::nothrow) Vec2[num];
    for(int i=0;i<num;++i)
        seg[i] = PhysicsHelper::cpv2point(verts[i]);
    
    drawNode->drawPolygon(seg, num, fillColor, 1.0f, outlineColor);
    
    delete[] seg;
}
void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) {

    Director* director = Director::getInstance();
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
    
    DrawNode* drawNode = DrawNode::create();
    
    if (_debugSlots) {
        // Slots.
        // DrawPrimitives::setDrawColor4B(0, 0, 255, 255);
        glLineWidth(1);
        Vec2 points[4];
        V3F_C4B_T2F_Quad quad;
        for (int i = 0, n = _skeleton->slotsCount; i < n; i++) {
            spSlot* slot = _skeleton->drawOrder[i];
            if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
            spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
            spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices);
            points[0] = Vec2(_worldVertices[0], _worldVertices[1]);
            points[1] = Vec2(_worldVertices[2], _worldVertices[3]);
            points[2] = Vec2(_worldVertices[4], _worldVertices[5]);
            points[3] = Vec2(_worldVertices[6], _worldVertices[7]);
            drawNode->drawPoly(points, 4, true, Color4F::BLUE);
        }
    }
    if (_debugBones) {
        // Bone lengths.
        glLineWidth(2);
        for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
            spBone *bone = _skeleton->bones[i];
            float x = bone->data->length * bone->a + bone->worldX;
            float y = bone->data->length * bone->c + bone->worldY;
            drawNode->drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y), Color4F::RED);
        }
        // Bone origins.
        auto color = Color4F::BLUE; // Root bone is blue.
        for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
            spBone *bone = _skeleton->bones[i];
            drawNode->drawPoint(Vec2(bone->worldX, bone->worldY), 4, color);
            if (i == 0) color = Color4F::GREEN;
        }
    }
    
    drawNode->draw(renderer, transform, transformFlags);
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
BallSprite *BallSprite::createParticleSprite(Node *parent ,b2World *world, b2ParticleSystem *particleSystem, b2ParticleGroup *particleGroup,const std::string& filename) {
    
    BallSprite* pInstance = (BallSprite *)Sprite::create();
    //BallSprite* pInstance = BallSprite::createBallSprite(parent,world,filename);
    pInstance->setTexture(filename);
    parent->addChild(pInstance);
    
    // 描画用ノードの作成
    DrawNode* draw = DrawNode::create();
    draw->setPosition(Vec2(0, 0));
    pInstance->addChild(draw);
    
    /* 円の描画 */
    draw->drawDot(Vec2(pInstance->getBallRadius()/2, pInstance->getBallRadius()/2), // 中心
                  pInstance->getBallRadius(),                        // 半径
                  Color4F(1, 0.5f, 0, 200)                  // 色
                  );
    
    
    particleSystem->SetRadius(getBallRadius()*1.2/PTM_RATIO);
    
    b2ParticleDef particleDef;
    
    //パーティクルの寿命
    //particleDef.lifetime = 2.0f;
    
    //particleDef.flags = b2_dynamicBody;
    particleDef.flags = b2_waterParticle;
    particleDef.flags |= b2_destructionListenerParticle;
    particleDef.color = b2ParticleColor(100,150,255,255);
    //particleDef.velocity.y = -100;
    
    //グループへのポインタを渡しておく事でそのグループ内で管理する事ができる。
    particleDef.group = particleGroup;
    particleDef.flags = b2_waterParticle;
    
   
    //void** userdata = particleSystem->GetUserDataBuffer();
    particleDef.userData = pInstance;
    particleSystem->CreateParticle(particleDef);
    
    return pInstance;

}
static void DrawCircle(cpVect p, cpFloat a, cpFloat r, cpSpaceDebugColor outline, cpSpaceDebugColor fill, cpDataPointer data)
{
    const Color4F fillColor(fill.r, fill.g, fill.b, fill.a);
    const Color4F outlineColor(outline.r, outline.g, outline.b, outline.a);
    DrawNode* drawNode = static_cast<DrawNode*>(data);
    float radius = PhysicsHelper::cpfloat2float(r);
    Vec2 centre = PhysicsHelper::cpv2point(p);
    
    static const int CIRCLE_SEG_NUM = 12;
    Vec2 seg[CIRCLE_SEG_NUM] = {};
    
    for (int i = 0; i < CIRCLE_SEG_NUM; ++i)
    {
        float angle = (float)i * M_PI / (float)CIRCLE_SEG_NUM * 2.0f;
        Vec2 d(radius * cosf(angle), radius * sinf(angle));
        seg[i] = centre + d;
    }
    drawNode->drawPolygon(seg, CIRCLE_SEG_NUM, fillColor, 1, outlineColor);
}
Example #22
0
void ClippingNode::setSquareStencil()
{
    isSquareStencil = true;
    if(getStencil() == nullptr || dynamic_cast<DrawNode*>(getStencil()) == nullptr)
    {
        setStencil(DrawNode::create());
        //addChild(getStencil()); //If you need to see what the stencil is like, for debug purpose
    }
    DrawNode* stencil = (DrawNode*)getStencil();
    stencil->clear();
    Vec2 rectangle[4];
    rectangle[0] = Vec2(0, 0);
    rectangle[1] = Vec2(this->getContentSize().width / this->getScaleX(), 0);
    rectangle[2] = Vec2(this->getContentSize().width / this->getScaleX(), this->getContentSize().height / this->getScaleY());
    rectangle[3] = Vec2(0, this->getContentSize().height / this->getScaleY());
    
    Color4F white(1, 1, 1, 1);
    stencil->drawPolygon(rectangle, 4, white, 1, white);
}
Example #23
0
 bool BlockHouse::init()
 {
     if (!Node::init())
         return false;
     
     this->firePoint = Vec2(15.f, 0.f);
     
     DrawNode *drawNode = DrawNode::create();
     addChild(drawNode);
     
     drawNode->drawSolidCircle(Vec2::ZERO, 10.f, 2 * M_PI, 64, 1, 1, Color4F::BLUE);
     drawNode->drawRect(Vec2(0, -3.f), Vec2(firePoint.x, 3.f), Color4F::BLUE);
     
     setFireable(false);
     fireTime = 0;
     
     this->scheduleUpdate();
     return true;
 }
	virtual void updateEmotion() override {
	//	if (_glasses) removeChild(_glasses);
	//	_glasses = nullptr;
		if (_emotion == 99) {
			_faceSprite->setUndertaleSprite(1986);
			setContentSize(_faceSprite->getContentSize());
			if (!_glasses) {
				addChild(_glasses = USprite::create(1989),100); // spr_face_torielglasses
				_glasses->setPosition(_glasses->getContentSize() / 2);
			}
			_emotion = 0;
		}
		else {
			switch (_emotion) {
			case 0: _faceSprite->setUndertaleSprite(1986); break;
			case 1: _faceSprite->setUndertaleSprite(2004); break;
			case 2: _faceSprite->setUndertaleSprite(1990); break;
			case 3: _faceSprite->setUndertaleSprite(1999); break;
			case 4: _faceSprite->setUndertaleSprite(2000); break;
			case 6: _faceSprite->setUndertaleSprite(1991); break;
			case 7: _faceSprite->setUndertaleSprite(1993); break;
			case 8: _faceSprite->setUndertaleSprite(1996); break;
			case 9: _faceSprite->setUndertaleSprite(1987); break;
			}
			
		}
		if (!_body) {
			addChild(_body = USprite::create(1985), -100); // "spr_face_torielbody" obj_torface.x + obj_torface.sprite_width / 2 - self.sprite_width / 2;
			Size contentSize(_body->getContentSize().width, _body->getContentSize().height + _faceSprite->getContentSize().height+9);
			setContentSize(contentSize);
			_faceSprite->setPositionY(_faceSprite->getPositionY() + 9);
			_body->setPositionY(_body->getPositionY() - 9);
	
			{// test box
				DrawNode * debug = DrawNode::create();
				Vec2 pos = getContentSize()/2;
				debug->drawRect(-pos, pos, Color4F::GREEN);
				addChild(debug, 1000);
			}
		}
	}
bool LayerAnimationStudy10::init()
{
    if (!LayerColor::initWithColor(Color4B::WHITE))
    {
        return false;
    }
    
    Size winSize = Director::getInstance()->getWinSize();
    
    Sprite* pItemSprite = Sprite::create("res/ui/coin.png");
    pItemSprite->setPosition(100.0f,300.0f);
    addChild(pItemSprite);
    
    PointArray* pPtArray = PointArray::create(10);
    pPtArray->addControlPoint(Vec2(winSize.width*0.5f, 50));
    pPtArray->addControlPoint(Vec2(winSize.width-80.0f,120));
    pPtArray->addControlPoint(Vec2(winSize.width-80,winSize.height-80));
    pPtArray->addControlPoint(Vec2(50.0f,winSize.height-80));
    pPtArray->addControlPoint(Vec2(50.0f, 120));
    pPtArray->addControlPoint(Vec2(winSize.width*0.5f, 50));
    
    int referenceCount = (int)pPtArray->getControlPoints()->size(); // 6个
    for (int i=0; i<referenceCount; ++i)
    {
        Vec2 ptItem = pPtArray->getControlPointAtIndex(i);
        createControlPoint(ptItem);
    }
    
    pItemSprite->setPosition(pPtArray->getControlPointAtIndex(0));
    
    DrawNode* pDrawNode = DrawNode::create();
    addChild(pDrawNode);
    pDrawNode->drawCatmullRom(pPtArray, 100, Color4F::GREEN);
    pDrawNode->setVisible(false);
    
    TargetedAction* pTargetAction = TargetedAction::create(pItemSprite, CatmullRomTo::create(3.0f, pPtArray));
    this->runAction(Sequence::create(DelayTime::create(1.0f), pTargetAction, nullptr));
    
    return true;
}
Example #26
0
bool GroundLayer::init()
{
	if (!CCSprite::initWithFile("DataUI/luodiantu.png"))
    {
        return false;
    }
	CCSprite* pBaxin = CCSprite::create("DataUI/baxinxiao.png");
	pBaxin->setPosition(ccp(272, 54 + instenceTarget * LUODIANBILI));
	this->addChild(pBaxin,-1);
	DataMager* pDate = DataMager::shareDataMager();
	for (size_t i = 0; i < pDate->size(); i++)
	{
		vector<CCPoint>* vecTemp = new vector<CCPoint>();
		vecTemp->push_back(ccp(0, 0));

		float x = pDate->getVelocity_xById(i)*pDate->getTimeById(i)*LUODIANBILI;
		float y = pDate->getVelocity_yById(i)*pDate->getTimeById(i)*LUODIANBILI;

		if (x>0&&y<150&&y>-150)
		{
			vecTemp->push_back(ccp(x, y));
			m_vec.push_back(vecTemp);
		}
		else
		{
			float ff = y > 0 ? 150.0f : -150.0f;
			x = ff / (y / x);
			vecTemp->push_back(ccp(x, ff * LUODIANBILI));
			m_vec.push_back(vecTemp);
		}
	}

	DrawNode* pDrawNode = DrawNode::create();
	pDrawNode->setPosition(ccp(272, 54));
	pDrawNode->setDrawPoint(m_vec);
	pDrawNode->setRotation(-90);
	this->addChild(pDrawNode);

    return true;
}
void StockShapeRenderer::InitializeGL() {
  Scene::Ptr scene = GetScene();
  ResourceManager::Ptr resources = GetResources();
  GroupNode* base_node = GetBaseNode();

  // Create a material to share among several shapes
  StockResources stock(resources);
  material_ = stock.NewMaterial(StockResources::kUniformColorLighting);
  material_->SetParam(sv::kDiffuse, 1.0, 0.5, 0.5, 1.0);
  material_->SetParam(sv::kSpecular, 1.0, 0.5, 0.5, 1.0);
  material_->SetParam(sv::kShininess, 10.0f);

  // Create a material to use for the selected shape
  select_material_ = stock.NewMaterial(StockResources::kUniformColorLighting);
  select_material_->SetParam(sv::kDiffuse, 1.0, 0.0, 1.0, 1.0);
  select_material_->SetParam(sv::kSpecular, 1.0, 0.0, 0.1, 1.0);
  select_material_->SetParam(sv::kShininess, 16.0f);

  // Create a bunch of shapes
  shapes_.push_back(scene->MakeDrawNode(base_node, stock.Cone(), material_));
  shapes_.push_back(scene->MakeDrawNode(base_node, stock.Cube(), material_));
  shapes_.push_back(scene->MakeDrawNode(base_node, stock.Cylinder(), material_));
  shapes_.push_back(scene->MakeDrawNode(base_node, stock.Sphere(), material_));

  DrawNode* axes = scene->MakeDrawNode(base_node);
  axes->Add(stock.UnitAxes());
  shapes_.push_back(axes);

  // Move the shapes so they're not all on top of each other.
  //
  // Also set the selection mask for each node so that they can be selected by
  // StockShapeSelector
  const double spacing = 2.0;
  const double x_start = - spacing * shapes_.size() / 2;
  for (size_t i = 0; i < shapes_.size(); ++i) {
    shapes_[i]->SetTranslation(x_start + i * spacing, 0, 0);
    shapes_[i]->SetSelectionMask(1);
  }
}
Example #28
0
void HelloWorld::drawPath(const std::vector<TileData*>& path)
{
    this->removeChildByName(DrawNodeStr);

    DrawNode* drawNode = DrawNode::create();

    Size mapSize = m_gamemap->getMapSize();
    Size tilesize = m_gamemap->getTileSize();
    int mapheight = mapSize.height * tilesize.height;

    int origin_x = path[0]->position().first * tilesize.width + tilesize.width / 2;
    int origin_y = path[0]->position().second * tilesize.height + tilesize.height / 2;
    Vec2 origin(origin_x, mapheight - origin_y);
    for (int index = 1; index < path.size(); ++index)
    {
        int destination_x = path[index]->position().first * tilesize.width + tilesize.width / 2;
        int destination_y = path[index]->position().second * tilesize.height + tilesize.height / 2;
        Vec2 destination(destination_x, mapheight - destination_y);
        drawNode->drawLine(origin, destination, Color4F(0.0, 1.0, 0.0, 1.0));
        origin = destination;
    }

    this->addChild(drawNode, 0, DrawNodeStr);
}
Waypoint::Waypoint(HelloWorld *theGame, const Vec2& location, Waypoint *nextWaypoint) : theGame(theGame), nextWaypoint(nextWaypoint)
{
    this->myPosition = location;
    this->setPosition(cocos2d::Vec2::ZERO);

#ifdef DRAW_DEBUG_INFO
    DrawNode *circle = DrawNode::create();
    circle->drawCircle(location, 6, 360, 30, false, Color4F::GREEN);
    this->addChild(circle);

    DrawNode *circle2 = DrawNode::create();
    circle2->drawCircle(location, 2, 360, 30, false, Color4F::GREEN);
    this->addChild(circle2);


    if (nextWaypoint) {
        DrawNode *line = DrawNode::create();
        line->drawLine(this->myPosition, nextWaypoint->myPosition, Color4F::GREEN);
        this->addChild(line);
    }
#endif

    theGame->addChild(this);
}
Example #30
0
void Sprite::debugDraw(bool on)
{
    DrawNode* draw = getChildByName<DrawNode*>("debugDraw");
    if(on)
    {
        if(!draw)
        {
            draw = DrawNode::create();
            draw->setName("debugDraw");
            addChild(draw);
        }
        draw->setVisible(true);
        draw->clear();
        //draw lines
        auto last = _polyInfo.triangles.indexCount/3;
        auto _indices = _polyInfo.triangles.indices;
        auto _verts = _polyInfo.triangles.verts;
        for(unsigned int i = 0; i < last; i++)
        {
            //draw 3 lines
            Vec3 from =_verts[_indices[i*3]].vertices;
            Vec3 to = _verts[_indices[i*3+1]].vertices;
            draw->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
            
            from =_verts[_indices[i*3+1]].vertices;
            to = _verts[_indices[i*3+2]].vertices;
            draw->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
            
            from =_verts[_indices[i*3+2]].vertices;
            to = _verts[_indices[i*3]].vertices;
            draw->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
        }
    }
    else
    {
        if(draw)
            draw->setVisible(false);
    }
}