Exemplo n.º 1
0
void GAFMovieClip::updateTextureWithEffects()
{
    if (!m_blurFilterData && !m_glowFilterData)
    {
        setTexture(m_initialTexture);
        setTextureRect(m_initialTextureRect, false, m_initialTextureRect.size);
        setFlippedY(false);
    }
    else
    {
        cocos2d::Texture2D * resultTex = nullptr;

        if (m_blurFilterData)
        {
            resultTex = GAFFilterManager::getInstance()->applyFilter(Sprite::createWithTexture(m_initialTexture, m_initialTextureRect), m_blurFilterData);
        }
        else if (m_glowFilterData)
        {
            resultTex = GAFFilterManager::getInstance()->applyFilter(Sprite::createWithTexture(m_initialTexture, m_initialTextureRect), m_glowFilterData);
        }

        if (resultTex)
        {
            setTexture(resultTex);
            setFlippedY(true);
            cocos2d::Rect texureRect = cocos2d::Rect(0, 0, resultTex->getContentSize().width, resultTex->getContentSize().height);
            setTextureRect(texureRect, false, texureRect.size);
        }
    }
}
void RenderTextureZbuffer::renderScreenShot()
{
    auto texture = RenderTexture::create(512, 512);
    if (NULL == texture)
    {
        return;
    }
    texture->setAnchorPoint(Point(0, 0));
    texture->begin();

    this->visit();

    texture->end();

    auto sprite = Sprite::createWithTexture(texture->getSprite()->getTexture());

    sprite->setPosition(Point(256, 256));
    sprite->setOpacity(182);
    sprite->setFlippedY(1);
    this->addChild(sprite, 999999);
    sprite->setColor(Color3B::GREEN);

    sprite->runAction(Sequence::create(FadeTo::create(2, 0),
                                          Hide::create(),
                                          NULL));
}
Exemplo n.º 3
0
void AnimatedSprite::reset()
{
	setColor(sf::Color::White);
	setRotation(0.f);
	setFlippedX(false);
	setFlippedY(false);
	setScale(sf::Vector2f(1.f, 1.f));
	setOrigin(0.f, 0.f);
}
Exemplo n.º 4
0
	bool initWithString(const char *string, const char *fontName,
			float fontSize, const cocos2d::Size& dimensions,
			cocos2d::TextHAlignment hAlignment,
			cocos2d::TextVAlignment vAlignment,
			float red, float green, float blue)
	{
		if (!cocos2d::LabelTTF::initWithString(string,
				fontName, fontSize, dimensions, hAlignment, vAlignment))
			return false;

		setFlippedY(true);
		setRGB(red, green, blue);
		return true;
	}
Exemplo n.º 5
0
void Bomb::explode()
{
	_explodeTime = Director::getInstance()->getTotalFrames();
	_isFire = true;
	_isRemote = false;
	_tick = 9999;
	GameSounds::Instance().playSound(ES_BOMB, false);
	if (_player)
	{
		_player->explodeBomb();
		_player = nullptr;
	}
	if (_brick)
	{
		_brick->explodeBomb();
		_brick = nullptr;
	}
	animate(_sprite, FCENTER);
	checkCollision(_sprite);
	_fires.push_back(_sprite);
	for (auto p : sPoints)
	{
		for (int i = 1; i <= _size; i++)
		{
			FireType type = i == _size ? FTAIL : FBODY;
			auto sprite = Sprite::createWithSpriteFrameName(typeStr[type] + "_1.png");
			sprite->setPosition(_sprite->getPosition() + p * i);

			Direction dir = pointToDir(p);
			if (dir == RIGHT)
			{
				sprite->setRotation(90);
			}
			else if (dir == LEFT)
			{
				sprite->setRotation(270);
			}
			else if (dir == DOWN)
			{
				sprite->setFlippedY(true);
			}

			animate(sprite, type);
			if (checkCollision(sprite)) break;
			_fires.push_back(sprite);
			addChild(sprite);
		}
	}
}
Exemplo n.º 6
0
bool pausePopup::init(RenderTexture* bgTexture, char* menuImage){
	if (!Layer::init()){
		return false;
	}

	auto bgSprite = Sprite::createWithTexture(bgTexture->getSprite()->getTexture());
	bgSprite->setFlippedY(true);
	auto visibleSize = Director::getInstance()->getVisibleSize();
	bgSprite->setPosition(visibleSize.width / 2, visibleSize.height / 2);
	this->addChild(bgSprite, 1);

	menuSprite = Sprite::create(menuImage);
	menuSprite->setPosition(visibleSize.width / 2, visibleSize.height / 2);
	menuSprite->setOpacity(200);
	this->addChild(menuSprite, 2);
	Action* popupAction = Sequence::create(ScaleTo::create(0.0f, 0.0f),
								ScaleTo::create(0.06f, 1.05f),
								ScaleTo::create(0.08f, 0.95f),
								ScaleTo::create(0.08f, 1.0f), NULL);
	menuSprite->runAction(popupAction);
	
	/*
	contentText = Label::createWithTTF("ÓÎÏ·ÔÝÍ£","fonts/msyhbd.ttc",30);
	contentText->setPosition(menuSprite->getContentSize().width/2, menuSprite->getContentSize().height/3*2);
	menuSprite->addChild(contentText);
	
	auto backLabel = Label::createWithTTF("·µ»ØÓÎÏ·", "fonts/msyhbd.ttc", 20);
	backLabel->setColor(Color3B::BLACK);
	auto backItem = MenuItemLabel::create(backLabel, CC_CALLBACK_0(pausePopup::backToGame,this));
	backItem->setPosition(backItem->getContentSize().width*2,0);

	auto levelLabel = Label::createWithTTF("Ñ¡Ôñ¹Ø¿¨", "fonts/msyhbd.ttc", 20);
	levelLabel->setColor(Color3B::BLACK);
	auto levelItem = MenuItemLabel::create(levelLabel, CC_CALLBACK_0(pausePopup::backToLevel,this));
	levelItem->setPosition(0, 0);

	auto overLabel = Label::createWithTTF("½áÊøÓÎÏ·", "fonts/msyhbd.ttc", 20);
	overLabel->setColor(Color3B::BLACK);
	auto overItem = MenuItemLabel::create(overLabel, CC_CALLBACK_0(pausePopup::endGame,this));
	overItem->setPosition(-overItem->getContentSize().width* 2, 0);

	auto menu = Menu::create(backItem, levelItem, overItem,NULL);
	menu->setPosition(menuSprite->getContentSize().width/2,backItem->getContentSize().height*2);
	menuSprite->addChild(menu,10);
	*/
	return true;
}
Exemplo n.º 7
0
void GameScene::spawn_tube_pair()
{
	auto upper_tube = get_an_inactive_tube();
	int upper_tube_pos_y{ std::rand() % 250 + 350 };	// dummy
	upper_tube->initialize_position((float)upper_tube_pos_y);
	upper_tube->setAnchorPoint(Vec2{ 1, 0 });
	upper_tube->set_score(0);
	upper_tube->start_moving();

	auto lower_tube = get_an_inactive_tube();
	float lower_tube_pos_y{ (float)upper_tube_pos_y - TUBE_UPPER_LOWER_GAP };
	lower_tube->initialize_position(lower_tube_pos_y);
	lower_tube->setAnchorPoint(Vec2{ 1, 1 });
	lower_tube->setFlippedY(true);
	lower_tube->set_score(1);
	lower_tube->start_moving();
}
Exemplo n.º 8
0
bool Popup::init(RenderTexture* bgTexture, char* menuImage){
	if (!Layer::init()){
		return false;
	}

	auto bgSprite = Sprite::createWithTexture(bgTexture->getSprite()->getTexture());
	bgSprite->setFlippedY(true);
	auto visibleSize = Director::getInstance()->getVisibleSize();
	bgSprite->setPosition(visibleSize.width / 2, visibleSize.height / 2);
	this->addChild(bgSprite, 1);

	auto menuSprite = Sprite::create(menuImage);
	menuSprite->setPosition(visibleSize.width / 2, visibleSize.height / 2);
	menuSprite->setOpacity(200);
	this->addChild(menuSprite, 2);

	return true;
}
Exemplo n.º 9
0
NS_GAF_BEGIN

GAFSprite::GAFSprite()
:
objectIdRef(IDNONE),
m_useSeparateBlendFunc(false),
m_isLocator(false),
m_blendEquation(-1),
m_atlasScale(1.0f),
m_externalTransform(AffineTransform::IDENTITY)
{
#if COCOS2D_VERSION < 0x00030300
    _batchNode = nullptr; // this will fix a bug in cocos2dx 3.2 tag
#endif
    setFlippedX(false); // Fix non-inited vars in cocos
    setFlippedY(false);
    _rectRotated = false;
}
Exemplo n.º 10
0
void Widget::copyProperties(Widget *widget)
{
    setEnabled(widget->isEnabled());
    setVisible(widget->isVisible());
    setBright(widget->isBright());
    setTouchEnabled(widget->isTouchEnabled());
    setLocalZOrder(widget->getLocalZOrder());
    setTag(widget->getTag());
    setName(widget->getName());
    setActionTag(widget->getActionTag());
    _ignoreSize = widget->_ignoreSize;
    _size = widget->_size;
    _customSize = widget->_customSize;
    _sizeType = widget->getSizeType();
    _sizePercent = widget->_sizePercent;
    _positionType = widget->_positionType;
    _positionPercent = widget->_positionPercent;
    setPosition(widget->getPosition());
    setAnchorPoint(widget->getAnchorPoint());
    setScaleX(widget->getScaleX());
    setScaleY(widget->getScaleY());
    setRotation(widget->getRotation());
    setRotationSkewX(widget->getRotationSkewX());
    setRotationSkewY(widget->getRotationSkewY());
    setFlippedX(widget->isFlippedX());
    setFlippedY(widget->isFlippedY());
    setColor(widget->getColor());
    setOpacity(widget->getOpacity());
    _touchEventCallback = widget->_touchEventCallback;
    _touchEventListener = widget->_touchEventListener;
    _touchEventSelector = widget->_touchEventSelector;
    _focused = widget->_focused;
    _focusEnabled = widget->_focusEnabled;
    
    copySpecialProperties(widget);

    //FIXME:copy focus properties, also make sure all the subclass the copy behavior is correct
    Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary;
    for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter)
    {
        setLayoutParameter(iter->second->clone());
    }
    onSizeChanged();
}
Exemplo n.º 11
0
void Widget::copyProperties(Widget *widget)
{
    setEnabled(widget->isEnabled());
    setVisible(widget->isVisible());
    setBright(widget->isBright());
    setTouchEnabled(widget->isTouchEnabled());
    setLocalZOrder(widget->getLocalZOrder());
    setTag(widget->getTag());
    setName(widget->getName());
    setActionTag(widget->getActionTag());
    _ignoreSize = widget->_ignoreSize;
    this->setContentSize(widget->_contentSize);
    _customSize = widget->_customSize;
    _sizeType = widget->getSizeType();
    _sizePercent = widget->_sizePercent;
    _positionType = widget->_positionType;
    _positionPercent = widget->_positionPercent;
    setPosition(widget->getPosition());
    setAnchorPoint(widget->getAnchorPoint());
    setScaleX(widget->getScaleX());
    setScaleY(widget->getScaleY());
    setRotation(widget->getRotation());
    setRotationSkewX(widget->getRotationSkewX());
    setRotationSkewY(widget->getRotationSkewY());
    setFlippedX(widget->isFlippedX());
    setFlippedY(widget->isFlippedY());
    setColor(widget->getColor());
    setOpacity(widget->getOpacity());
    _touchEventCallback = widget->_touchEventCallback;
    _touchEventListener = widget->_touchEventListener;
    _touchEventSelector = widget->_touchEventSelector;
    _clickEventListener = widget->_clickEventListener;
    _focused = widget->_focused;
    _focusEnabled = widget->_focusEnabled;
    _propagateTouchEvents = widget->_propagateTouchEvents;

    copySpecialProperties(widget);

    Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary;
    for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter)
    {
        setLayoutParameter(iter->second->clone());
    }
}
Exemplo n.º 12
0
bool UIButtonFlipTest::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        // Add a label in which the button events will be displayed
        _displayValueLabel = Text::create("Button X Flipped", "fonts/Marker Felt.ttf",20);
        _displayValueLabel->setNormalizedPosition(Vec2(0.3, 0.7));
        _uiLayer->addChild(_displayValueLabel);
        
        
        // Create the button
        auto button = Button::create("cocosui/animationbuttonnormal.png",
                                     "cocosui/animationbuttonpressed.png");
        button->setNormalizedPosition(Vec2(0.3f, 0.5f));
        button->setTitleText("PLAY GAME");
        button->setTitleFontName("fonts/Marker Felt.ttf");
        button->setZoomScale(0.3f);
        button->setScale(2.0f);
        button->setFlippedX(true);
        button->setPressedActionEnabled(true);
        
        
        _uiLayer->addChild(button);
        
        // Create the button
        auto button2 = Button::create("cocosui/animationbuttonnormal.png",
                                      "cocosui/animationbuttonpressed.png");
        button2->setNormalizedPosition(Vec2(0.8f, 0.5f));
        button2->setTitleText("PLAY GAME");
        button2->setFlippedY(true);
        _uiLayer->addChild(button2);
        
        auto titleLabel = Text::create("Button Y flipped", "Arial", 20);
        titleLabel->setNormalizedPosition(Vec2(0.8, 0.7));
        this->addChild(titleLabel);
        
        return true;
    }
    return false;
}
Exemplo n.º 13
0
bool GameScene::init() {
    Scene = this;
    
    ShaderLayer::init("shaders/vignette.glsl");
    
    rendTexSprite->getGLProgramState()->setUniformVec2("darkness", Vec2(1,1));
    
    mGame = new GameLogic(this);
    mGame->mWinGameEvent = [this]{onWinGame();};
    createControlPad();
    createMenuButtons();
    
#if 0
    Rect r = VisibleRect::getVisibleRect();
    
    Size sz(r.size);
    auto testsp = Sprite::create();
    testsp->setContentSize(sz);
    testsp->setTag(1024);
    
    testsp->setTexture(renderTextureBlur->getSprite()->getTexture());
    addChild(testsp,5000);
    
    r.size = sz;
    testsp->setTextureRect(r);
    
    auto ruv = r;
    ruv.size = renderTexture->getSprite()->getTexture()->getContentSizeInPixels() / 4;
    testsp->setPosition(VisibleRect::center());
    testsp->setFlippedY(true);
    testsp->setTextureCoords(ruv);
    //testsp->addEffect(EffectBloom::create(), 1);
    //testsp->addEffect(EffectBlur::create(), 2);
    
    testsp->setBlendFunc({GL_ONE,GL_ONE});
    //auto visibleRect = VisibleRect::getVisibleRect();
    //testsp->setScale(visibleRect.size.width / sz.width, visibleRect.size.height / sz.height);
#endif
    
    return true;
}
Exemplo n.º 14
0
void ControlSwitchSprite::needsLayout()
{
    _onSprite->setPosition(Point(_onSprite->getContentSize().width / 2 + _sliderXPosition,
        _onSprite->getContentSize().height / 2));
    _offSprite->setPosition(Point(_onSprite->getContentSize().width + _offSprite->getContentSize().width / 2 + _sliderXPosition, 
        _offSprite->getContentSize().height / 2));
    _thumbSprite->setPosition(Point(_onSprite->getContentSize().width + _sliderXPosition,
        _maskTexture->getContentSize().height / 2));

    if (_onLabel)
    {
        _onLabel->setPosition(Point(_onSprite->getPosition().x - _thumbSprite->getContentSize().width / 6,
            _onSprite->getContentSize().height / 2));
    }
    if (_offLabel)
    {
        _offLabel->setPosition(Point(_offSprite->getPosition().x + _thumbSprite->getContentSize().width / 6,
            _offSprite->getContentSize().height / 2));
    }

    RenderTexture *rt = RenderTexture::create((int)_maskTexture->getContentSize().width, (int)_maskTexture->getContentSize().height);

    rt->begin();
    _onSprite->visit();
    _offSprite->visit();

    if (_onLabel)
    {
        _onLabel->visit();
    }
    if (_offLabel)
    {
        _offLabel->visit();
    }

    rt->end();

    setTexture(rt->getSprite()->getTexture());
    setFlippedY(true);
}
Exemplo n.º 15
0
void Widget::copyProperties(Widget *widget)
{
    setEnabled(widget->isEnabled());
    setVisible(widget->isVisible());
    setBright(widget->isBright());
    setTouchEnabled(widget->isTouchEnabled());
    _touchPassedEnabled = false;
    setLocalZOrder(widget->getLocalZOrder());
    setTag(widget->getTag());
    setName(widget->getName());
    setActionTag(widget->getActionTag());
    _ignoreSize = widget->_ignoreSize;
    _size = widget->_size;
    _customSize = widget->_customSize;
    copySpecialProperties(widget);
    _sizeType = widget->getSizeType();
    _sizePercent = widget->_sizePercent;
    _positionType = widget->_positionType;
    _positionPercent = widget->_positionPercent;
    setPosition(widget->getPosition());
    setAnchorPoint(widget->getAnchorPoint());
    setScaleX(widget->getScaleX());
    setScaleY(widget->getScaleY());
    setRotation(widget->getRotation());
    setRotationSkewX(widget->getRotationSkewX());
    setRotationSkewY(widget->getRotationSkewY());
    setFlippedX(widget->isFlippedX());
    setFlippedY(widget->isFlippedY());
    setColor(widget->getColor());
    setOpacity(widget->getOpacity());
    Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary;
    for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter)
    {
        setLayoutParameter(iter->second->clone());
    }
    onSizeChanged();
}
Exemplo n.º 16
0
void CommonBg::initContent()
{
	auto winSize = Director::getInstance()->getWinSize();
	setContentSize(winSize);
	setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	setPosition(INSTANCE(GameUtils)->getWindowsCenterPosition());
	
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ui/chapter/chapter.plist");
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("common/common.plist");

	auto topBar = Scale9Sprite::createWithSpriteFrame(
		SpriteFrameCache::getInstance()->getSpriteFrameByName("chapter_texture.png"));
	topBar->setPreferredSize(Size(winSize.width,115));
	topBar->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP);
	topBar->setPosition(Vec2(0,winSize.height/2));
	addChild(topBar);

	auto bottomBar = Scale9Sprite::createWithSpriteFrame(
		SpriteFrameCache::getInstance()->getSpriteFrameByName("chapter_texture.png"));
	bottomBar->setPreferredSize(Size(winSize.width,115));
	bottomBar->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
	bottomBar->setPosition(Vec2(0,-winSize.height/2));
	addChild(bottomBar);

	auto frame1 = Sprite::createWithSpriteFrameName("chapter_frame_1.png");
	addChild(frame1);
	frame1->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP);
	frame1->setPosition(Vec2(0,winSize.height/2));

	auto frame2 = Sprite::createWithSpriteFrameName("chapter_frame_1.png");
	addChild(frame2);
	frame2->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
	frame2->setPosition(Vec2(0,-winSize.height/2));
	frame2->setFlippedY(true);

	auto frameLeft = Sprite::createWithSpriteFrameName("chapter_frame_2.png");
	addChild(frameLeft);
	frameLeft->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
	frameLeft->setPosition(Vec2(-winSize.width/2,0));
	frameLeft->setRotation(180);

	auto frameRight = Sprite::createWithSpriteFrameName("chapter_frame_2.png");
	addChild(frameRight);
	frameRight->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
	frameRight->setPosition(Vec2(winSize.width/2,0));

	auto colorLayer = LayerColor::create(Color4B(61,34,0,255));
	addChild(colorLayer);
	colorLayer->setPosition(Vec2(-winSize.width/2+7,-winSize.height/2+115));
	colorLayer->setContentSize(Size(winSize.width-14,410));

	auto line_1 = Sprite::createWithSpriteFrameName("chapter_line.png");
	addChild(line_1);
	line_1->setPosition(Vec2(-1,winSize.height/2 - 115));

	auto line_2 = Sprite::createWithSpriteFrameName("chapter_line.png");
	addChild(line_2);
	line_2->setPosition(Vec2(-1,-winSize.height/2+ 115));
	line_2->setFlippedY(true);

	auto titleBg = Sprite::createWithSpriteFrameName("common_titleBg.png");
	addChild(titleBg);
	titleBg->setPosition(Vec2(40,240));

	//显示不了中文,莫名其妙!!!
	//需要转换成utf-8格式
	auto title = Label::createWithBMFont("font/font_uiTitle.fnt",this->title);
    //auto title = Label::createWithTTF("hello world", "fonts/Marker Felt.ttf", 24);
	//auto title = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", "中国.");
	//auto title = Label::createWithBMFont("fonts/futura-48.fnt", "Chapter");
	addChild(title);
	title->setPosition(Vec2(0,240));
	title->setColor(Color3B::RED);
}
Exemplo n.º 17
0
void Pipe::SpawnPipe( cocos2d::Layer *layer )
{
    CCLOG( "SPAWN PIPE" );
    
    //SpriteBatchNode* spritebatch = SpriteBatchNode::create("flappySprites.png");
    //SpriteFrameCache* cache = SpriteFrameCache::getInstance();
    //cache->addSpriteFramesWithFile("flappySprites.plist");
    
    //auto backgroundSprite = Sprite::createWithSpriteFrameName("background1.png");

    
    auto topPipe = Sprite::createWithSpriteFrameName( "pipe.png" );
    auto bottomPipe = Sprite::createWithSpriteFrameName( "pipe.png" );
    
    auto topPipeBody = PhysicsBody::createBox( topPipe->getContentSize( ) );
    auto bottomPipeBody = PhysicsBody::createBox( bottomPipe->getContentSize( ) );
    
    auto random = CCRANDOM_0_1( );
    
    if ( random < LOWER_SCREEN_PIPE_THRESHOLD )
    {
        random = LOWER_SCREEN_PIPE_THRESHOLD;
    }
    else if ( random > UPPER_SCREEN_PIPE_THRESHOLD )
    {
        random = UPPER_SCREEN_PIPE_THRESHOLD;
    }
    
    
    auto topPipePosition = ( random * visibleSize.height ) + ( topPipe->getContentSize( ).height*2 / 3 );
    
    topPipeBody->setDynamic( false );
    bottomPipeBody->setDynamic( false );
    
    topPipeBody->setCollisionBitmask( OBSTACLE_COLLISION_BITMASK );
    bottomPipeBody->setCollisionBitmask( OBSTACLE_COLLISION_BITMASK );
    topPipeBody->setContactTestBitmask( true );
    bottomPipeBody->setContactTestBitmask( true );
    
    topPipe->setPhysicsBody( topPipeBody );
    bottomPipe->setPhysicsBody( bottomPipeBody );
    
    topPipe->setFlippedY(true);
    topPipe->setPosition( Point( visibleSize.width + topPipe->getContentSize( ).width + origin.x, topPipePosition ) );
    bottomPipe->setPosition( Point( topPipe->getPositionX(), topPipePosition - ( Sprite::createWithSpriteFrameName( "frame-1.png" )->getContentSize( ).height * PIPE_GAP ) - topPipe->getContentSize().height ) );
    
    layer->addChild( topPipe );
    layer->addChild( bottomPipe );
    
    auto topPipeAction = MoveBy::create( PIPE_MOVEMENT_SPEED * visibleSize.width, Point( -visibleSize.width * 1.5, 0 ) );
    auto bottomPipeAction = MoveBy::create( PIPE_MOVEMENT_SPEED * visibleSize.width, Point( -visibleSize.width * 1.5, 0 ) );
    
    topPipe->runAction( topPipeAction );
    bottomPipe->runAction( bottomPipeAction );
    
    auto pointNode = Node::create( );
    auto pointBody = PhysicsBody::createBox( Size( 1, Sprite::createWithSpriteFrameName( "frame-1.png" )->getContentSize( ).height * PIPE_GAP ) );
    
    pointBody->setDynamic( false );
    pointBody->setCollisionBitmask( POINT_COLLISION_BITMASK );
    pointBody->setContactTestBitmask( true );
    pointBody->resetForces();
    
    pointNode->setPhysicsBody( pointBody );
    pointNode->setPosition( Point( topPipe->getPositionX( ), topPipe->getPositionY( ) - ( topPipe->getContentSize( ).height / 2 ) - ( ( Sprite::createWithSpriteFrameName( "frame-1.png" )->getContentSize( ).height * PIPE_GAP ) / 2 ) ) );
    
    layer->addChild( pointNode );
    
    auto pointNodeAction = MoveBy::create( PIPE_MOVEMENT_SPEED * visibleSize.width, Point( -visibleSize.width * 1.5, 0 ) );
    
    pointNode->runAction( pointNodeAction );}
Exemplo n.º 18
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
//    auto back = Sprite::create("menuback.jpg");
//    back->setPosition(Vec2(visibleSize.width/2
//                           , visibleSize.height/2));
//    this->addChild(back, 0);
//    back->setScale(1.2);
    
    auto back = Sprite::create("black_background.jpg");
    back->setFlippedY(true);
    back->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
    back->setScale(2);
    this->addChild(back, 0);
    
    for (int i = 0; i < 1750; ++i)
        back->addChild(Star::create(), 10);
    
    for (int i = 0; i < 550; ++i)
        back->addChild(Star::create(StarType::kFarStar), 10);
    
    for (int i = 0; i < 10; ++i)
        back->addChild(Star::create(StarType::kNearStar), 10);
    
    
    auto gameLabel = Label::createWithTTF("fonts/arial.ttf", "FlightX");
    gameLabel->setColor(Color3B(255, 0 , 0));
    gameLabel->setPosition(Vec2(origin.x + visibleSize.width/2,
                                origin.y + visibleSize.height/2 + 30));
    this->addChild(gameLabel,1);
    auto startGameButton = ui::Button::create();
    startGameButton->setTitleText("Play");
    startGameButton->setColor(Color3B(0, 255, 0));
    
    startGameButton->addTouchEventListener([&](Ref* sender, cocos2d::ui::Widget::TouchEventType type){
        switch (type) {
            case ui::Widget::TouchEventType::ENDED:
				Director::getInstance()->replaceScene(GameScene::createScene());
                break;
            default:
                break;
        }
    });
    startGameButton->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height/2));

    this->addChild(startGameButton, 1);
    
    auto QuitGameButton = ui::Button::create();
    QuitGameButton->setTitleText("Exit");
    QuitGameButton->setColor(Color3B(0, 0, 150));
    
    QuitGameButton->addTouchEventListener([&](Ref* sender, cocos2d::ui::Widget::TouchEventType type){
        switch (type) {
            case ui::Widget::TouchEventType::ENDED:
                Director::getInstance()->end();
                break;
            default:
                break;
        }
    });
    QuitGameButton->setPosition(Vec2(origin.x + visibleSize.width/2,
                                      origin.y + visibleSize.height/2-30));
    
    this->addChild(QuitGameButton, 1);
    
    return true;
}
bool ItemMixedPageLayer::init()
{
    if (!Layer::init()) {
        return false;
    }

    Size winSize = Director::getInstance()->getWinSize();
    Size resolutionSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
    
    auto background = Sprite::create("bg/shop03_a.jpg");
    background->setOpacity(96);
    background->setScale(winSize.width / background->getContentSize().width);
    background->setPosition(Point(winSize.width/2, winSize.height/2));
    this->addChild(background);
    
    // キャラ表示
    auto playerSprite = Sprite::create("novel/actor10_novel_s_1.png");
    playerSprite->setScale(resolutionSize.height/playerSprite->getContentSize().height);
    playerSprite->setPosition(Point(winSize.width * 0.85, winSize.height * 0.4));
    this->addChild(playerSprite);
    
    Size layerSize = Size(winSize.width*0.5, winSize.height*0.3);
    std::string spriteFrameFileName = "grid32.png";
    auto imageSpriteFrame = cocos2d::SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameFileName);
    if (!imageSpriteFrame) {
        imageSpriteFrame = cocos2d::Sprite::create(spriteFrameFileName)->getSpriteFrame();
        cocos2d::SpriteFrameCache::getInstance()->addSpriteFrame(imageSpriteFrame, spriteFrameFileName);
    }
    
    // ベース
    auto baseSprite = cocos2d::Sprite::createWithSpriteFrame(imageSpriteFrame);
    auto baseItemMenuLabel = CommonWindowUtil::createMenuItemLabelWithSpriteIcon(layerSize, baseSprite, FontUtils::getDefaultFontTTFConfig(), "ベースを選択してください", [this, baseSprite](Ref *ref) {
        if (_menuCallback1) {
            _menuCallback1(ref);
        }
    });
    baseItemMenuLabel->setPosition(Point(winSize.width*0.275, winSize.height*0.7));
    _baseSprite = baseSprite;
    _baseMenuItemLabel = baseItemMenuLabel;
    
    // 素材
    auto materialSprite = cocos2d::Sprite::createWithSpriteFrame(imageSpriteFrame);
    auto materialItemlayer = CommonWindowUtil::createMenuItemLabelWithSpriteIcon(layerSize, materialSprite, FontUtils::getDefaultFontTTFConfig(), "そざいを選択してください",[this, materialSprite](Ref *ref) {
        if (_menuCallback2) {
            _menuCallback2(ref);
        }
    });
    materialItemlayer->setPosition(Point(winSize.width*0.275, winSize.height*0.3));
    _materialSprite = materialSprite;
    _materialMenuItemLabel = materialItemlayer;
    
    // L表示
    auto sprite1 = Sprite::create("ui/l_image.png");
    sprite1->setPosition(Point(winSize.width*0.575, winSize.height*0.65));
    this->addChild(sprite1);
    auto sprite2 = Sprite::create("ui/l_image.png");
    sprite2->setFlippedY(true);
    sprite2->setPosition(Point(winSize.width*0.575, winSize.height*0.35));
    this->addChild(sprite2);
    
    // 合成ボタン
    auto mixedMenuItem = CommonWindowUtil::createMenuItemLabelWaku(Label::createWithTTF(FontUtils::getStrongFontTTFConfig(), "合成"), Size(16, 8), [this, baseSprite, baseItemMenuLabel, materialSprite, materialItemlayer](Ref *ref) {
        if (_menuCallback3) {
            _menuCallback3(ref);
        }
    });
    mixedMenuItem->setPosition(Point(winSize.width*0.675, winSize.height*0.5));
    
    auto menu = Menu::create(baseItemMenuLabel, materialItemlayer, mixedMenuItem, NULL);
    menu->setPosition(Point::ZERO);
    this->addChild(menu);
    
    return true;
}