예제 #1
0
void MainLayer::createSpecRecomend()
{
	if (!_hideNode->isVisible() || _pageView->getCurPageIndex() != MAIN_PAGE || !_isUseSpec)
		return;

	auto rt = RenderTexture::create(_pageView->getContentSize().width,
		_pageView->getContentSize().height,
		Texture2D::PixelFormat::RGBA8888,
		GL_DEPTH24_STENCIL8);
	rt->beginWithClear(0, 0, 0, 0, 0);
	_pageView->getPage(MAIN_PAGE)->visit(_director->getRenderer(), _director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW), true);
	rt->end();
	rt->getSprite()->setScaleY(-1);

	auto sprite = dynamic_cast<Sprite*>(LsTools::seekNodeByName(_rootNode, formatStr("dy_%d", MAIN_PAGE)));
	sprite->setTexture(rt->getSprite()->getTexture());

	auto pane1 = LsTools::seekNodeByName(_pageView, "Panel_0");
	auto img3 = (ui::ImageView*)(LsTools::seekNodeByName(pane1, "3"));
	auto img0 = (ui::ImageView*)(LsTools::seekNodeByName(pane1, "0"));
	auto img2 = (ui::ImageView*)(LsTools::seekNodeByName(pane1, "2"));
	auto img1 = (ui::ImageView*)(LsTools::seekNodeByName(pane1, "1"));

	Rect rect(img1->getLeftBoundary(), img1->getBottomBoundary(),
		img3->getRightBoundary() - img1->getLeftBoundary(),
		img2->getContentSize().height);

	sprite->setTextureRect(Rect(rect.origin.x, rect.origin.y, rect.size.width, 300));
	float bot = img2->getBottomBoundary() - (sprite->getTextureRect().getMaxY() - sprite->getTextureRect().getMinY()) / 2 - 5;
}
예제 #2
0
bool GameNext::init()
{
    //////////////////////////////
    // 1. super init first
    if (!Scene::init())
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    /////////////////////////////

    
    if(game_round<=9)
    {
        gr_pic = "0" + Value(game_round).asString();
    }else if(game_round>=10)
    {
        gr_pic = Value(game_round).asString();
    }
    
    if((game_level-1)<=9)
    {
        gl_pic = "0" + Value(game_level-1).asString();
    }else if((game_level-1)>=10)
    {
        gl_pic = Value(game_level-1).asString();
    }
    
    
    //被弄成灰色的截图
    auto ac = Sprite::create(picNext);
    ac->setAnchorPoint(Vec2(0,0));
    ac->setPosition(Vec2(0,0));
    ac->setScaleX(visibleSize.width/ac->getTextureRect().getMaxX()); //设置精灵宽度缩放比例
    ac->setScaleY(visibleSize.height/ac->getTextureRect().getMaxY());
    this->addChild(ac,100);
    
    
    //半透明层,在截图之上
    LayerColor* layerColor = CCLayerColor::create();
    layerColor->setColor(cocos2d::Color3B(0, 0, 0));
    layerColor->setOpacity(150);
    layerColor->setContentSize(Size(visibleSize.width, visibleSize.height));
    this->addChild(layerColor,101);
    
    
    //next小方块的背景
    auto gameover = Sprite::create("setting/gamenext.png");
    gameover->setPosition(Vec2(origin.x + visibleSize.width/2,origin.y + visibleSize.height/2));
    this->addChild(gameover,102);
    
    
    scheduleUpdate();
    
    return true;
    
}
예제 #3
0
bool GameOver::init(){
	if(!Layer::init())
		return false;
	//定义背景
	auto sprite = Sprite::create("background.jpg");
	//float windowWidth=Director::getInstance()->getWinSize().width;
	//float windowHeight=Director::getInstance()->getWinSize().height;
	float imgWidth=sprite->getTextureRect().getMaxX();
	float imgHeight=sprite->getTextureRect().getMaxY();
	sprite->setScaleX(GAME_SCREEN_WIDTH/imgWidth);
	sprite->setScaleY(GAME_SCREEN_HEIGHT/imgHeight);
	sprite->setPosition(GAME_SCREEN_WIDTH/2,GAME_SCREEN_HEIGHT/2);
	this->addChild(sprite, 0);
	//定义标题
	auto labelTitle=Label::createWithTTF("GAME OVER", "fonts/showg.ttf", FONT_SUPER_LARGE);
	labelTitle->setPosition(Point(GAME_SCREEN_WIDTH/2,GAME_SCREEN_HEIGHT*3/4));
	labelTitle->setColor(Color3B(238,149,114));
	this->addChild(labelTitle);
	//定义restart
	auto labelRestart=Label::createWithTTF("Restart", "fonts/arial.ttf", FONT_SMALL);
	labelRestart->setColor(Color3B(238,149,114));
	auto menuItemLabel=MenuItemLabel::create(labelRestart,CC_CALLBACK_1(GameOver::restart,this));
	menuItemLabel->setPosition(Point(GAME_SCREEN_WIDTH-labelRestart->getContentSize().width,GAME_SCREEN_HEIGHT*3/5));
	auto menu=Menu::create(menuItemLabel,NULL);
	menu->setPosition(Point::ZERO);
	this->addChild(menu);

	return true;
}
예제 #4
0
void AnimatedSprite::setAnimation(Animation& anim)
{
	//reset();
	animation = anim;
	setTexture(animation.spriteSheet);
	setTextureRect(animation.getFrame(iFrame));
	setOrigin(getTextureRect().width / 2, getTextureRect().height / 2);
}
예제 #5
0
sf::Vector2f SpritePlus::getFrame() const
{
	float left = getTextureRect().left,
		top = getTextureRect().top,
		width = getTextureRect().width,
		height = getTextureRect().height;

	return sf::Vector2f(left/width, top/height);
}
예제 #6
0
bool GameOver::init()
{
    //////////////////////////////
    // 1. super init first
    if (!Scene::init())
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    /////////////////////////////
   
    
    
    
    auto ac = Sprite::create(picOver);
    ac->setAnchorPoint(Vec2(0,0));
    ac->setPosition(Vec2(0,0));
    ac->setScaleX(visibleSize.width/ac->getTextureRect().getMaxX()); //设置精灵宽度缩放比例
    ac->setScaleY(visibleSize.height/ac->getTextureRect().getMaxY());
    
    this->addChild(ac,100);
    
    
    
    
    //半透明层
    
    LayerColor* layerColor = CCLayerColor::create();
    
    layerColor->setColor(cocos2d::Color3B(0, 0, 0));
    
    layerColor->setOpacity(150);
    
    layerColor->setContentSize(Size(visibleSize.width, visibleSize.height));
    
    this->addChild(layerColor,101);
    
    
    auto gameover = Sprite::create("setting/gameover.png");
    //gameover->setAnchorPoint(Vec2(0,0));
    gameover->setPosition(Vec2(origin.x + visibleSize.width/2,
                               origin.y + visibleSize.height/2));
    this->addChild(gameover,102);
    

    
    scheduleUpdate();
    
    return true;
    
}
NS_FENNEX_BEGIN
void CustomDropDownList::updateTweenAction(float value, const std::string& key)
{
    if(key.compare("textureWidth") == 0)
    {
        setTextureRect(Rect(getTextureRect().origin.x, getTextureRect().origin.y, value, getTextureRect().size.height));
    }
    else if(key.compare("textureHeigth") == 0)
    {
        setTextureRect(Rect(getTextureRect().origin.x, getTextureRect().origin.y, getTextureRect().size.width, value));
    }
}
예제 #8
0
void MainLayer::createSpec(int index)
{
	//return;
	if (!_hideNode->isVisible() || !_isUseSpec)
		return;
	_pageView->setPositionX(-MY_SCREEN.width * index);
	auto rt = RenderTexture::create(_pageView->getContentSize().width,
		_pageView->getContentSize().height,
		Texture2D::PixelFormat::RGBA8888,
		GL_DEPTH24_STENCIL8);
	rt->beginWithClear(0, 0, 0, 0, 0);
	_pageView->getPage(index)->visit(_director->getRenderer(), _director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW), true);
	rt->end();
	rt->getSprite()->setScaleY(-1);
	// 	_renderPageViewTex->saveToFile("pageview.png");

	auto sprite = dynamic_cast<Sprite*>(LsTools::seekNodeByName(_rootNode, formatStr("dy_%d", index)));
	sprite->setTexture(rt->getSprite()->getTexture());
	//sprite->setTextureRect(rt->getSprite()->getTextureRect());

	if (index == 0)//main page
	{
		auto pane1 = LsTools::seekNodeByName(_pageView, "Panel_0");
		auto img3 = (ui::ImageView*)(LsTools::seekNodeByName(pane1, "3"));
		auto img0 = (ui::ImageView*)(LsTools::seekNodeByName(pane1, "0"));
		auto img2 = (ui::ImageView*)(LsTools::seekNodeByName(pane1, "2"));
		auto img1 = (ui::ImageView*)(LsTools::seekNodeByName(pane1, "1"));

		Rect rect(img1->getLeftBoundary(), img1->getBottomBoundary(),
			img3->getRightBoundary() - img1->getLeftBoundary(),
			img2->getContentSize().height);

		sprite->setTextureRect(Rect(rect.origin.x, rect.origin.y, rect.size.width, 300));
		float bot = img2->getBottomBoundary() - (sprite->getTextureRect().getMaxY() - sprite->getTextureRect().getMinY()) / 2 - 5;
		//sprite->setPosition(_pageView->getContentSize().width / 2, bot);
	}
	else/* if (curPage == 1)*///game category page
	{
		auto pane2 = LsTools::seekNodeByName(_pageView, "Panel_1");
		auto img0 = (ui::ImageView*)(LsTools::seekNodeByName(pane2, "0"));
		auto img5 = (ui::ImageView*)(LsTools::seekNodeByName(pane2, "5"));

		Rect rect(img0->getLeftBoundary(), img0->getBottomBoundary(),
			img5->getRightBoundary() - img0->getLeftBoundary(),
			img5->getContentSize().height);

		sprite->setTextureRect(Rect(rect.origin.x, rect.origin.y, rect.size.width, 300));
		float bot = img0->getBottomBoundary() - (sprite->getTextureRect().getMaxY() - sprite->getTextureRect().getMinY()) / 2 - 5;
		//sprite->setPosition(_pageView->getContentSize().width / 2, bot);
	}
}
예제 #9
0
void Cursor::onUpdateVertexCache()
{
	clearVertices();

	std::vector<sf::Vertex> vertices;

	// pos coords.
	sf::Vector2f tl(myCursorTransform.getTransform().transformPoint(sf::Vector2f(0,0)));
	sf::Vector2f tr(myCursorTransform.getTransform().transformPoint(sf::Vector2f(getTextureRect().width,0)));
	sf::Vector2f br(myCursorTransform.getTransform().transformPoint(sf::Vector2f(getTextureRect().width,getTextureRect().height)));
	sf::Vector2f bl(myCursorTransform.getTransform().transformPoint(sf::Vector2f(0,getTextureRect().height)));

	// tex coords.
	sf::Vector2f ttl(getTextureRect().left, getTextureRect().top);
	sf::Vector2f tbr(getTextureRect().left + getTextureRect().width, getTextureRect().top + getTextureRect().height);
	sf::Vector2f ttr(tbr.x, ttl.y);
	sf::Vector2f tbl(ttl.x, tbr.y);

	// add vertices.
	vertices.push_back(sf::Vertex(tl, sf::Color::White, ttl));
	vertices.push_back(sf::Vertex(tr, sf::Color::White, ttr));
	vertices.push_back(sf::Vertex(bl, sf::Color::White, tbl));
	vertices.push_back(sf::Vertex(tr, sf::Color::White, ttr));
	vertices.push_back(sf::Vertex(br, sf::Color::White, tbr));
	vertices.push_back(sf::Vertex(bl, sf::Color::White, tbl));

	vertexAddTextured(vertices);
}
예제 #10
0
 void Explosion::changeFrame(){
	 if (frames == 0) return;

	 if (ticks % frame_wait_set == 0){
		 curr_frame++;
		 int curr_framerectX = curr_frame % tex_frames.x;
		 int curr_framerectY = curr_frame / tex_frames.x;
		 
		 // do not change frame if it goes over frame limit
		 if (curr_frame >= frames) return;
		 this->setTextureRect(sf::IntRect(curr_framerectX * int(this->getTextureRect().width),
			                  curr_framerectY * int(this->getTextureRect().height),
							  getTextureRect().width, getTextureRect().height));
	 }
 }
예제 #11
0
// on "init" you need to initialize your instance
bool SplashScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

	//定时器设置停留2秒后自动跳转到主界面
    this->scheduleOnce( schedule_selector( SplashScene::GoToMainMenuScene ), DISPLAY_TIME_SPLASH_SCENE );

    auto backgroundSprite = Sprite::create( "splash.jpg" );
	Size size = Director::getInstance()->getWinSize();
	backgroundSprite->setPosition(Vec2(size.width / 2, size.height / 2));
	float winw = size.width; //获取屏幕宽度
	float winh = size.height;//获取屏幕高度

	float spx = backgroundSprite->getTextureRect().getMaxX();
	float spy = backgroundSprite->getTextureRect().getMaxY();

	backgroundSprite->setScaleX(winw / spx); //设置精灵宽度缩放比例
	backgroundSprite->setScaleY(winh / spy);

    //backgroundSprite->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y) );
    
    this->addChild( backgroundSprite );
    
    return true;
}
예제 #12
0
void ObjectSprite::updateFrame()
{
	cocos2d::Rect now = getTextureRect();

	cocos2d::Rect src((now.size.width * frame), 0, now.size.width, now.size.height);
	setTextureRect(src);
}
// Called once every frame of the game. 
void AnimatedSprite::update()
{
	World* world = AssetManager::getAssetManager()->getWorld();

	// Update the position of the sprite:
	float x = body->GetPosition().x  * SCALE - (spriteSheetData.drawWidth / 2)  - world->getXOffset();
	float y = body->GetPosition().y  * SCALE - (spriteSheetData.drawHeight / 2) - world->getYOffset();

	if(this->getScale().x == -1)
		x += getTextureRect().width;

	this->setPosition(x, y);

	// Stop the timer 
	timer->Stop();
	timeSinceLastFrame += timer->GetElapsedAsSeconds();

	// When the timer reaches the right amount of time, switch frames.
	if(timeSinceLastFrame  > spriteSheetData.timeBetweenFrames  )
	{
		nextFrame();
		timeSinceLastFrame = 0;
	}
	timer->Start();

}
예제 #14
0
파일: MySprite.cpp 프로젝트: zjjick/demo
CCRect MySprite::rect(void)
{
	// 后面的比较是以锚点为标准的
	const CCSize& s = getTextureRect().size;
	const CCPoint& p = this->getAnchorPointInPoints();
	return CCRectMake(-p.x, -p.y, s.width, s.height);
}
예제 #15
0
Enemy::Enemy(void) : GameObject("enemy")
{
	Enemy::fCurrentEnemies++;
	delete m_collider;
	m_collider = new Collider(&(getPosition()), getTextureRect().width / 2.0f);
	fSHOOT_TIME = 0.6f + MathHelper::Random(0.6f);
}
예제 #16
0
void Enemy::Hit(GameObject* other)
{
	if(other->m_collider->IsCircular)
	{
		if(other->GetType() != "Bullet")
		{
			sf::Vector2f normalizedDir = getPosition() - other->getPosition();
			float dist = MathHelper::Distance(getPosition(), other->getPosition());
			normalizedDir = MathHelper::Normalize(normalizedDir);
		
			move(normalizedDir * ((getTextureRect().width + other->getTextureRect().width) / 2.0f - dist));
		}
	}
	else
	{
		if(getPosition().x + m_collider->m_fRadius < other->getPosition().x - other->getTextureRect().width / 2)
		{
			float ownX = getPosition().x + m_collider->m_fRadius;
			float otherX = other->getPosition().x - other->getTextureRect().width / 2;
			move(otherX - ownX,0);
		}
		else if(getPosition().x - m_collider->m_fRadius > other->getPosition().x + other->getTextureRect().width / 2)
		{
			float ownX = getPosition().x - m_collider->m_fRadius;
			float otherX = other->getPosition().x + other->getTextureRect().width / 2;
			move(otherX - ownX,0);
		}

		if(getPosition().y - m_collider->m_fRadius < other->getPosition().y - other->getTextureRect().height / 2)
		{
			float ownY = getPosition().y + m_collider->m_fRadius;
			float otherY = other->getPosition().y - other->getTextureRect().height / 2;
			move(0, otherY - ownY);
		}
		else if(getPosition().y + m_collider->m_fRadius > other->getPosition().y + other->getTextureRect().height / 2)
		{
			float ownY = getPosition().y - m_collider->m_fRadius;
			float otherY = other->getPosition().y + other->getTextureRect().height / 2;
			move(0, otherY - ownY);
		}

		if(getPosition().y + m_collider->m_fRadius > other->getPosition().y - other->getTextureRect().height / 2 &&
		   getPosition().y - m_collider->m_fRadius < other->getPosition().y + other->getTextureRect().height / 2 &&
		   getPosition().x - m_collider->m_fRadius < other->getPosition().x + other->getTextureRect().width / 2 &&
		   getPosition().x + m_collider->m_fRadius > other->getPosition().x - other->getTextureRect().width / 2)
		{
			sf::Vector2f dir = MathHelper::Normalize(getPosition() - other->getPosition());
			move(dir * 10.0f);
		}
	}

	if(other->GetType() == "Bullet")
	{
		if(((Bullet*)(other))->m_owner != this)
		{
			m_fHealth -= 15;
			SoundManager::getInstance()->Play("impact_body", 70.f, true);
		}
	}
}
예제 #17
0
CCRect CDragSprite::GetTouchRect()
{
	const CCSize& kSize = getTextureRect().size;
	const CCPoint& kPosition = getAnchorPointInPixels();

	return CCRectMake(-kPosition.x,-kPosition.y,kSize.width,kSize.height);
}
예제 #18
0
bool TouchablePoker::isTouchPointInside(Point &point)
{
    Rect rect1 = getTextureRect();
    Size s = rect1.size;
    Rect rect2 = Rect(-s.width / 2, -s.height / 2, s.width, s.height);
    
    return rect2.containsPoint(point);
}
예제 #19
0
void Enemy::Shoot(void)
{
	Bullet* bullet = new Bullet();
	bullet->m_direction = sf::Vector2f(std::cos(PI * (getRotation() + (-9 + 18*MathHelper::Random()) - 90) / 180.0f), std::sin(PI * (getRotation() + (-9 + 18*MathHelper::Random()) - 90) / 180.0f));
	bullet->setPosition(getPosition() + bullet->m_direction * (float)(getTextureRect().width / 2));
	bullet->m_owner = this;
	SoundManager::getInstance()->Play("shoot_enemy", 50.f, true);
	m_bullets.push_back(bullet);
}
예제 #20
0
파일: Player.cpp 프로젝트: alex2202375/dice
void PlayerSprite::placeSelf(){
    Size pSize = getTextureRect().size;
    mNameLabel->setPosition(Vec2(pSize.width/2, -5));
    
    mDice->setPosition(Vec2(pSize.width/2, pSize.height+mDice->getContentSize().height/2+PlayerLineMarginTop));
    
    mPhotoPic->setPosition(getContentSize().width/2, getContentSize().height/2);
    
//    setContentSize(Size(pSize.width, pSize.height+mNameLabel->getContentSize().height + mDice->getContentSize().height + 2*PlayerLineMarginTop));
}
예제 #21
0
CCRect RCUnit::getUnitRect()
{
    CCRect textureRect = getTextureRect();

    float x = getPosition().x - textureRect.size.width/2*getScale();
    float y = getPosition().y - textureRect.size.height/2*getScale();
    float width = textureRect.size.width*getScale();
    float height = textureRect.size.height*getScale();

    CCRect rect = CCRectMake(x, y, width, height);
    return rect;
}
예제 #22
0
void MenuBoxManager::setImageWithName(Button* button, const char* ImgName)
{
    //    auto lbInfo = button->getChildByTag(TAG_MENU_BOX_TITLE);

    //이미지를 박스크기에 맞게 자르기 위한 임시 이미지

    auto tempSprite  =  Sprite::create("Main_BoxDown-hd.png");
    //이미지를 라벨을 뺀 크기로 만든다.
    Rect rc = tempSprite->getTextureRect();
    tempSprite->setTextureRect(Rect(rc.origin.x, rc.origin.y, rc.size.width- 6, rc.size.height - (_tempPoint.y + _tempSize.height)));

    auto layout = Layout::create();
    layout->setSize(Size(tempSprite->getTextureRect().size.width,
                         tempSprite->getTextureRect().size.height));
    // ImageView를 생성하고 Layout에 add함
    auto imageView = ImageView::create(StringUtils::format("%s",ImgName));
    //    imageView->setAnchorPoint(Point::ANCHOR_TOP_LEFT);
    //    imageView->setPosition(Vec2(2, 2));
    imageView->setTextureRect(tempSprite->getTextureRect());
    imageView->setPosition(Vec2(button->getContentSize().width/2, button->getContentSize().height - (tempSprite->getContentSize().height/2 + 2)));
    layout->addChild(imageView);

    button->addChild(layout);
}
예제 #23
0
void PlayerHpBar::SetFeedback()
{
	auto character = m_player->GetComponent<CharacterComponent>()->GetCharacter();
	int hp = character->GetHp();
	if (hp == m_lastHp) return;
	if (hp < 0) m_object->GetParent()->GetComponent<MainGame>()->AnnounceFinish(m_object->GetName());
	m_lastHp = hp;
	int maxHp = character->GetMaxHp();
	float perc = (float)hp / maxHp;

	auto sprite = m_greenBar->GetComponent<SpriteComponent>()->GetSprite();
	auto rect = sprite->getTextureRect();
	rect.width = (int)(m_barSize.x * perc);
	sprite->setTextureRect(rect);
}
예제 #24
0
void Renderable::render(sf::RenderWindow* window)
{
    const sf::Vector2u size = sf::Sprite::getTexture()->getSize();
    const sf::Vector2f rectSize(size.x, size.y);
    const sf::Vector2f pos = sf::Sprite::getPosition();
    const sf::IntRect rect = getTextureRect();
    const sf::Vector2f center = sf::Vector2f(rect.width * 0.5, rect.height * 0.5);

    sf::RectangleShape outline;
    outline.setSize(rectSize);
    outline.setOutlineColor(sf::Color::Green);
    outline.setOutlineThickness(-1.0f);
    outline.setFillColor(sf::Color(0, 0, 0, 0));
    outline.setPosition(pos);
    outline.setOrigin(center);

    window->draw(outline);
}
GamePlayerSprite* GamePlayerSprite::create(const std::string& filename){
    
    
    auto player = (GamePlayerSprite *)Sprite::create(filename);
    float playerScale = (VisibleRect::getVisibleRect().size.height*playerOffsetScale)/player->getTextureRect().size.height;
    player->setScale(playerScale);
    player->setAnchorPoint(Point(0.5,0));
    
    auto body = PhysicsBody::createBox(Size(player->getTextureRect().size.width * playerScale, player->getTextureRect().size.height * playerScale));
    
    body->setContactTestBitmask(1);
    player->setPhysicsBody(body);

    

    
    player->isJump = false;
    
    return player;

}
예제 #26
0
void FeImage::set_subimg_height( int h )
{
	sf::IntRect r = getTextureRect();
	r.height=h;
	setTextureRect( r );
}
예제 #27
0
float GraphicalEntity::getHeight() {
    sf::Vector2f scale = this->getScale();
    return getTextureRect().height * scale.y;
}
 void centerOrigin() {
     setOrigin(getTextureRect().width/2, getTextureRect().height/2);
 }
예제 #29
0
PowerUp::PowerUp(Type type):
	m_type(type)
{
	setTexture(Resources::getTexture("entities/power-ups.png"));
	setTextureRect(getTextureRect(type));
}
예제 #30
0
float GraphicalEntity::getWidth() {
    sf::Vector2f scale = this->getScale();
    return getTextureRect().width * scale.x;
};