void CameraFrameBufferTest::onEnter() { auto sizeInpixels = Director::getInstance()->getWinSizeInPixels(); auto size = Director::getInstance()->getWinSize(); auto fboSize = Size(sizeInpixels.width * 1, sizeInpixels.height * 1.5); auto fbo = experimental::FrameBuffer::create(1, fboSize.width, fboSize.height); CameraBaseTest::onEnter(); //auto sprite = Sprite::createWithTexture(fbo); //sprite->setPosition(Vec2(100,100)); //std::string filename = "Sprite3DTest/girl.c3b"; //auto sprite = Sprite3D::create(filename); //sprite->setScale(1.0); //auto animation = Animation3D::create(filename); //if (animation) //{ // auto animate = Animate3D::create(animation); // sprite->runAction(RepeatForever::create(animate)); //} //sprite->setPosition(Vec2(100,100)); auto rt = experimental::RenderTarget::create(fboSize.width, fboSize.height); auto rtDS = experimental::RenderTargetDepthStencil::create(fboSize.width, fboSize.height); fbo->attachRenderTarget(rt); fbo->attachDepthStencilTarget(rtDS); auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture()); sprite->setScale(0.3); sprite->runAction(RepeatForever::create(RotateBy::create(1, 90))); sprite->setPosition(size.width/2, size.height/2); addChild(sprite); auto sprite2 = Sprite::create(s_pathGrossini); sprite2->setPosition(Vec2(size.width/5,size.height/5)); addChild(sprite2); sprite2->setCameraMask((unsigned short)CameraFlag::USER1); auto move = MoveBy::create(1.0, Vec2(100,100)); sprite2->runAction( RepeatForever::create( Sequence::createWithTwoActions( move, move->reverse()) ) ); auto camera = Camera::create(); camera->setCameraFlag(CameraFlag::USER1); camera->setDepth(-1); camera->setFrameBufferObject(fbo); fbo->setClearColor(Color4F(1,1,1,1)); addChild(camera); }
void LHBox2dDebug::DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) { const float32 k_segments = 16.0f; int vertexCount=16; const float32 k_increment = 2.0f * b2_pi / k_segments; float32 theta = 0.0f; Vec2* vertices = new Vec2[vertexCount]; for (int32 i = 0; i < k_segments; ++i) { b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta)); vertices[i] = Vec2(v.x*mRatio, v.y*mRatio); theta += k_increment; } Color4F fillColor = Color4F(color.r, color.g, color.b, 0.5); Color4F borderColor = Color4F(color.r, color.g, color.b, 1); drawNode->drawPolygon(vertices, vertexCount, fillColor, 1, borderColor); delete[] vertices; }
bool GamePanel::onTouchBegan(Touch* touch, Event* event){ //CALCULATION startLoc = touch->getLocation(); //DRAW BEGIN POINT pen->drawSolidCircle(startLoc, 70.0f, 0.0f, 100, Color4F(1, 0, 0, 0.1f)); //PLAYER CHANGE SPRITE player->readyToJump(Vec2(0, 0)); //DEBUG* auto para = player->getParent()->getParent(); char str[100] = { 0 }; sprintf(str, "Began: (%d, %d) %s", (int)(startLoc.x), (int)(startLoc.y), para->getName().c_str()); debugLabel->setString(str); return true; }
bool UT_Map::init(){ if(!Layer::init()){ return false; } //seeds the random number generator srand((unsigned int)time(nullptr)); visibleSize = Director::getInstance()->getVisibleSize(); origin = Director::getInstance()->getVisibleOrigin(); //create wall //If Full Paint FPS Droped to 12 // test_map = new GameMap(); test_map->BuildMap("res/map/block_01.jpg" , Size(18, 10), (int)PhysicsCategory::Wall, (int)PhysicsCategory::None, (int)PhysicsCategory::Player); this->addChild(test_map); log("GetPlayerPos() ? (%f, %f)",test_map->GetPlayerPos().x , test_map->GetPlayerPos().y); //create wall crasher if(true){ body = cocos2d::DrawNode::create(); body->drawSolidRect(Vec2(0,0), Vec2(10,25), Color4F(0.1, 0, 1, 1)); body->setPosition(test_map->GetPlayerPos()); test_map->addChild(body); body->setName("Player_body"); body->setZOrder(1); auto body_phyBody = PhysicsBody::createBox(Size(body->getContentSize().width , body->getContentSize().height),PhysicsMaterial(0.1f, 1.0f, 0.0f)); body_phyBody->setDynamic(true); body_phyBody->setCategoryBitmask((int)PhysicsCategory::Player); body_phyBody->setCollisionBitmask((int)PhysicsCategory::None); body_phyBody->setContactTestBitmask((int)PhysicsCategory::Wall); body->setPhysicsBody(body_phyBody); } this->schedule(schedule_selector(UT_Map::Scheduler)); //Set the Physics Collision notification auto contactListener = EventListenerPhysicsContact::create(); contactListener->onContactBegin = CC_CALLBACK_1(UT_Map::onContactBegan, this); this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener, this); return true; }
void taskMgr::ShowMainTask(PMission task) { if(m_openMain||m_openSaml) { return; } m_openMain = true; maskLayer = DrawNode::create(); maskLayer->drawSolidRect(Vec2(-7000, -7000), Vec2(7000, 7000), Color4F(0, 0, 0, 0.6)); G_MainGame->m_UILayer->addChild(maskLayer, 99); AddBg(0,task); auto btnClose = MenuItemImage::create("ccb/ccbResources/common/close.png","ccb/ccbResources/common/close.png",[&](Ref* Sender){ BUBBLE; this->CloseMissInfo(); }); Menu *menu; MenuItemImage *m_btn; Sprite* getBtnPic=Sprite::create(); if(task->missState != task->missNeed) { // no com m_btn = MenuItemImage::create("ccb/ccbResources/common/lButton_down.png","",[&](Ref* Sender){ }); getBtnPic->setTexture("images/Word/get_award_gray.png"); } else { m_btn = MenuItemImage::create("ccb/ccbResources/common/lButton_up.png","",[=](Ref* Sender){ LoseMission(0); if(task->rewardType == 0) { Player::getInstance()->AddGold(task->rewardnum); } task->missState = 999999; this->CloseMissInfo(); }); getBtnPic->setTexture("images/Word/get_award.png"); } menu = Menu::create(btnClose,m_btn,nullptr); m_ui->addChild(menu); m_ui->addChild(getBtnPic); menu->setPosition(0,0); btnClose->setPosition(Vec2(210, 180)); m_btn->setPosition(Vec2(0, -150)); getBtnPic->setPosition(Vec2(0, -150)); }
void GamePanel::onTouchMoved(Touch* touch, Event* event){ //CALCULATION endLoc = touch->getLocation(); auto dist = endLoc.distance(startLoc); float deltaX = startLoc.x - endLoc.x; float deltaY = startLoc.y - endLoc.y; //DRAW DISTANCE pen->clear(); pen->drawSolidCircle(startLoc, 70.0f, 0.0f, 100, Color4F(1, 0, 0, 0.1f)); pen->drawSolidCircle(endLoc, 30.0f, 0.0f, 100, Color4F(0, 1, 0, 0.1f)); //PLAYER CHANGE SPRITE player->readyToJump(Vec2(deltaX, deltaY)); //DEBUG* auto diff = touch->getDelta(); auto para = (ParallaxNode*) (player->getParent()->getParent()); auto map = para->getChildByName("Map"); auto currentPos = para->getPosition(); //para->setPosition(currentPos + diff); pen->drawSolidCircle(currentPos, 30.0f, 0.0f, 100, Color4F(0, 0, 1, 0.1f)); char str[100] = { 0 }; sprintf(str, "Moved: (%d, %d) %s", (int)(startLoc.x), (int)(startLoc.y), map->getName().c_str()); debugLabel->setString(str); }
FrameBuffer::FrameBuffer() : _clearColor(Color4F(0, 0, 0, 1)) , _clearDepth(1.0) , _clearStencil(0) , _fbo(0) , _rt(nullptr) , _rtDepthStencil(nullptr) , _fboBindingDirty(true) , _isDefault(false) #if CC_ENABLE_CACHE_TEXTURE_DATA , _dirtyFBOListener(nullptr) #endif { _frameBuffers.insert(this); }
void LabelAtlas::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { AtlasNode::draw(renderer, transform, transformUpdated); _debugDrawNode->clear(); auto size = getContentSize(); Vec2 vertices[4]= { Vec2::ZERO, Vec2(size.width, 0), Vec2(size.width, size.height), Vec2(0, size.height) }; _debugDrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0)); }
bool Lander::init() { if (!Node::init()) { return false; } _landerBody = DrawNode::create(); addChild(_landerBody); Vec2 landerVecs[] = { Vec2(-20, 0), Vec2(-15, 10), Vec2(-13, 10), Vec2(-10, 15), Vec2(10, 15), Vec2(13, 10), Vec2(15, 10), Vec2(20, 0), }; _landerBody->drawPoly(landerVecs, 8, true, Color4F(1.f, 0.f, 1.f, 1.f)); _fire = DrawNode::create(); addChild(_fire); _fire->drawTriangle(Vec2(-6, 0), Vec2(6, 0), Vec2(0, -8), Color4F(1.f, 1.f, 0.f, 0.5f)); _fire->setVisible(false); _fitnessScore = -999999.f; _velocity = Vec2::ZERO; _actionFlag = NONE; _mass = LANDER_MASS; _tickCount = 0; _bLandOver = false; _bLandOK = false; _bCtrlByHuman = false; return true;; }
void PauseLayer::AddSpriteBorder(MenuItemImage *sp) { auto drawNode = DrawNode::create(); auto p = sp->getPosition(); Size s = Director::getInstance()->getVisibleSize(); Vec2 ps[4] = { Vec2(p.x - s.width*0.13, p.y - s.height*0.04), Vec2(p.x + s.width*0.13, p.y - s.height*0.04), Vec2(p.x + s.width*0.13, p.y + s.height*0.04), Vec2(p.x - s.width*0.13, p.y + s.height*0.04), }; drawNode->drawPoly(ps, 4, true, Color4F(1.0, 1.0, 1.0, 1.0)); this->addChild(drawNode); }
Color4F HelloWorld::randomBrightColor() { while (true) { float requiredBrightness = 192; Color4B randomColor = Color4B(rand() % 255, rand() % 255, rand() % 255, 255); if (randomColor.r > requiredBrightness || randomColor.g > requiredBrightness || randomColor.b > requiredBrightness) { return Color4F(randomColor); } } }
void OBBTest::update(float dt) { if (_pick) return; _drawAABB->clear(); Mat4 mat = Mat4::IDENTITY; mat.rotate(Vec3::UNIT_Y, 0.01f); _obb.transform(mat); Vec3 corners[8] = {}; _obb.getCorners(corners); _drawAABB->setPosition3D(_obb._center); _drawAABB->drawCube(corners, Color4F(0,0,1,1)); }
void Player::update(float delta) { auto c = Coordinate::getInstance(); this->velocity.y += this->acceleration * this->direction; this->point += this->velocity; this->prevPoints.push_back(this->point); if (this->prevPoints.size() > 50) this->prevPoints.pop_front(); int i = 0; for (auto p : this->prevPoints) { this->raw_points[i++] = c->logical2physical(p); } this->node->clear(); this->node->drawPoly(this->raw_points, (unsigned)this->prevPoints.size(), false, Color4F(1, 1, 1, 1)); }
void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) { setClearColor(Color4F(r, g, b, a)); setClearDepth(depthValue); setClearStencil(stencilValue); setClearFlags(flags); this->begin(); //clear screen _beginWithClearCommand.init(_globalZOrder); _beginWithClearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this); Director::getInstance()->getRenderer()->addCommand(&_beginWithClearCommand); }
Node::Node() : _Zorder(0), _pParent(nullptr), _Pos(Point::ZERO), _AnchorPoint(Point::ANCHOR_MIDDLE), _Center(Point::ZERO), _Scale(Point(1, 1)), _CollisionRect(Rect(0, 0, 0, 0)), _Size(Size::ZERO), _Color4F(Color4F(254, 254, 254, 254)), _d3dColor(D3DCOLOR_RGBA(254,254,254,254)), _RotAngle(0), _Visible(true)//, //_IsRunningAction(false) { _ChildPool.reserve(5); }
void ClippingNode::drawFullScreenQuadClearStencil() { kmGLMatrixMode(KM_GL_MODELVIEW); kmGLPushMatrix(); kmGLLoadIdentity(); kmGLMatrixMode(KM_GL_PROJECTION); kmGLPushMatrix(); kmGLLoadIdentity(); DrawPrimitives::drawSolidRect(Point(-1,-1), Point(1,1), Color4F(1, 1, 1, 1)); kmGLMatrixMode(KM_GL_PROJECTION); kmGLPopMatrix(); kmGLMatrixMode(KM_GL_MODELVIEW); kmGLPopMatrix(); }
NS_CC_EXT_BEGIN PathRenderingPaint::PathRenderingPaint (PaintType type) : _paintType(type), _paintColor(Color4F(0, 0, 0, 0)), _colorRampSpreadMode(PAINT_COLOR_RAMP_SPREAD_PAD), _isDirty(true), _gradientImage(nullptr) { for (int i = 0; i < 4; i++) _paintLinearGradient[i] = 0; for (int i = 0; i < 5; i++) _paintRadialGradient[i] = 0; for (int i = 0; i < 6; i++) _paint2x3Gradient[i] = 0; }
bool SimpleButton::init(){ if(!Node::init()){ return false; } //两个叠在一起的正六边形 auto bg1 = Hexagon::create(_sideLen, BG_COLOR_4F); this->addChild(bg1); auto bg2 = Hexagon::create(_sideLen * 0.8, Color4F(1, 0.75f, 0.14f, 1)); this->addChild(bg2); //按钮中间的文字 auto lblContent = Label::createWithSystemFont(_content, "黑体", 32); lblContent->setPosition(Point::ZERO); this->addChild(lblContent); //触摸的监听事件 _eventListener = EventListenerTouchOneByOne::create(); //_eventListener->setSwallowTouches(true); //C++11的lambda _eventListener->onTouchBegan = [=](Touch * tou, Event * evt){ auto target = static_cast<Node *>(evt->getCurrentTarget()); Point locatioInNode = target->convertToNodeSpace(tou->getLocation()); //判断是否点击,自己处理碰撞检测((⊙o⊙)…应该是触摸)中按钮,点击中放大 if(bg1->hitCheckPoint(locatioInNode)){ target->setScale(1.1f); } return true; }; //触摸结束 _eventListener->onTouchEnded = [=](Touch * tou, Event * evt){ auto target = static_cast<Node *>(evt->getCurrentTarget()); Point locatioInNode = target->convertToNodeSpace(tou->getLocation()); target->setScale(1.0f); if(bg1->hitCheckPoint(locatioInNode)){ _callback(this); } }; _eventDispatcher->addEventListenerWithSceneGraphPriority(_eventListener, this); return true; }
void StayingBlobSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t transformFlags) { if(_bodies.size() == 0)return; Vec2 vertices[NUM_SEGMENTS]; Vec2 opos = this->getPosition(); for(int i = 0; i < _bodies.size(); i++) { b2PolygonShape *shape = (b2PolygonShape *) _bodies[i]->GetFixtureList()->GetShape(); b2Vec2 point; if(i < NUM_SEGMENTS / 4) point = _bodies[i]->GetWorldVector(shape->GetVertex(0)); else if(i < NUM_SEGMENTS * 2/4) point = _bodies[i]->GetWorldVector(shape->GetVertex(1)); else if(i < NUM_SEGMENTS * 3/4) point = _bodies[i]->GetWorldVector(shape->GetVertex(2)); else if(i < NUM_SEGMENTS) point = _bodies[i]->GetWorldVector(shape->GetVertex(3)); b2Vec2 pos = _bodies[i]->GetPosition(); vertices[i].x = (point.x + pos.x)*PTM_RATIO - opos.x; vertices[i].y = (point.y + pos.y)*PTM_RATIO - opos.y; } Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); //glLineWidth( 5.0f ); //ccDrawColor4F(1.f, 0.125f, 0.15625f, 1); // tiny side burns (...Guesss that one way to call it) // for(int i = 0; i < _bodies.size(); i++) { // Vec2 target = (center - vertices[i]) * nub_pos; // target += center; // DrawPrimitives::drawSolidCircle(vertices[i], nub_size, CC_DEGREES_TO_RADIANS(360), 30); // } // draw the body //DrawPrimitives::drawSolidPoly(vertices, NUM_SEGMENTS, blobColor); DrawPrimitives::drawSolidPoly(vertices, NUM_SEGMENTS, Color4F(1, 1, 1, 1)); _face->setPosition(this->getCenter() + Vec2(-30, -100)*_face->getScale()); updateEye(); CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void ClippingNode::drawFullScreenQuadClearStencil() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); DrawPrimitives::drawSolidRect(Vec2(-1,-1), Vec2(1,1), Color4F(1, 1, 1, 1)); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
//void City_layer::create_human1(Vec3 pos,float scale) //{ // // // // auto sprite = Sprite3D::create(name+".obj"); // sprite->setScale(scale); // sprite->setTexture(TextureName); // sprite->setRotation3D(rotate); // this->addChild(sprite); // sprite->setPosition3D(pos); // sprite->setCameraMask(2); // // Vec3 corners[8]={}; // AABB aabbsp1=sprite->getAABB(); // aabbsp1.getCorners(corners); // _aabb.push_back(aabbsp1); // node1->drawCube(corners, Color4F(0,0,1,1)); // // //} void City_layer::update(float dt){ node1->clear(); Vec3 corners[8]={}; if(selected){ AABB aabbsp1=selected->getAABB(); aabbsp1.getCorners(corners); node1->drawCube(corners, Color4F(1,0,0,1)); } // for (auto obj :vecObj) { // Vec3 corners[8]={}; // AABB aabbsp1=obj->getAABB(); // aabbsp1.getCorners(corners); // node1->drawCube(corners, Color4F(0,0,1,1)); // } }
void RawStencilBufferTest::draw() { auto winPoint = Point(Director::getInstance()->getWinSize()); auto planeSize = winPoint * (1.0 / _planeCount); glEnable(GL_STENCIL_TEST); CHECK_GL_ERROR_DEBUG(); for (int i = 0; i < _planeCount; i++) { auto stencilPoint = planeSize * (_planeCount - i); stencilPoint.x = winPoint.x; auto spritePoint = planeSize * i; spritePoint.x += planeSize.x / 2; spritePoint.y = 0; _sprite->setPosition( spritePoint ); this->setupStencilForClippingOnPlane(i); CHECK_GL_ERROR_DEBUG(); DrawPrimitives::drawSolidRect(Point::ZERO, stencilPoint, Color4F(1, 1, 1, 1)); kmGLPushMatrix(); this->transform(); _sprite->visit(); kmGLPopMatrix(); this->setupStencilForDrawingOnPlane(i); CHECK_GL_ERROR_DEBUG(); GL::blendFunc(BlendFunc::ALPHA_NON_PREMULTIPLIED.src, BlendFunc::ALPHA_NON_PREMULTIPLIED.dst); DrawPrimitives::drawSolidRect(Point::ZERO, winPoint, _planeColor[i]); kmGLPushMatrix(); this->transform(); _sprite->visit(); kmGLPopMatrix(); } glDisable(GL_STENCIL_TEST); CHECK_GL_ERROR_DEBUG(); }
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; }
void SpaceStation::draw() { node()->clear(); float r = _size / 2; Color4F darkGray = colorFilter(Color4F(0.3f, 0.3f, 0.3f, 1.0f)); node()->drawSolidCircle(Vec2::ZERO, r*1.05, 0, 12, darkGray); node()->drawSolidCircle(Vec2::ZERO, r, 0, 12, colorFilter(Color4F::GRAY)); node()->drawSolidRect( Vec2(-7*r/10, 4*r/10), Vec2( 7*r/10, 6*r/10), darkGray ); node()->drawTriangleGradient( Vec2(-7*r/10, -6*r/10), Vec2( 7*r/10, -6*r/10), Vec2( 0, r), colorFilter(Color4F::GRAY), colorFilter(Color4F::GRAY), uniformColor() ); }
void GameLevel::initCurtainPos() { float screenHeight = VisibleRect::getVisibleRect().size.height; float screenWidth = VisibleRect::getVisibleRect().size.width; auto color = mPalette->getDefaultColor(KIND_BLOCK); auto camPos = mGameLayer->getCamera()->getPosition(); if (mCurtain) { mCurtain->setVisible(true); } else { mCurtain = DrawNode::create(); mCurtain->setCameraMask((unsigned short) CameraFlag::USER2); mGameLayer->addChild(mCurtain, ZORDER_CURTAIN); } mCurtain->clear(); mCurtain->drawSolidRect(Vec2(camPos.x - screenWidth / 2, camPos.y - screenHeight * 1.5f), Vec2(camPos.x + screenWidth / 2, camPos.y - screenHeight / 2), Color4F(color)); }
void CameraCullingDemo::update(float dt) { _drawAABB->clear(); if(_cameraType == CameraType::ThirdPerson) drawCameraFrustum(); Vector<Node*>& children = _layer3D->getChildren(); Vec3 corners[8]; for (const auto& iter: children) { const AABB& aabb = static_cast<Sprite3D*>(iter)->getAABB(); if (_cameraFirst->isVisibleInFrustum(&aabb)) { aabb.getCorners(corners); _drawAABB->drawCube(corners, Color4F(0, 1, 0, 1)); } } }
Color4F getColor4F(int color){ switch(color){ case Star::Color::PURPLE: return Color4F(0.74,0.30,0.99,1); case Star::Color::BLUE: return Color4F(84/255.0f,203/255.0f,254/255.0f,1); case Star::Color::RED: return Color4F(253/255.0f,80/255.0f,126/255.0f,1); case Star::Color::YELLOW: return Color4F(253/255.0f,234/255.0f,84/255.0f,1); case Star::Color::GREEN: return Color4F(132/255.0f,226/255.0f,111/255.0f,1); } return Color4F(1,1,1,0); }
bool HelloWorld::checkNeedEliminate() { if (_elements[_touchElements[0]]->getName() == _elements[_touchElements[1]]->getName()) { std::vector<int> path; if (BFSearch(_touchElements[0], _touchElements[1], path, 0)){ for (unsigned int i = 0; i < path.size() - 1; ++i) { int rowi = path[i] / MAX_CAPACITY_NUM_IN_LINE; int coli = path[i] - (rowi * MAX_CAPACITY_NUM_IN_LINE); int rowi1 = path[i + 1] / MAX_CAPACITY_NUM_IN_LINE; int coli1 = path[i + 1] - (rowi1 * MAX_CAPACITY_NUM_IN_LINE); Vec3 posi = Vec3((-(MAX_CAPACITY_NUM_IN_LINE / 2 - _elementSize.width / 2.0f) + rowi) * _elementSize.width, 0.0f, (-(MAX_CAPACITY_NUM_IN_LINE / 2 - _elementSize.height / 2.0f) + coli) * _elementSize.height); Vec3 posi1 = Vec3((-(MAX_CAPACITY_NUM_IN_LINE / 2 - _elementSize.width / 2.0f) + rowi1) * _elementSize.width, 0.0f, (-(MAX_CAPACITY_NUM_IN_LINE / 2 - _elementSize.height / 2.0f) + coli1) * _elementSize.height); _drawNode->drawLine(posi, posi1, Color4F(0.0f, 1.0f, 0.0f, 1.0f)); } return true; } } return false; }
void Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { // Don't do calculate the culling if the transform was not updated _insideBounds = (flags & FLAGS_TRANSFORM_DIRTY) ? renderer->checkVisibility(transform, _contentSize) : _insideBounds; if(_insideBounds) { _quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, transform); renderer->addCommand(&_quadCommand); #if CC_SPRITE_DEBUG_DRAW _debugDrawNode->clear(); Vec2 vertices[4] = { Vec2( _quad.bl.vertices.x, _quad.bl.vertices.y ), Vec2( _quad.br.vertices.x, _quad.br.vertices.y ), Vec2( _quad.tr.vertices.x, _quad.tr.vertices.y ), Vec2( _quad.tl.vertices.x, _quad.tl.vertices.y ), }; _debugDrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0)); #endif //CC_SPRITE_DEBUG_DRAW } }
// on "init" you need to initialize your instance bool Level03::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } m_visibleSize = Director::getInstance()->getVisibleSize(); m_floorPoint = m_visibleSize.height / 4.6; Point origin = Director::getInstance()->getVisibleOrigin(); auto wall = DrawNode::create(); wall->drawSolidRect(Vec2(0, 0), Vec2(m_visibleSize.width, m_visibleSize.height), Color4F::BLACK); this->addChild(wall); setBG(); setPlayer(); animCache(); auto shade = DrawNode::create(); shade->drawSolidRect(Vec2(0, 0), Vec2(m_visibleSize.width, m_visibleSize.height), Color4F(0, 0, 0, 180)); //this->addChild(shade); idle(); eventHandler(); m_enterButton = ui::Button::create("img/button.png"); m_enterButton->setScale(0.6); m_enterButton->setTitleColor(Color3B::WHITE); m_enterButton->setTitleFontName("fonts/ant-maru.ttf"); m_enterButton->setTitleFontSize(45); m_enterButton->setTitleText("入る"); m_enterButton->setVisible(false); m_enterButton->setPosition(Vec2(m_visibleSize.width / 2, m_visibleSize.height / 10)); this->addChild(m_enterButton); this->scheduleUpdate(); return true; }