void LoadingBar::handleSpriteFlipX()
{
    if (_direction == Direction::LEFT)
    {
        if (!_scale9Enabled)
        {
            auto innerSprite = _barRenderer->getSprite();
            if (nullptr != innerSprite)
            {
                innerSprite->setFlippedX(false);
            }
        }
    }
    else
    {
        if (!_scale9Enabled)
        {
            auto innerSprite = _barRenderer->getSprite();
            if (nullptr != innerSprite)
            {
                innerSprite->setFlippedX(true);
            }
        }
    }
}
void LoadingBar::loadTexture(const std::string& texture,TextureResType texType)
{
    if (texture.empty())
    {
        return;
    }
    _renderBarTexType = texType;
    _textureFile = texture;
    switch (_renderBarTexType)
    {
        case TextureResType::LOCAL:
            _barRenderer->initWithFile(texture);
            break;
        case TextureResType::PLIST:
            _barRenderer->initWithSpriteFrameName(texture);
            break;
        default:
            break;
    }
    
    _barRendererTextureSize = _barRenderer->getContentSize();
    
    switch (_direction)
    {
        case Direction::LEFT:
            _barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(false);
                }
            }
            break;
        case Direction::RIGHT:
            _barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(true);
                }
            }
            break;
    }
    _barRenderer->setCapInsets(_capInsets);
    this->updateChildrenDisplayedRGBA();

    barRendererScaleChangedWithSize();
    updateContentSizeWithTextureSize(_barRendererTextureSize);
    
    this->updateProgressBar();
    _barRendererAdaptDirty = true;
}
Beispiel #3
0
bool MyMap::mapReload(float xpos){
	auto s = (Sprite*)curMaplist.begin()[0];
	auto bp = convertToWorldSpace(s->getPosition());
	if(bp.x+s->getContentSize().width<0){
		s->removeFromParentAndCleanup(true);
		curMaplist.eraseObject(s);
	}
	auto lm =(Sprite*) curMaplist.at(curMaplist.size()-1);
	auto wp = convertToWorldSpace(lm->getPosition());
	if(wp.x+lm->getContentSize().width < Director::getInstance()->getVisibleSize().width){
		//auto p = (ParallaxNode*)lm->getParent();
		if(layerMark ==MID_SCENE){
			auto newMap =Sprite::create(PIC_MID);
			if(mapCount ==-1){
			newMap->setFlippedX(true);
			}
			mapCount = mapCount*(-1);
			newMap->setAnchorPoint(Vec2(0,0));
			mlayer->addChild(newMap,3,909);
			newMap->setPosition(lm->getPositionX()+lm->getContentSize().width,100);
			auto paraMove = MoveBy::create(2,Vec2(MID_RATE*SPEED*2,0));
			auto seq =Sequence::create(paraMove,NULL);
			newMap->runAction(RepeatForever::create(seq));
			curMaplist.pushBack(newMap);
			//float x = lm->getContentSize().width+lm->getPositionX()-MID_RATE*p->getPositionX()+p->getPositionX();
			auto p = ParallaxNode::create();
			//p->addChild(newMap,3,Vec2(MID_RATE,0),Vec2(x,100));
			//newMap->setPosition(lm->getPositionX()+lm->getContentSize().width,100);
			
			
		}
		else{
			auto newMap =Sprite::create(PIC_FAR);
			if(mapCount ==-1){
				newMap->setFlippedX(true);
			}
			mapCount = mapCount*(-1);
			newMap->setAnchorPoint(Vec2(0,0));
			mlayer->addChild(newMap);
			newMap->setPosition(lm->getPositionX()+lm->getContentSize().width,200);
			auto paraMove = MoveBy::create(2,Vec2(FAR_RATE*SPEED*2,0));
			auto seq =Sequence::create(paraMove,NULL);
			newMap->runAction(RepeatForever::create(seq));
			curMaplist.pushBack(newMap);
			//float x = lm->getContentSize().width+lm->getPositionX()-FAR_RATE*p->getPositionX()+p->getPositionX();
			//p->addChild(newMap,2,Vec2(FAR_RATE,0),Vec2(x,0));

		}
	return true;
	}
	else
	{
		return false;
	}
}
Beispiel #4
0
void Enemy::updateFaceDir()
{
	RelativeDirection rd = getActorRD();
	if (rd == RD_LEFT) {
		setFlippedX(true);
		m_faceDir = F_LEFT;
	}
	else if (rd == RD_RIGHT) {
		setFlippedX(false);
		m_faceDir = F_RIGHT;
	}
}
Beispiel #5
0
void Enemy::updateEnemy(float delta)
{
	if (getFaceDir() == F_RIGHT) {
		setFlippedX(true);
	}
	else {
		setFlippedX(false);
	}
	updatePeople(delta);
	onDieEnemy();
	updateFireBullet();
}
void HelloWorld::createDragon() {
	auto texture = Director::getInstance()->getTextureCache()->addImage("Images/dragon_animation.png");
	auto animation = Animation::create();
	animation->setDelayPerUnit(0.1f);

	for (int i = 0; i < 6; i++) {
		int index = i % 4;
		int rowIndex = i / 4;

		animation->addSpriteFrameWithTexture(texture, Rect(index * 130, rowIndex * 140, 130, 140));
	}



	auto dragon = Sprite::createWithTexture(texture, Rect(0, 0, 130, 140));
	dragon->setPosition(dragonPosition);
	this->addChild(dragon);

	dragon->setFlippedX(true);

	dragon->setScale(0.5);

	auto animate = Animate::create(animation);
	auto rep = RepeatForever::create(animate);
	dragon->runAction(rep);
}
Beispiel #7
0
bool Fire::init(int base_hurt){
    if (!Sprite::init()){
        return false;
    }


    initWithSpriteFrameName("fire00.png");

    Animation* fly = GameUtile::createNormalAction("fire%02d.png", 10, 30);
    setFlyAction(Animate::create(fly));
    Animation* end = GameUtile::createNormalAction("fire_end%02d.png", 4, 20);
    setEndAction(Sequence::create(Animate::create(end),
        CallFuncN::create(CC_CALLBACK_0(Fire::EndFire, this)),
        NULL));

    m_baseHurt = base_hurt;
    m_bodyBox = GameUtile::createBoundingBox(Vec2(0, 0), getContentSize());
    m_velocity = Vec2(10, 0);
    setFlippedX(global->hero->getDirection() == ROLE_DIRECTION_RIGHT);

    m_nTimer = 0;

    scheduleUpdate();

    return true;
}
Beispiel #8
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);
}
Beispiel #9
0
void SGSHero::setDirection(HERO_DIRECTION direction)
{
  __direction = direction;
  switch (__direction)
  {
  case HERO_DIRECTION_EAST:
    setFlippedX(true);
    break;
  case HERO_DIRECTION_WEST:
  case HERO_DIRECTION_NORTH:
  case HERO_DIRECTION_SOUTH:
    setFlippedX(false);
    break;
  default:
    break;
  }

}
Beispiel #10
0
void LoadingBar::setupTexture()
{
    _barRendererTextureSize = _barRenderer->getContentSize();

    switch (_direction)
    {
        case Direction::LEFT:
            _barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(false);
                }
            }
            break;
        case Direction::RIGHT:
            _barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(true);
                }
            }
            break;
    }
    _barRenderer->setCapInsets(_capInsets);
    this->updateChildrenDisplayedRGBA();

    barRendererScaleChangedWithSize();
    updateContentSizeWithTextureSize(_barRendererTextureSize);

    this->updateProgressBar();
    _barRendererAdaptDirty = true;
}
void LoadingBar::setDirection(cocos2d::ui::LoadingBar::Direction direction)
{
    if (_direction == direction)
    {
        return;
    }
    _direction = direction;
    
    switch (_direction)
    {
        case Direction::LEFT:
            _barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
            _barRenderer->setPosition(Vec2(0,_contentSize.height*0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(false);
                }
            }
            break;
        case Direction::RIGHT:
            _barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
            _barRenderer->setPosition(Vec2(_totalLength,_contentSize.height*0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(true);
                }
            }
            break;
    }

}
Beispiel #12
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;
}
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();
}
Beispiel #14
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());
    }
}
Beispiel #15
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;
}
Beispiel #16
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();
}
Beispiel #17
0
AttackObject* HeroBow::createAttackObject()
{
    std::string strAttID=getArmature()->getAnimation()->getCurrentMovementID();
    auto actionMode=getActionFileMode();
    //获取方向
    bool facing=getFacing();
    float attackDist=getHeroModel()->AttackDist;      //攻击距离

    //创建子弹
    auto bullet=BulletObject::create();
    bullet->setAttackType(1);
    bullet->setAttackObject(this);
    
    if (strAttID==actionMode->ActionAttackName1 || strAttID==actionMode->ActionAttackName2 || strAttID==actionMode->ActionAttackName3 || strAttID==actionMode->ActionAttackName4)
    {
        bullet->setRepelPower(8.0);
        float bulletX=GameBLL::instance()->getMaxMapWidth();
        if(!facing){
            bulletX*=-1;
        }
        auto b=Sprite::createWithSpriteFrameName("v_arrow_1.png");
        b->setFlippedX(!facing);
        bullet->setSprite(b);
        bullet->setPosition(getPosition()+vShootPos);
        bullet->setTargetPos(getPosition()+Vec2(bulletX,vShootPos.y), 3000);
        bullet->setAttack(getHeroModel()->Attack);
        BulletBLL::getInstance()->addBullet(bullet);
    }
    //技能1
    if (strAttID==actionMode->SkillName1) {
        bullet->setPenetrateAttack(true);
        bullet->setRepelPower(32);
        attackDist=skills[0].AttackDist;
        
        float width=1280.0;
        float rota=21.24;   //旋转角度
        if(!facing){
            attackDist*=-1;
            rota*=-1;
            width*=-1;
        }
        auto bulletStartPos=getPosition() + Vec2(0, 255);
        auto b=Sprite::createWithSpriteFrameName("v_arrow_2.png");
        b->setFlippedX(!facing);
        bullet->setSprite(b);
        bullet->setPosition(bulletStartPos);
        //bullet->setTargetPos(pos+Vec2(attackDist,0), 2000);
        bullet->setIsDone(true);
        bullet->setRotation(rota);
        int attack=skills[0].CurrAttack + getHeroModel()->Attack / 4;
        bullet->setAttack(attack);
        BulletBLL::getInstance()->addBullet(bullet);
        
        auto call=CallFunc::create(CC_CALLBACK_0(HeroBow::bulletCallback, this, bullet));
        ccBezierConfig bc;
        bc.endPosition=Vec2(bulletStartPos.x + width, bulletStartPos.y);
        
        if(!facing){
            bc.controlPoint_1 = Vec2(bulletStartPos.x - width * 0.2, bulletStartPos.y - 300);
            bc.controlPoint_2 = Vec2(bc.endPosition.x + width * 0.2, bulletStartPos.y - 300);
        }else{
            bc.controlPoint_1 = Vec2(bulletStartPos.x + width * 0.2, bulletStartPos.y - 300);
            bc.controlPoint_2 = Vec2(bc.endPosition.x - width * 0.2, bulletStartPos.y - 300);
        }
        //子弹动作
        auto bez=BezierTo::create(0.5, bc);
        auto seq=Sequence::create(bez,call, NULL);
        bullet->runAction(APRotateWithAction::create(seq));
        
    }else if (strAttID==actionMode->SkillName2){
        float bAngle=345;
        if(!facing){
            bAngle=215;
        }
        auto bulletPos=getPosition() + Vec2(0, 272);
        int attack=skills[1].CurrAttack + getHeroModel()->Attack / 4;
        for (int i=0; i<3; i++) {
            auto targetPos=APTools::getRoundPoint(bulletPos, bAngle - (i * 10), 1700);
            float rotation=APTools::getAngle(bulletPos, targetPos);
            auto b=Sprite::createWithSpriteFrameName("v_arrow_3.png");
            b->setFlippedX(!facing);
            
            //创建子弹
            auto newbullet=BulletObject::create();
            newbullet->setRepelPower(8.0);
            newbullet->setAttackType(1);
            newbullet->setPenetrateAttack(true);
            newbullet->setAttackObject(this);
            newbullet->setSprite(b);
            newbullet->setPosition(bulletPos);
            newbullet->setTargetPos(targetPos, 2000);
            newbullet->setRotation(rotation);
            newbullet->setAttack(attack);
            BulletBLL::getInstance()->addBullet(newbullet);

        }
    }else if (strAttID==actionMode->SkillName3){
        attackDist=skills[2].AttackDist;
        //创建攻击对象
        int attack=skills[2].CurrAttack + getHeroModel()->Attack / 4;
        auto att=AttackObject::create();
        att->setAttack(attack);
        att->setRepelPower(280);
        att->setAttackObject(this);
        //是否被击倒
        att->setIsHitDown(true);
        //攻击范围
        Vec2 pos=this->getPosition();
        float attStartPosX=getPositionX();
        if (!facing) {
            attStartPosX-=attackDist;
        }
        
        Rect attRect=Rect(attStartPosX,getPositionY(),attackDist, 100);
        att->setAttRange(attRect);
        return att;
        
    }else if (strAttID==actionMode->SkillName4){
        attackDist=skills[3].AttackDist;
        //创建攻击对象
        int attack=skills[3].CurrAttack + getHeroModel()->Attack / 4;
        auto att=AttackObject::create();
        att->setAttack(attack);
        att->setRepelPower(120);
        att->setAttackObject(this);
        //是否被击倒
        att->setIsHitDown(false);
        //攻击范围
        Vec2 pos=this->getPosition();
        auto worldPos=this->getParent()->convertToWorldSpace(pos);
        float attDist=1280-worldPos.x;
        float attStartPosX=pos.x;
        if (!facing) {
            attDist=worldPos.x;
            attStartPosX-=attDist;
        }
        
        Rect attRect=Rect(attStartPosX,getPositionY(),attDist, 100);
        att->setAttRange(attRect);
        
        return att;
    }
    
    return nullptr;
}
Beispiel #18
0
bool WarriorInfoPanel::init()
{
    auto player_bg = Sprite::create("Images/ui_bg.png");
    if (nullptr != player_bg)
    {
        player_bg->setAnchorPoint(Vec2::ZERO);
        player_bg->setPosition(Vec2::ZERO);
        this->addChild(player_bg);
    }

    auto player_eye1 = Sprite::create("Images/tou_eye1.png");
    if (nullptr != player_eye1)
    {
        player_eye1->setPosition(Vec2(86.0f, 100.0f));
        this->addChild(player_eye1);
    }

    auto player_eye2 = Sprite::create("Images/tou_eye2.png");
    if (nullptr != player_eye2)
    {
        player_eye2->setPosition(Vec2(86.0f, 100.0f));
        this->addChild(player_eye2);
    }

    auto player_head = Sprite::create("Images/tou_base.png");
    if (nullptr != player_head)
    {
        player_head->setPosition(Vec2(86.0f, 100.0f));
        this->addChild(player_head);
    }

    auto player_attack_icon = Sprite::create("Images/ui_attack.png");
    if (nullptr != player_attack_icon)
    {
        player_attack_icon->setPosition(Vec2(180.0f, 140.0f));
        this->addChild(player_attack_icon);

        _attack_num = LabelAtlas::create("10", "Images/ps_num_shared.png", 21, 29, '0');
        if (nullptr != _attack_num)
        {
            _attack_num->setScaleX(0.8f);
            _attack_num->setAnchorPoint(Vec2(0.0f, 0.5f));
            _attack_num->setPosition(Vec2(40.0f, player_attack_icon->getContentSize().height / 2));
            player_attack_icon->addChild(_attack_num);
        }
    }

    auto player_defend_icon = Sprite::create("Images/ui_defend.png");
    if (nullptr != player_defend_icon)
    {
        player_defend_icon->setPosition(Vec2(330.0f, 140.0f));
        this->addChild(player_defend_icon);

        _defend_num = LabelAtlas::create("10", "Images/ps_num_shared.png", 21, 29, '0');
        if (nullptr != _defend_num)
        {
            _defend_num->setScaleX(0.8f);
            _defend_num->setAnchorPoint(Vec2(0.0f, 0.5f));
            _defend_num->setPosition(Vec2(40.0f, player_defend_icon->getContentSize().height / 2));
            player_defend_icon->addChild(_defend_num);
        }
    }

    auto player_jb_icon = Sprite::create("Images/ui_jb.png");
    if (nullptr != player_jb_icon)
    {
        player_jb_icon->setPosition(Vec2(180.0f, 90.0f));
        this->addChild(player_jb_icon);

        _jb_num = LabelAtlas::create("0", "Images/ps_num_shared.png", 21, 29, '0');
        if (nullptr != _jb_num)
        {
            _jb_num->setScaleX(0.8f);
            _jb_num->setAnchorPoint(Vec2(0.0f, 0.5f));
            _jb_num->setPosition(Vec2(40.0f, player_jb_icon->getContentSize().height / 2));
            player_jb_icon->addChild(_jb_num);
        }
    }

    auto player_hun_icon = Sprite::create("Images/ui_hun.png");
    if (nullptr != player_hun_icon)
    {
        player_hun_icon->setPosition(Vec2(330.0f, 90.0f));
        this->addChild(player_hun_icon);

        _hun_num = LabelAtlas::create("0", "Images/ps_num_shared.png", 21, 29, '0');
        if (nullptr != _hun_num)
        {
            _hun_num->setScaleX(0.8f);
            _hun_num->setAnchorPoint(Vec2(0.0f, 0.5f));
            _hun_num->setPosition(Vec2(40.0f, player_hun_icon->getContentSize().height / 2));
            player_hun_icon->addChild(_hun_num);
        }
    }

    const auto LENGHT = 280.0f;
    auto progress_bg = Node::create();
    if (nullptr != progress_bg)
    {
        progress_bg->setPosition(Vec2(160.0f, 34.0f));
        this->addChild(progress_bg);

        auto head = Sprite::create("Images/ui_hp_bg_a.png");
        auto tail = Sprite::create("Images/ui_hp_bg_a.png");
        auto body = Sprite::create("Images/ui_hp_bg_b.png");
        head->setAnchorPoint(Vec2::ZERO);
        head->setPosition(Vec2::ZERO);
        progress_bg->addChild(head);
        auto scale = (LENGHT - 2 * head->getContentSize().width) / body->getContentSize().width;
        body->setScaleX(scale);
        body->setAnchorPoint(Vec2::ZERO);
        body->setPosition(Vec2(head->getContentSize().width, 0));
        progress_bg->addChild(body);
        tail->setFlippedX(true);
        tail->setAnchorPoint(Vec2::ZERO);
        tail->setPosition(Vec2(head->getContentSize().width + body->getBoundingBox().size.width, 0));
        progress_bg->addChild(tail);

        _hp_num = LabelAtlas::create("500", "Images/ps_num_shared.png", 21, 29, '0');
        if (nullptr != _hp_num)
        {
            _hp_num->setScaleX(0.8f);
            _hp_num->setAnchorPoint(Vec2(0.5f, 0.5f));
            _hp_num->setPosition(Vec2(LENGHT / 2, body->getContentSize().height / 2));
            progress_bg->addChild(_hp_num);
        }
    }

    for (int32_t i = 0; i < 3; ++i)
    {
        auto key_bg = Sprite::create("Images/ui_btn2.png");
        if (nullptr != key_bg)
        {
            key_bg->setAnchorPoint(Vec2(0, 0.5f));
            key_bg->setPosition(Vec2(456.0f + i * 66.0f, 142.0f));
            this->addChild(key_bg);

            auto key_res = "Images/key" + String::createWithFormat("%d", i)->_string + ".png";
            auto key_sprite = Sprite::create(key_res);
            key_sprite->setScale(0.6f);
            key_sprite->setPosition(Vec2(key_bg->getContentSize().width / 2, key_bg->getContentSize().height / 2));
            key_bg->addChild(key_sprite);
        }
    }

    _key_red_num = LabelAtlas::create("0", "Images/ps_num_key.png", 17, 22, '0');
    if (_key_red_num)
    {
        _key_red_num->setPosition(Vec2(490.0f, 120.0f));
        this->addChild(_key_red_num);
    }
    _key_blue_num = LabelAtlas::create("0", "Images/ps_num_key.png", 17, 22, '0');
    if (_key_blue_num)
    {
        _key_blue_num->setPosition(Vec2(556.0f, 120.0f));
        this->addChild(_key_blue_num);
    }
    _key_yellow_num = LabelAtlas::create("0", "Images/ps_num_key.png", 17, 22, '0');
    if (_key_yellow_num)
    {
        _key_yellow_num->setPosition(Vec2(622.0f, 120.0f));
        this->addChild(_key_yellow_num);
    }

    for (int32_t i = 0; i < 2; ++i)
    {
        auto daoju_bg = Sprite::create("Images/ui_btn.png");
        if (nullptr != daoju_bg)
        {
            daoju_bg->setAnchorPoint(Vec2(0, 0.5f));
            daoju_bg->setPosition(Vec2(466.0f + i * 94.0f, 76.0f));
            this->addChild(daoju_bg);
        }
    }
    return true;
}
Beispiel #19
0
void Role::setFaceLeft(bool flag)
{
	setFlippedX(flag); 
	mIsFaceLeft = flag; 
}
Beispiel #20
0
void MyMap::mapupdate(float x){
	auto h = (Hero*)mlayer->getChildByTag(TAG_HERO_CLASS);
	if(h->status != HERO_STATUS_FALLEN)
	{
		if(1)
		{
			Vector<Sprite*>::iterator it;
			for(int i = 0;i<curMaplist.size();i++){
				auto tmp = (Sprite*)curMaplist.at(i);
				float posx = 0;
				switch (layerMark)
				{
				case MID_SCENE:
					{
						posx = 0; 
						break;
					}
				case FAR_SCENE:
					{
						posx = 0.2;
						break;
					}
				case FARFAR_SCENE:
					{
						posx = 0.5;
						break;
					}
				default:
				break;
				}
			tmp->setPositionX(tmp->getPositionX()+posx);
			}
		}
		else
		{
			mapWidth++;
		}
	}
	auto lm = (Sprite*)curMaplist.at(curMaplist.size()-1);
	if(x+lm->getContentSize().width > lm->getPositionX()+Director::getInstance()->getVisibleSize().width)
	{
		auto newMap = Sprite::create(BG_PIC[layerMark-1]);
		if(mapCount == 1){
			newMap->setFlippedX(true);
		}
		mapCount = mapCount*(-1);
		newMap->setAnchorPoint(Vec2(0,0));

		if(layerMark != FARFAR_SCENE){
			newMap->setPosition(Vec2(lm->getPositionX()+lm->getContentSize().width-2,0)); 
		}
		else
		{
			newMap->setPosition(Vec2(lm->getPositionX()+lm->getContentSize().width-2,(layerMark-2)*groundHeight));
		}

		mlayer->addChild(newMap,-layerMark,TAG_MAP);
		curMaplist.pushBack(newMap);
	}
	auto fm = (Sprite*)curMaplist.at(0);
	if(fm->getPositionX()+fm->getContentSize().width<x-200)
	{
		fm->removeFromParentAndCleanup(true);
		curMaplist.eraseObject(fm);
	}
}
Beispiel #21
0
bool GameScene24::init() {

    if ( !Layer::init() )
    {
        return false;
    }

    m_ui = UISimple::create();
    this->addChild(m_ui, 30);


    Size visibleSize = Director::getInstance()->getWinSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

    zidan = false;
    time = 5.0;

    //背景
    auto bg = Sprite::create("level_24/bg.jpg");
    bg->setPosition(Point(visibleSize.width* 0.5f,visibleSize.height * 0.5f));
    this->addChild(bg);
    //创建月亮
    moon = Sprite::create("level_24/hand1.png");
    moon->setPosition(Point(visibleSize.width * 0.5f,visibleSize.height * 0.5f));
    moon->setAnchorPoint(Point::ANCHOR_MIDDLE);
    moon->setTag(13);
    this->addChild(moon);

    auto body = PhysicsBody::createCircle(moon->getContentSize().width * 0.5f);
    body->getShape(0)->setFriction(0.0f);
    body->getShape(0)->setRestitution(1.001f);
    body->getShape(0)->setDensity(1.0f);
    body->setCategoryBitmask(1);    // 0001
    body->setCollisionBitmask(1);   // 0001
    body->setContactTestBitmask(1); // 0001
    body->setGravityEnable(false);
    moon->setPhysicsBody(body);
    body->applyImpulse(Vect(3500000, 0));


    //创建锯齿边缘
    auto border = Sprite::create("level_24/border.png");
    Size borderSize = border->getContentSize();

    auto border1 = createBorder(Point(borderSize.width * 0.9f, borderSize.height * 0.7f));
    this->addChild(border1);

    auto border2 = createBorder(Point(visibleSize.width - borderSize.width * 0.5f, borderSize.height * 0.7f));
    border2->setFlippedX(true);
    this->addChild(border2);

    auto border3 = createBorder(Point(visibleSize.width * 0.5f, visibleSize.height * 0.15f));
    borderSize = border3->getContentSize();
    border3->setRotation(90.0f);
    this->addChild(border3);

    auto border4 = createBorder(Point(visibleSize.width * 0.5f, visibleSize.height * 0.8f));
    borderSize = border4->getContentSize();
    border4->setRotation(90.0f);
    this->addChild(border4);

    //子弹
    shoot = Sprite::create("level_24/zidan1.png");
    shoot->setPosition(Point( visibleSize.width * 0.5f,visibleSize.height * 0.15f+40));
    shoot->setVisible(false);
    shoot->setAnchorPoint(Point::ANCHOR_MIDDLE);
    shoot->setTag(14);
    this->addChild(shoot);

    body1 = PhysicsBody::createCircle(shoot->getContentSize().width * 0.5f);
    body1->setCategoryBitmask(1);    // 0001
    body1->setCollisionBitmask(1);   // 0001
    body1->setContactTestBitmask(1); // 0001
    shoot->setPhysicsBody(body1);

    //加载初始文字
    boss = Sprite::create("new/text_she.png");
    boss->setAnchorPoint(Point::ANCHOR_MIDDLE_BOTTOM);
    boss->setPosition(Point(visibleSize.width/2,visibleSize.height+100));
    this->addChild(boss,30);

    auto pSequence2 = Sequence::create(CallFunc::create(
    [&]() {
        auto bossAct = MoveTo::create(0.5f, Point(Director::getInstance()->getVisibleSize().width/2, 680));
        auto bossEase = EaseBackInOut::create(bossAct);
        boss->runAction(bossEase);
    }),
    DelayTime::create(1.0f),
    CallFunc::create(
    [&]() {
        boss->runAction(MoveTo::create(0.5f,
                                       Point(Director::getInstance()->getVisibleSize().width/2, Director::getInstance()->getVisibleSize().height+200)));
    }),NULL);
    this->runAction(pSequence2);


    //触摸监听
    auto listener = EventListenerTouchOneByOne::create();

    //listener->setSwallowTouches(true);
    listener->onTouchBegan = CC_CALLBACK_2(GameScene24::onTouchBegan,this);

    listener->onTouchEnded = CC_CALLBACK_2(GameScene24::onTouchEnded,this);

    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

    //碰撞监听
    auto contactListener = EventListenerPhysicsContact::create();

    contactListener->onContactBegin = CC_CALLBACK_1(GameScene24::onContactBegin, this);

    _eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);

    //5秒内无动作失败
    this->schedule(schedule_selector(GameScene24::update));
    return true;
}
Beispiel #22
0
void AllianceFlagPar::createPar(std::string icon){
    if(icon == "Blood.png"){
        bloodPar();
    }
    if(icon == "Snow.png"){
        snowPar();
    }
    if(icon == "Warhammer.png"){
        warhammerPar();
    }
    if(icon == "Tree.png"){
        treePar();
    }
    if(icon == "Cure.png"){
        curePar();
    }
    if(icon == "Death.png"){
        deathPar();
    }
    if(icon == "Fire.png"){
        firePar();
    }
    if(icon == "Ocean.png"){
        oceanPar();
    }
    if(icon == "Sun.png"){
        sunPar();
    }
    if(icon == "Wolf.png"){
        wolfPar();
    }
    if(icon == "Angel.png"){
        m_partileNode = CCNode::create();
        this->addChild(m_partileNode);
        for (int i=1; i<5; i++) {
            auto particle = ParticleController::createParticle(CCString::createWithFormat("FlagAngel_%d",i)->getCString());
            particle->setPosition(0, 0);
            m_partileNode->addChild(particle);
        }
    }
    if(icon == "Cattle.png"){
        m_partileNode = CCNode::create();
        this->addChild(m_partileNode);
        for (int i=1; i<6; i++) {
            auto particle = ParticleController::createParticle(CCString::createWithFormat("FlagCattle_%d",i)->getCString());
            particle->setPosition(0, 0);
            m_partileNode->addChild(particle);
        }
    }
    if(icon == "FireWolf.png"){
        m_partileNode = CCNode::create();
        this->addChild(m_partileNode);
        
        auto particle = ParticleController::createParticle("FireWolf_1");
        particle->setPosition(-6, 18);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FireWolf_2");
        particle->setPosition(-12, 22);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FireWolf_3");
        particle->setPosition(6, 20);
        m_partileNode->addChild(particle);
    }
    if(icon == "Grail.png"){
        m_partileNode = CCNode::create();
        this->addChild(m_partileNode);
        for (int i=1; i<5; i++) {
            auto particle = ParticleController::createParticle(CCString::createWithFormat("FlagGrail_%d",i)->getCString());
            particle->setPosition(0, 0);
            m_partileNode->addChild(particle);
        }
    }
    if(icon == "Knight.png"){
        m_partileNode = CCNode::create();
        this->addChild(m_partileNode);
        
        auto particle = ParticleController::createParticle("FlagDeath_4");
        particle->setPosition(3, 17);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FlagDeath_4");
        particle->setPosition(-6, 21);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FlagKnight_R");
        particle->setPosition(48, -17);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FlagKnight_L");
        particle->setPosition(-50, -15);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FlagKnight_1");
        particle->setPosition(0, 18);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FlagKnight_2");
        particle->setPosition(0, -32);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FlagKnight_3");
        particle->setPosition(0, 91);
        m_partileNode->addChild(particle);

        particle = ParticleController::createParticle("FlagKnight_4");
        particle->setPosition(-3, -40);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FlagKnight_4");
        particle->setPosition(-40, -60);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FlagKnight_4");
        particle->setPosition(-20, -54);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("FlagKnight_4");
        particle->setPosition(45, -40);
        m_partileNode->addChild(particle);
        
    }
    if(icon == "Spain.png"){
        m_spainWingNode = Node::create();
        this->addChild(m_spainWingNode);
        auto wing = CCLoadSprite::createSprite("SpainWing.png");
        wing->setPosition(-70,20);
        CCSequence *sequene = CCSequence::create(CCFadeTo::create(2, 102), CCFadeTo::create(2, 255), NULL);
        CCSequence *sequene1 = CCSequence::create(CCFadeTo::create(2, 102), CCFadeTo::create(2, 255), NULL);
        wing->runAction(CCRepeatForever::create(sequene));
        m_spainWingNode->addChild(wing);
        wing = CCLoadSprite::createSprite("SpainWing.png");
        wing->setFlippedX(true);
        wing->setPosition(70,20);
        wing->runAction(CCRepeatForever::create(sequene1));
        m_spainWingNode->addChild(wing);
        
        m_partileNode = CCNode::create();
        this->addChild(m_partileNode);
        
        auto particle = ParticleController::createParticle("Spain_1");
        particle->setPosition(37, 0);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("Spain_2");
        particle->setPosition(-46, 0);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("Spain_3");
        particle->setPosition(0, 0);
        m_partileNode->addChild(particle);
        
        particle = ParticleController::createParticle("Spain_4");
        particle->setPosition(0, 0);
        m_partileNode->addChild(particle);
    }
}