Beispiel #1
0
vmain::vmain() : img(NULL){
	setSize(283,342);
	setPosition(800/2-283/2,600/2-342/2);
	setMovable(false);
	setTitleBarHeight(0);
	setPadding(0);
	setFocusable(false);
	login_added=false;

	/*puerto= new _TextField("7666",gcn::Graphics::CENTER);
	puerto->setSize(133,14);
	puerto->setBackgroundColor(gcn::Color(0,0,0,0));
	puerto->setForegroundColor(gcn::Color(255,255,255,255));
	puerto->setBorderSize(0);
	add(puerto,200,163);*/

	/*host= new _TextField("testserver.aonx.com.ar",gcn::Graphics::CENTER);
	host->setSize(208,14);
	host->setBackgroundColor(gcn::Color(0,0,0,0));
	host->setForegroundColor(gcn::Color(255,255,255,255));
	host->setBorderSize(0);
	add(host,366,163);*/

	/*blogin = new NoDrawButton;
	blogin->setSize(230,80);
	blogin->setFocusable(false);
	blogin->setActionEventId("blogin");
	blogin->addActionListener(this);

	add(blogin,560,340);*/

	/*bcreate = new NoDrawButton;
	bcreate->setSize(230,80);
	bcreate->setFocusable(false);
	bcreate->setActionEventId("CREATE");
	bcreate->addActionListener(ClienteArgentum::instancia());

	add(bcreate,560,440);*/

	login_button = new ImageButton();
	create_button = new ImageButton();
	servers_button = new ImageButton();
	options_button = new ImageButton();
	exit_button = new ImageButton();

	login_button->setSize(250, 40);
	create_button->setSize(250, 40);
	servers_button->setSize(250, 40);
	options_button->setSize(250, 40);
	exit_button->setSize(250, 40);
	
	std::string path;
	path=ConfigData::GetPath("gui") + std::string("main_menu/");

	login_button->setNormalImage(path + std::string("login.png"));
	login_button->setMoserOverImage(path + std::string("loginb.png"));
	login_button->setActionEventId("LOGIN_DIALOG");
	login_button->addActionListener(ClienteArgentum::instancia());

	create_button->setNormalImage(path + std::string("create.png"));
	create_button->setMoserOverImage(path + std::string("createb.png"));
	create_button->setActionEventId("CREATE");
	create_button->addActionListener(ClienteArgentum::instancia());

	servers_button->setNormalImage(path + std::string("servers.png"));
	servers_button->setMoserOverImage(path + std::string("serversb.png"));

	options_button->setNormalImage(path + std::string("opciones.png"));
	options_button->setMoserOverImage(path + std::string("opcionesb.png"));
	options_button->setActionEventId("OPTIONS");
	options_button->addActionListener(ClienteArgentum::instancia());

	exit_button->setNormalImage(path + std::string("salir.png"));
	exit_button->setMoserOverImage(path + std::string("salirb.png"));
	exit_button->setActionEventId("EXIT");
	exit_button->addActionListener(ClienteArgentum::instancia());

	add(login_button,17, 66);
	add(create_button,17, 121);
	add(servers_button,17, 176);
	add(options_button,17, 231);
	add(exit_button,17, 287);


}
Beispiel #2
0
void Widget::setLeft( int newLeft )
{
  setPosition( Point( newLeft, getTop() ) );    
}
////////////////////////////////////////////////////////
//
// ParticleMainScene
//
////////////////////////////////////////////////////////
void ParticleMainScene::initWithSubTest(int asubtest, int particles)
{
    //srandom(0);

    subtestNumber = asubtest;
    auto s = Director::getInstance()->getWinSize();

    lastRenderedCount = 0;
    quantityParticles = particles;

    MenuItemFont::setFontSize(65);
    auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) {
		quantityParticles -= kNodesIncrease;
		if( quantityParticles < 0 )
			quantityParticles = 0;

		updateQuantityLabel();
		createParticleSystem();
	});
    decrease->setColor(Color3B(0,200,20));
    auto increase = MenuItemFont::create(" + ", [&](Ref *sender) {
		quantityParticles += kNodesIncrease;
		if( quantityParticles > kMaxParticles )
			quantityParticles = kMaxParticles;

		updateQuantityLabel();
		createParticleSystem();
	});
    increase->setColor(Color3B(0,200,20));

    auto menu = Menu::create(decrease, increase, NULL);
    menu->alignItemsHorizontally();
    menu->setPosition(Vec2(s.width/2, s.height/2+15));
    addChild(menu, 1);

    auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30);
    infoLabel->setColor(Color3B(0,200,20));
    infoLabel->setPosition(Vec2(s.width/2, s.height - 90));
    addChild(infoLabel, 1, kTagInfoLayer);

    // particles on stage
    auto labelAtlas = LabelAtlas::create("0000", "fps_images.png", 12, 32, '.');
    addChild(labelAtlas, 0, kTagLabelAtlas);
    labelAtlas->setPosition(Vec2(s.width-66,50));

    // Next Prev Test
    auto menuLayer = new ParticleMenuLayer(true, TEST_COUNT, s_nParCurIdx);
    addChild(menuLayer, 1, kTagMenuLayer);
    menuLayer->release();

    // Sub Tests
    MenuItemFont::setFontSize(40);
    auto pSubMenu = Menu::create();
    for (int i = 1; i <= 6; ++i)
    {
        char str[10] = {0};
        sprintf(str, "%d ", i);
        auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(ParticleMainScene::testNCallback, this));
        itemFont->setTag(i);
        pSubMenu->addChild(itemFont, 10);

        if (i <= 3)
        {
            itemFont->setColor(Color3B(200,20,20));
        }
        else
        {
            itemFont->setColor(Color3B(0,200,20));
        }
    }
    pSubMenu->alignItemsHorizontally();
    pSubMenu->setPosition(Vec2(s.width/2, 80));
    addChild(pSubMenu, 2);

    auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32);
    addChild(label, 1);
    label->setPosition(Vec2(s.width/2, s.height-50));

    updateQuantityLabel();
    createParticleSystem();

    schedule(schedule_selector(ParticleMainScene::step));
}
Beispiel #4
0
void TextCursor::setPosition(const KTextEditor::Cursor& position)
{
    setPosition(position, false);
}
Beispiel #5
0
void AutoTank::moveTo(TVector newPosition)
{
	setPosition(newPosition.X(), newPosition.Y(), newPosition.Z());
	currentPosition.setY(terrain->GetHeight((float)currentPosition.X(), (float)currentPosition.Z()) + 6.4);
}
void BasicScreenObject::setX(float _x) {
  setPosition(_x, getY(), getZ());
}
void BasicScreenObject::setZ(float _z) {
  setPosition(getX(), getY(), _z);
}
Beispiel #8
0
void Sprite::setCurrentFrame(u16 animID, u16 frameID) {
	setPosition(m_animations.at(animID).getFramePosition(frameID).x,
	            m_animations.at(animID).getFramePosition(frameID).y);

	setCurrentFrame(m_animations.at(animID).getFrame(frameID));
}
CGUICalibMapDialog::CGUICalibMapDialog()
  : CRRCDialog(0, 0, CRRC_DIALOG_OK), state(0), numaxis(0)
{
  // activate the test mode to see the movements of the model
  activate_test_mode();
  
  //activate verbosity
  sVerbosity = Global::nVerbosity;
  Global::nVerbosity  =1;
  
  // create some label strings from scratch
  // ("0", "1", ...)
  for (int i = 0; i < TX_MAXAXIS; i++)
  {
    // attention: only works for TX_MAXAXIS < 10
    axislabel[i] = new char[2];
    *(axislabel[i]) = 0x30 + i;
    *(axislabel[i] + 1) = '\0';
  }
  axislabel[TX_MAXAXIS] = NULL;
  
  // Create the selection list for the SelectBoxes.
  // Contains as many axis as the interface features,
  // plus "-" (deactivate) and NULL (terminate).
  // The number of axis will be stored to make sure
  // it doesn't change until the dialog is closed.
  numaxis = Global::TXInterface->getNumAxes();
  
  if (numaxis > TX_MAXAXIS)
  {
    numaxis = TX_MAXAXIS;
  }
  for (int i = 0; i < numaxis; i++)
  {
    selectlist[i] = axislabel[i];
  }
  selectlist[numaxis]   = mapped_to_keyboard;
  selectlist[numaxis+1] = NULL;

  // The "mapping group" (left part of the dialog).
  // The combo box on top is not part of the group
  // because it controls hiding and revealing of the
  // other widgets.
  mapgroup = new puGroup(LABEL_W + DLG_DEF_SPACE,
                         BUTTON_BOX_HEIGHT);
  for (int i = 0; i < NUM_FUNCTIONS; i++)
  {
    int index = NUM_FUNCTIONS - 1;
    axismapping[i] = new puaSelectBox(0,
                                     (index-i)* DLG_DEF_SPACE + (index-i) * INPUT_H,
                                     INPUT_W,
                                     (index-i)* DLG_DEF_SPACE + (index+1-i) * INPUT_H,
                                     (char **)selectlist
                                    );
    axismapping[i]->setLabelPlace(PUPLACE_CENTERED_LEFT);
    axismapping[i]->setLabel(Global::inputDev->AxisStringsGUI[i+1]);
    int item = Global::TXInterface->map->func[i+1];
    if (item < 0)
    {
      // disable (set to "K")
      item = numaxis;
    }
    axismapping[i]->setCurrentItem(item);
    axismapping[i]->setUserData(this);
    axismapping[i]->setCallback(CGUIMapCallback);

    invert[i] = new puButton(DLG_DEF_SPACE + INPUT_W,
                             4 + (index-i)* DLG_DEF_SPACE + (index-i) * INPUT_H,
                             DLG_DEF_SPACE + INPUT_W + DLG_CHECK_W,
                             4 + (index-i)* DLG_DEF_SPACE + (index-i) * INPUT_H + DLG_CHECK_H);
    invert[i]->setButtonType(PUBUTTON_VCHECK);
    invert[i]->setLabelPlace(PUPLACE_CENTERED_RIGHT);
    invert[i]->setLabel(_("Inv"));
    if (Global::TXInterface->map->inv[i+1] > 0)
    {
      invert[i]->setValue(0);
    }
    else
    {
      invert[i]->setValue(1);
    }
    invert[i]->setUserData(this);
    invert[i]->setCallback(CGUIMapCallback);
  }
  mapgroup->close();
  mapgroup->hide();

  // The combo box above the "mapping group"
  combo_radiotype = new puaComboBox(LABEL_W + DLG_DEF_SPACE,
                                   BUTTON_BOX_HEIGHT + (NUM_FUNCTIONS)* DLG_DEF_SPACE + (NUM_FUNCTIONS) * INPUT_H,
                                   LABEL_W + DLG_DEF_SPACE + COMBO_W,
                                   BUTTON_BOX_HEIGHT + (NUM_FUNCTIONS)* DLG_DEF_SPACE + (NUM_FUNCTIONS + 1) * INPUT_H,
                                   NULL, false);
  combo_radiotype->setChildColourScheme(PUCLASS_POPUPMENU, dlgCol1[0], dlgCol1[1], dlgCol1[2]);
  combo_radiotype->newList(radioTypes);
  combo_radiotype->setLabelPlace(PUPLACE_CENTERED_LEFT);
  combo_radiotype->setLabel(_("Radio type"));
  combo_radiotype->setUserData(this);
  combo_radiotype->setCurrentItem(Global::TXInterface->map->radioType());
  combo_radiotype->setCallback(CGUIComboCallback);

  if (combo_radiotype->getCurrentItem() == T_AxisMapper::CUSTOM)
  {
    mapgroup->reveal();
  }

  if ((Global::TXInterface->inputMethod() == T_TX_Interface::eIM_mouse)
        ||
      (Global::TXInterface->inputMethod() == T_TX_Interface::eIM_joystick))
  {
    Global::TXInterface->map->setRadioType(T_AxisMapper::CUSTOM);
    combo_radiotype->setCurrentItem(Global::TXInterface->map->radioType());
    combo_radiotype->hide();
  }
  else
  {
    combo_radiotype->reveal();
  }
  
  // The "calibration group" (right part of the dialog).
  calibgroup = new puGroup(LABEL_W + 3*DLG_DEF_SPACE + DLG_CHECK_W + INPUT_W + HORIZ_SPACER,
                           BUTTON_BOX_HEIGHT + DLG_DEF_SPACE);
  
  for (int i = 0; i < TX_MAXAXIS; i++)
  {
    axis[i] = new puSlider( i*SLIDER_SP + i * SLIDER_W,
                            LABEL_H + DLG_DEF_SPACE + DLG_DEF_BUTTON_HEIGHT,
                            SLIDER_SZ,
                            TRUE,
                            SLIDER_W);
    axis[i]->setLabelPlace(PUPLACE_BOTTOM_CENTERED);
    axis[i]->setLabel(axislabel[i]);
    axis[i]->setValue((float)0.5);
    
    // set min and max to some excessive values
    minval[i] = 1.0e30;
    maxval[i] = -1.0e30;
  }
  
  butCalibrate = new puOneShot( 0,
                                0,
                                DLG_DEF_BUTTON_WIDTH + 10,
                                DLG_DEF_BUTTON_HEIGHT);
  butCalibrate->setLegend(_("Calibrate"));
  butCalibrate->setLabelPlace(PUPLACE_BOTTOM_LEFT);
  butCalibrate->setLabel("");
  butCalibrate->setUserData(this);
  butCalibrate->setCallback(CGUICalibButtonCallback);
  
  if (Global::TXInterface->usesCalibration())
  {
    butCalibrate->reveal();
  }
  else
  {
    butCalibrate->hide();
  }

  calibgroup->close();

  close();
  
  //resize
  setSize(LABEL_W + (TX_MAXAXIS -1)*SLIDER_SP + DLG_DEF_SPACE+ DLG_CHECK_W + INPUT_W + 2*HORIZ_SPACER + TX_MAXAXIS * SLIDER_W,
          BUTTON_BOX_HEIGHT + (NUM_FUNCTIONS+3) * DLG_DEF_SPACE + (NUM_FUNCTIONS+1) * INPUT_H);
  
  
  setCallback(CGUICalibMapCallback);

  // center the dialog on screen
  int wwidth, wheight;
  int current_width = getABox()->max[0] - getABox()->min[0];
  int current_height = getABox()->max[1] - getABox()->min[1];
  puGetWindowSize(&wwidth, &wheight);
  setPosition(wwidth/2 - current_width/2, wheight/2 - current_height/2);
  
  //set the dialogue transparent  and hide the others dialogues to better see the model
  setTransparency(.3);
  hideOthers();
  
  reveal();

}
YInfoJumpListRecord::YInfoJumpListRecord(const QString & filename, const QPoint pos)
{
    mFilename = filename;
    setPosition(pos);
}
void TextDocumentManipulator::insertCodeSnippet(int position, const QString &text)
{
    auto cursor = m_textEditorWidget->textCursor();
    cursor.setPosition(position, QTextCursor::KeepAnchor);
    m_textEditorWidget->insertCodeSnippet(cursor, text);
}
Beispiel #12
0
bool Explosive::doAction(float _f)
{
#ifdef						GOLDEN_MINER_2_VERSION_TIME
	statusTimeCount += _f;
	double _positionX = 0;
	double _positionY = 0;
	float _ratio = (GRENADE_TIME/60.0 - statusTimeCount) / (GRENADE_TIME/60.0);
	if (_ratio < 0)
	{
		_ratio = 0;
	}
	if(hanger->carryTargetType == GAMECONTROL_TYPE_TARGET_STATIC)
	{
		_positionX = ((Target *)hanger->carryTargetPoint)->getPositionX() + (Global::getInstance()->getcentreX() - ((Target *)hanger->carryTargetPoint)->getPositionX()) * _ratio;
		_positionY = ((Target *)hanger->carryTargetPoint)->getPositionY() + (Global::getInstance()->getcentreY() - ((Target *)hanger->carryTargetPoint)->getPositionY()) * _ratio;
		setPosition(ccp(_positionX, _positionY));
	}
	else if (hanger->carryTargetType == GAMECONTROL_TYPE_TARGET_DYNAMIC)
	{
		if (((DynamicTarget *)hanger->carryTargetPoint)->getId() == DYNAMIC_ID_SHELL)
		{
			_positionX = ((DynamicTargetShell *)hanger->carryTargetPoint)->shellSprite->getPositionX() + (Global::getInstance()->getcentreX() - ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionX()) * _ratio;
			_positionY = ((DynamicTargetShell *)hanger->carryTargetPoint)->shellSprite->getPositionY() + (Global::getInstance()->getcentreY() - ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionY()) * _ratio;
		}
		else
		{
			_positionX = ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionX() + (Global::getInstance()->getcentreX() - ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionX()) * _ratio;
			_positionY = ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionY() + (Global::getInstance()->getcentreY() - ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionY()) * _ratio;
		}
		setPosition(ccp(_positionX, _positionY));
	}
	else
	{
		return true;
	}
	if ((statusTimeCount >= GRENADE_TIME/60.0)&& ((statusTimeCount - _f) >= GRENADE_TIME/60.0))
	{
		return true;
		//releaseSkills(SKILL_ID_GRENADE);	
	}
#else
	statusTimeCount++;
	double _positionX = 0;
	double _positionY = 0;
	if(hanger->carryTargetType == GAMECONTROL_TYPE_TARGET_STATIC)
	{
		_positionX = ((Target *)hanger->carryTargetPoint)->getPositionX() + (Global::getInstance()->getcentreX() - ((Target *)hanger->carryTargetPoint)->getPositionX()) * (GRENADE_TIME - statusTimeCount) / GRENADE_TIME;
		_positionY = ((Target *)hanger->carryTargetPoint)->getPositionY() + (Global::getInstance()->getcentreY() - ((Target *)hanger->carryTargetPoint)->getPositionY()) * (GRENADE_TIME - statusTimeCount) / GRENADE_TIME;
		setPosition(ccp(_positionX, _positionY));
	}
	else if (hanger->carryTargetType == GAMECONTROL_TYPE_TARGET_DYNAMIC)
	{
		if (((DynamicTarget *)hanger->carryTargetPoint)->getId() == DYNAMIC_ID_SHELL)
		{
			_positionX = ((DynamicTargetShell *)hanger->carryTargetPoint)->shellSprite->getPositionX() + (Global::getInstance()->getcentreX() - ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionX()) * (GRENADE_TIME - statusTimeCount) / GRENADE_TIME;
			_positionY = ((DynamicTargetShell *)hanger->carryTargetPoint)->shellSprite->getPositionY() + (Global::getInstance()->getcentreY() - ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionY()) * (GRENADE_TIME - statusTimeCount) / GRENADE_TIME;
		}
		else
		{
			_positionX = ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionX() + (Global::getInstance()->getcentreX() - ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionX()) * (GRENADE_TIME - statusTimeCount) / GRENADE_TIME;
			_positionY = ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionY() + (Global::getInstance()->getcentreY() - ((DynamicTarget *)hanger->carryTargetPoint)->getArmature()->getPositionY()) * (GRENADE_TIME - statusTimeCount) / GRENADE_TIME;
		}
		setPosition(ccp(_positionX, _positionY));
	}
	else
	{
		return true;
	}
	if (statusTimeCount == GRENADE_TIME)
	{
		return true;
		//releaseSkills(SKILL_ID_GRENADE);	
	}
#endif
	return false;
}
void OrthoViewControllerCustom::lookAt( const Ogre::Vector3& point )
{
  setPosition( point - target_scene_node_->getPosition() );
}
Beispiel #14
0
void clearTrajectory() {
    setPosition(0, 0, 0);
    lastLeft = 0.0f;
    lastRight = 0.0f;
    lastAngle = 0.0f;
}
BasicScreenObject::BasicScreenObject() {

  masktype = MASK_TYPE_CLIPPLANES;
  ismask = false;
  hasmask = false;

  setPosition(0, 0, 0);
  speed.set(0, 0, 0);
  accel.set(0, 0, 0);
  moveattractionforce = 0;
  movedrag = 1;

  setScale(1, 1, 1);
  width = height = 10;

  alpha = 255;
  setColor(255, 255, 255);
  tweenr = 255;
  tweeng = 255;
  tweenb = 255;
  isColorTweening = false;
  isFadeTweening = false;
  isFadeTweeningToInvisible = false;

  // Rotation
  rotationdrag = 0.99;
  rotationspeed.set(0, 0, 0);

  setRotationSpeed(0, 0, 0);
  setRotationDrag(0.99);
  rotationattractionforce = 0;
  rotationattractionquat.set(0, 0, 0, 1);
  rotationattractionangles.set(0, 0, 0);

  isRotationTweening = false;

  lightingbefore = false;
  lightingenabled = false;
  depthtestbefore = false;
  depthtestenabled = false;

  age = 0;
  _isAddedToRenderer = false;
  issetup = false; // TODO: issetup needed??

  parent_so = NULL;
  root = NULL;

  myEventArgs.target = this;

  sfactor = GL_SRC_ALPHA;
  dfactor = GL_ONE_MINUS_SRC_ALPHA;

  tweenx = 0;
  tweeny = 0;
  tweenz = 0;
  isMoveTweening = false;
  isSizeTweening = false;

  tweenscalex = 0;
  tweenscaley = 0;
  tweenscalez = 0;
  tweenrotslerp = 0.0;
  isScaleTweening = false;

  isvisible = true;
  _isParentTreeVisible = true;
  isorderbyz = false;
  isupdating = true;

  isRenderer = false;

  ofAddListener(ofEvents().setup, this, &BasicScreenObject::_setup);
  ofAddListener(ofEvents().update, this, &BasicScreenObject::_update);
  ofAddListener(ofEvents().exit, this, &BasicScreenObject::_exit);
  ofAddListener(killEvent, this, &BasicScreenObject::onKill);
  ofAddListener(hideEvent, this, &BasicScreenObject::onHide);
  ofAddListener(showEvent, this, &BasicScreenObject::onShow);
  ofAddListener(Tweener.onTweenCompleteEvent, this, &BasicScreenObject::onTweenComplete);
}
Beispiel #16
0
void Bullet::move(float dt) {
    setPosition(cocos2d::Vec2(getPositionX() + (velocity.x*dt),
                            getPositionY() + (velocity.y*dt)));
}
void BasicScreenObject::setPosition(float _x, float _y) {
  setPosition(_x, _y, getZ());
}
Beispiel #18
0
void HeroFrog::setCurPosition(Point pos){
    setPosition(pos);
    if (pos.x - downPoint.x>=0) {
        setHeroStatus(frogJumpDown);
    }
}
void BasicScreenObject::setY(float _y) {
  setPosition(getX(), _y, getZ());
}
void LevelSelectState::addLevel(LevelData lData, const std::string &map, bool enabled){

    sf::Vector2f windowSize(getContext().window->getSize());
    auto levelButton = std::make_shared<GUI::ContainerButton>(
         *getContext().textureManager);

    levelButton->setCallback(
        [this, map]() {
            requestStackPop();
            requestStackPush(State::ID::Loading, map);
        });

    GUI::Label::Ptr levelLabel;
    if (enabled){
        levelLabel = std::make_shared<GUI::Label>(
            lData.name,
            sf::Color::Black,
            28,
            *getContext().fontManager);

        GUI::Label::Ptr timeLabel;
        std::ostringstream timeStream;
        timeStream << lData.bestTime;
        timeLabel = std::make_shared<GUI::Label>(
            timeStream.str(),
            sf::Color::Black,
            32,
            *getContext().fontManager);
    }
    else{
        levelLabel = std::make_shared<GUI::Label>(
            lData.name,
            sf::Color(0,0,0,100),
            32,
            *getContext().fontManager);
        levelButton->disable();
    }  
    levelLabel->setOrigin(0.f, levelLabel->getOrigin().y);

    GUI::Label::Ptr timeLabel;

    if (lData.bestTime > 0.0f){
        std::ostringstream timeStream;
        timeStream << lData.bestTime;
        timeLabel = std::make_shared<GUI::Label>(
            timeStream.str(),
            sf::Color::Black,
            32,
            *getContext().fontManager);
    }
    else{
        std::ostringstream timeStream;
        timeStream << lData.bestTime;
        timeLabel = std::make_shared<GUI::Label>(
            timeStream.str(),
            sf::Color(0,0,0,100),
            32,
            *getContext().fontManager);
    }

    GUI::Number::Ptr numGems = std::make_shared<GUI::Number>(
        *getContext().textureManager, static_cast<unsigned int>(lData.requiredGems));

    sf::Texture &HUDTexture = getContext().textureManager->get(TextureID::HUDSpriteSheet);
    sf::IntRect rect;

    if (lData.collectedGem)
        rect = sf::IntRect(98, 185, 46, 36);
    else
        rect = sf::IntRect(98, 97, 46, 36);
    GUI::Image::Ptr gem = std::make_shared<GUI::Image>(
        HUDTexture, rect);

    if (lData.badgeEarned)
        rect = sf::IntRect(54, 49, 48, 48);
    else
        rect = sf::IntRect(54, 0, 48, 48);
    GUI::Image::Ptr badge = std::make_shared<GUI::Image>(
        HUDTexture, rect);
    
    levelButton->add(levelLabel);
    levelButton->add(timeLabel);
    levelButton->add(numGems);
    levelButton->add(gem);
    levelButton->add(badge);
    mLevelContainer->add(levelButton);
    float posX = windowSize.x * 0.5f;
    float firstButtonPadding = windowSize.y / 2.f - mLevelPanel.getGlobalBounds().height / 2.f + 100.f;
    float posY = static_cast<float>(firstButtonPadding + 100 * numLevels);
    levelButton->setPosition(posX, posY);
    
    levelLabel->move(-270, -10);
    timeLabel->move(0, -10);
    timeLabel->move(280, 0);
    numGems->move(-330, 0);
    gem->move(130, 0);
    badge->move(180, 0);

    ++numLevels;
}
Beispiel #21
0
void GameOver::update(float dt)
{
    
    
    second = second + 1;
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
     if(second == 1)
    {
        std::string pass_pic = "over/over.png";
        auto gameover_pass_pic = Sprite::create(pass_pic);
        gameover_pass_pic->setPosition(Vec2(origin.x + visibleSize.width/2-20,
                                            origin.y + visibleSize.height/2+150));
        this->addChild(gameover_pass_pic,103);
        /*
        auto gameover_score = Sprite::create("setting/gameoverscore.png");
        gameover_score->setPosition(Vec2(origin.x + visibleSize.width/2,
                                         origin.y + visibleSize.height/2+200));
        
        
        this->addChild(gameover_score,102);
        
        auto score_all = CCLabelTTF::create("",  "American Typewriter", 60);
        score_all->setColor(cocos2d::Color3B(100, 60, 60));
        score_all->retain();
        score_all->setPosition(origin.x + visibleSize.width/2+33,
                               origin.y + visibleSize.height/2+200);
        char str_1[100];
        sprintf(str_1, " %d ", score_this);
        score_all->setString(str_1);
        score_all->setVisible(true);
        this->addChild(score_all, 103);
        
        */
        
        
    }else if(second == 5)
    {
        auto tryAgainItem = MenuItemImage::create(
                                                  "setting/tryagain.png",
                                                  "setting/tryagain.png",
                                                  CC_CALLBACK_1(GameOver::menuTryAgainItemCallback, this));
        
        tryAgainItem->setPosition(Vec2(origin.x + visibleSize.width/2,
                                       origin.y + visibleSize.height/2));
    
        
        auto gameoverShareItem = MenuItemImage::create(
                                                       "setting/gameovershare.png",
                                                       "setting/gameovershare.png",
                                                       CC_CALLBACK_1(GameOver::menuGameoverShareItemCallback, this));
        
        gameoverShareItem->setPosition(Vec2(origin.x + visibleSize.width/2-250 ,
                                            origin.y + visibleSize.height/2-250));
        
        auto gameoverCommentItem = MenuItemImage::create(
                                                         "setting/gameovercomment.png",
                                                         "setting/gameovercomment.png",
                                                         CC_CALLBACK_1(GameOver::menuGameoverCommentItemCallback, this));
        
        gameoverCommentItem->setPosition(Vec2(origin.x + visibleSize.width/2+250 ,
                                              origin.y + visibleSize.height/2-250));
        
       auto backItem = MenuItemImage::create(
                                             "setting/backtomenu.png",
                                             "setting/backtomenu.png",
                                              CC_CALLBACK_1(GameOver::menuBackItemCallback, this));
        
        backItem->setPosition(Vec2(origin.x + visibleSize.width/2 ,
                                   origin.y + visibleSize.height/2-250));
        
        
        
        //auto menu = Menu::create(tryAgainItem, gameoverShareItem, gameoverCommentItem, backItem, NULL);
        auto menu = Menu::create(tryAgainItem, gameoverShareItem, gameoverCommentItem,backItem, NULL);
        menu->setPosition(Vec2::ZERO);
        this->addChild(menu,103);
        
    }
     
    
}
Beispiel #22
0
//------------------------------------------------------------------
//
// MenuLayer4
//
//------------------------------------------------------------------
MenuLayer4::MenuLayer4()
{
    MenuItemFont::setFontName("American Typewriter");
    MenuItemFont::setFontSize(18);
    auto title1 = MenuItemFont::create("Sound");
    title1->setEnabled(false);
    MenuItemFont::setFontName( "fonts/Marker Felt.ttf" );
    MenuItemFont::setFontSize(34);
    auto item1 = MenuItemToggle::createWithCallback( CC_CALLBACK_1(MenuLayer4::menuCallback, this),
                 MenuItemFont::create( "On" ),
                 MenuItemFont::create( "Off"),
                 nullptr );

    MenuItemFont::setFontName( "American Typewriter" );
    MenuItemFont::setFontSize(18);
    auto title2 = MenuItemFont::create( "Music" );
    title2->setEnabled(false);
    MenuItemFont::setFontName( "fonts/Marker Felt.ttf" );
    MenuItemFont::setFontSize(34);
    auto item2 = MenuItemToggle::createWithCallback(CC_CALLBACK_1(MenuLayer4::menuCallback, this),
                 MenuItemFont::create( "On" ),
                 MenuItemFont::create( "Off"),
                 nullptr );

    MenuItemFont::setFontName( "American Typewriter" );
    MenuItemFont::setFontSize(18);
    auto title3 = MenuItemFont::create( "Quality" );
    title3->setEnabled( false );
    MenuItemFont::setFontName( "fonts/Marker Felt.ttf" );
    MenuItemFont::setFontSize(34);
    auto item3 = MenuItemToggle::createWithCallback(CC_CALLBACK_1(MenuLayer4::menuCallback, this),
                 MenuItemFont::create( "High" ),
                 MenuItemFont::create( "Low" ),
                 nullptr );

    MenuItemFont::setFontName( "American Typewriter" );
    MenuItemFont::setFontSize(18);
    auto title4 = MenuItemFont::create( "Orientation" );
    title4->setEnabled(false);
    MenuItemFont::setFontName( "fonts/Marker Felt.ttf" );
    MenuItemFont::setFontSize(34);
    auto item4 = MenuItemToggle::createWithCallback(CC_CALLBACK_1(MenuLayer4::menuCallback, this),
                 MenuItemFont::create( "Off" ),
                 nullptr );

    // TIP: you can manipulate the items like any other MutableArray
    item4->getSubItems().pushBack( MenuItemFont::create( "33%" ) );
    item4->getSubItems().pushBack( MenuItemFont::create( "66%" ) );
    item4->getSubItems().pushBack( MenuItemFont::create( "100%" ) );

    // you can change the one of the items by doing this
    item4->setSelectedIndex( 2 );

    MenuItemFont::setFontName( "fonts/Marker Felt.ttf" );
    MenuItemFont::setFontSize( 34 );

    auto label = Label::createWithBMFont("fonts/bitmapFontTest3.fnt",  "go back");
    auto back = MenuItemLabel::create(label, CC_CALLBACK_1(MenuLayer4::backCallback, this) );

    auto menu = Menu::create(
                    title1, title2,
                    item1, item2,
                    title3, title4,
                    item3, item4,
                    back, nullptr ); // 9 items.

    menu->alignItemsInColumns(2, 2, 2, 2, 1, NULL);

    addChild( menu );

    auto s = Director::getInstance()->getWinSize();
    menu->setPosition(Vec2(s.width/2, s.height/2));
}
Beispiel #23
0
HiddenMask::HiddenMask(unsigned int width, unsigned int height, int x, int y)// : Image(width, height)
{
    setPosition({x, y});
}
Beispiel #24
0
//------------------------------------------------------------------
//
// MenuLayerMainMenu
//
//------------------------------------------------------------------
MenuLayerMainMenu::MenuLayerMainMenu()
{
    _touchListener = EventListenerTouchOneByOne::create();
    _touchListener->setSwallowTouches(true);
    _touchListener->onTouchBegan = CC_CALLBACK_2(MenuLayerMainMenu::onTouchBegan, this);
    _touchListener->onTouchMoved = CC_CALLBACK_2(MenuLayerMainMenu::onTouchMoved, this);
    _touchListener->onTouchEnded = CC_CALLBACK_2(MenuLayerMainMenu::onTouchEnded, this);
    _touchListener->onTouchCancelled = CC_CALLBACK_2(MenuLayerMainMenu::onTouchCancelled, this);

    _eventDispatcher->addEventListenerWithFixedPriority(_touchListener, 1);

    // Font Item
    auto spriteNormal = Sprite::create(s_MenuItem, Rect(0,23*2,115,23));
    auto spriteSelected = Sprite::create(s_MenuItem, Rect(0,23*1,115,23));
    auto spriteDisabled = Sprite::create(s_MenuItem, Rect(0,23*0,115,23));

    auto item1 = MenuItemSprite::create(spriteNormal, spriteSelected, spriteDisabled, CC_CALLBACK_1(MenuLayerMainMenu::menuCallback, this) );

    // Image Item
    auto item2 = MenuItemImage::create(s_SendScore, s_PressSendScore, CC_CALLBACK_1(MenuLayerMainMenu::menuCallback2, this) );

    // Label Item (LabelAtlas)
    auto labelAtlas = LabelAtlas::create("0123456789", "fonts/labelatlas.png", 16, 24, '.');
    auto item3 = MenuItemLabel::create(labelAtlas, CC_CALLBACK_1(MenuLayerMainMenu::menuCallbackDisabled, this) );
    item3->setDisabledColor( Color3B(32,32,64) );
    item3->setColor( Color3B(200,200,255) );
    CCLOG("test MenuItem Label getString: %s", item3->getString().c_str());
    // Font Item
    auto item4 = MenuItemFont::create("I toggle enable items", [&](Ref *sender) {
        _disabledItem->setEnabled(! _disabledItem->isEnabled() );
    });

    item4->setFontSizeObj(20);
    item4->setFontName("fonts/Marker Felt.ttf");

    // Label Item (LabelBMFont)
    auto label = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "configuration");
    auto item5 = MenuItemLabel::create(label, CC_CALLBACK_1(MenuLayerMainMenu::menuCallbackConfig, this));

    // Testing issue #500
    item5->setScale( 0.8f );

    // Events
    MenuItemFont::setFontName("fonts/Marker Felt.ttf");
    // Bugs Item
    auto item6 = MenuItemFont::create("Bugs", CC_CALLBACK_1(MenuLayerMainMenu::menuCallbackBugsTest, this));

    // Font Item
    auto item7= MenuItemFont::create("Quit", CC_CALLBACK_1(MenuLayerMainMenu::onQuit, this));

    auto item8 = MenuItemFont::create("Remove menu item when moving", CC_CALLBACK_1(MenuLayerMainMenu::menuMovingCallback, this));

    auto color_action = TintBy::create(0.5f, 0, -255, -255);
    auto color_back = color_action->reverse();
    auto seq = Sequence::create(color_action, color_back, nullptr);
    item7->runAction(RepeatForever::create(seq));

    auto menu = Menu::create( item1, item2, item3, item4, item5, item6, item7, item8,  nullptr);
    menu->alignItemsVertically();


    // elastic effect
    auto s = Director::getInstance()->getWinSize();

    int i=0;
    for(const auto &child : menu->getChildren()) {
        auto dstPoint = child->getPosition();
        int offset = (int) (s.width/2 + 50);
        if( i % 2 == 0)
            offset = -offset;

        child->setPosition( Vec2( dstPoint.x + offset, dstPoint.y) );
        child->runAction(
            EaseElasticOut::create(MoveBy::create(2, Vec2(dstPoint.x - offset,0)), 0.35f)
        );
        i++;
    }

    _disabledItem = item3;
    item3->retain();
    _disabledItem->setEnabled( false );

    addChild(menu);
    menu->setPosition(Vec2(s.width/2, s.height/2));
    menu->setScale(0);
    menu->runAction(ScaleTo::create(1,1));
}
Beispiel #25
0
void Item::setPosition(int x, int y) {
	setPosition(Point<int>(x, y));
}
Beispiel #26
0
void TextBox::setPosition(float x, float y){ setPosition(sf::Vector2f(x, y)); }
Beispiel #27
0
void Widget::setTop( int newTop )
{
  setPosition( Point( getLeft(), newTop ) );    
}
Beispiel #28
0
void UIUtils::checkShowLeadHand(cocos2d::Node * rootWidget)
{
    if (m_leadHandMap == nullptr || rootWidget == nullptr) return;
    
    bool isRight = false;
    
    std::string curUIName = rootWidget->getName();
    auto iter = m_leadHandMap->find(curUIName);
    if (iter == m_leadHandMap->end()) {
        return;
    }
    else {
        isRight = iter->second.asBool();
        syncLeadHandShowUI(curUIName, false, false);
    }
    
    const char * LAYER_NAME = "leadHandLayer";
    auto leadHandLayer = rootWidget->getChildByName(LAYER_NAME);
    if (!leadHandLayer) {
        leadHandLayer = CSLoader::createNode("LeadHandLayer.csb");
        leadHandLayer->setName(LAYER_NAME);
        rootWidget->addChild(leadHandLayer);
    }
    leadHandLayer->setVisible(true);
    
    auto layout_leadHand = leadHandLayer->getChildByName<Layout *>("Layout_LeadHand");
    auto img_Hand = layout_leadHand->getChildByName<ImageView *>("Image_Hand");
    auto img_ArrowToRight = layout_leadHand->getChildByName<ImageView *>("Image_ArrowToRight");
    auto img_ArrowToLeft = layout_leadHand->getChildByName<ImageView *>("Image_ArrowToLeft");
    auto visibleSize = Director::getInstance()->getVisibleSize();
    
    Vec2 oriPos;
    Vec2 desPos;
    ImageView * img_Arrow = img_ArrowToRight;
    if (isRight) {
        // 手势向右
        oriPos = Vec2(visibleSize.width * 0.33, visibleSize.height * 0.65);
        desPos = Vec2(visibleSize.width * 0.5, visibleSize.height * 0.65);
        img_Arrow = img_ArrowToRight;
        img_Hand->setAnchorPoint(Vec2(0, 1));
    }
    else {
        // 手势向左
        oriPos = Vec2(visibleSize.width * 0.67, visibleSize.height * 0.65);
        desPos = Vec2(visibleSize.width * 0.5, visibleSize.height * 0.65);
        img_Arrow = img_ArrowToLeft;
        img_Hand->setAnchorPoint(Vec2(1, 1));
    }
    
    Sequence * runHandSequence = Sequence::create(
                                                MoveTo::create(1, desPos),
                                                FadeOut::create(1),
                                                CallFunc::create([=]()
                                                                 {
                                                                     img_Hand->setOpacity(255);
                                                                     img_Hand->setPosition(oriPos);
                                                                 }),
                                                NULL
                                                  );
    
    Sequence * runArrowSequence = Sequence::create(
                                              DelayTime::create(0.2),
                                              CallFunc::create([=]()
                                                                {
                                                                    img_Arrow->setVisible(true);
                                                                }),
                                              MoveTo::create(0.8, desPos),
                                              FadeOut::create(1),
                                              CallFunc::create([=]()
                                                               {
                                                                   img_Arrow->setVisible(false);
                                                                   img_Arrow->setOpacity(255);
                                                                   img_Arrow->setPosition(oriPos);
                                                               }),
                                              NULL
                                              );
    
    img_Arrow->setVisible(false);
    img_Arrow->setPosition(oriPos);
    img_Arrow->runAction(RepeatForever::create(runArrowSequence));
    
    img_Hand->setPosition(oriPos);
    img_Hand->runAction(RepeatForever::create(runHandSequence));
    
}
bool LevelThirteen::init()
{
	if (!Layer::init())
	{
		return false;
	}

	// 用于解决刚体穿透问题
	this->scheduleUpdate();
	// 计时器
	this->schedule(schedule_selector(LevelThirteen::timeCounter), 1.0f);

	auto visibleSize = Director::getInstance()->getVisibleSize();
	auto origin = Director::getInstance()->getVisibleOrigin();

	// 加载背景贴图
	auto spriteBg = Sprite::create("background.png");
	spriteBg->setAnchorPoint(Vec2::ZERO);
	spriteBg->setPosition(Vec2::ZERO);
	addChild(spriteBg);

	ballOne = Sprite::createWithSpriteFrameName("hero.png");
	ballOne->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f);
	auto ballBodyOne = PhysicsBody::createCircle(ballOne->getContentSize().width / 2, PHYSICSBODY_MATERIAL_DEFAULT);
	//是否设置物理为静态
	//ballBodyOne->setDynamic(false);
	//设置物理的恢复力
	ballBodyOne->getShape(0)->setRestitution(0.5f);
	//设置物体的摩擦力
	ballBodyOne->getShape(0)->setFriction(0.0f);
	ballBodyOne->getShape(0)->setDensity(0.3f);
	// 设置质量 质量等于密度乘以面积
	//ballBodyOne->getShape(0)->setMass(5000);
	// 设置物体是否受重力系数影响
	ballBodyOne->setGravityEnable(true);
	ballBodyOne->setCategoryBitmask(1);// 分类掩码
	ballBodyOne->setCollisionBitmask(1 | 2 | 4 | 8);// 碰撞掩码
	ballBodyOne->setContactTestBitmask(2);// 接触测试掩码

	// 把物体添加到精灵
	ballOne->setPhysicsBody(ballBodyOne);
	this->addChild(ballOne);

	// 创建抢食者(黑色)
	Sprite* black = nullptr;
	PhysicsBody* blackBody = nullptr;
	Vec2 arrBlack[] =
	{
		Vec2(-34.00000, -32.50000),
		Vec2(-15.00000, 36.00000),
		Vec2(35.00000, -15.00000)
	};
	int indexBlack = CCRANDOM_0_1() * 3;
	switch (indexBlack)
	{
	case 0:
	{
			  black = Sprite::createWithSpriteFrameName("black1.png");
			  blackBody = PhysicsBody::createBox(black->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT);
	}
		break;
	case 1:
	{
			  black = Sprite::createWithSpriteFrameName("black2.png");
			  blackBody = PhysicsBody::createCircle(black->getContentSize().width / 2.0f, PHYSICSBODY_MATERIAL_DEFAULT);
	}
		break;
	case 2:
	{
			  black = Sprite::createWithSpriteFrameName("black3.png");
			  blackBody = PhysicsBody::createPolygon(arrBlack, 3, PHYSICSBODY_MATERIAL_DEFAULT);
	}
		break;
	default:
		break;
	}
	black->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f);
	blackBody->setDynamic(true);
	blackBody->setGravityEnable(false);
	blackBody->setCategoryBitmask(8);
	blackBody->setCollisionBitmask(1 | 2 | 4 | 8);
	blackBody->setContactTestBitmask(2);
	black->setPhysicsBody(blackBody);
	this->addChild(black);

	//创建一个盒子,用来碰撞
	auto edgeSpace = Sprite::create();
	auto boundBody = PhysicsBody::createEdgeBox(visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3);
	boundBody->getShape(0)->setFriction(0.0f);
	boundBody->getShape(0)->setRestitution(1.0f);

	edgeSpace->setPhysicsBody(boundBody);
	edgeSpace->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
	this->addChild(edgeSpace);
	edgeSpace->setTag(0);

	boundBody->setCategoryBitmask(4);
	boundBody->setCollisionBitmask(1 | 2 | 4 | 8);
	boundBody->setContactTestBitmask(0);

	// 随机位置
	int index = CCRANDOM_0_1() * 4;
	auto suiji1 = 0;
	auto suiji2 = 0;
	auto suiji3 = 0;
	switch (index)
	{
	case 0:
		suiji1 = CCRANDOM_0_1() * 240;
		suiji2 = -CCRANDOM_0_1() * 100;
		suiji3 = -CCRANDOM_0_1() * 150;
		break;
	case 1:
		suiji1 = -CCRANDOM_0_1() * 240;
		suiji2 = -CCRANDOM_0_1() * 100;
		suiji3 = -CCRANDOM_0_1() * 150;
		break;
	case 2:
		suiji1 = -CCRANDOM_0_1() * 240;
		suiji2 = CCRANDOM_0_1() * 100;
		suiji3 = CCRANDOM_0_1() * 150;
		break;
	case 3:
		suiji1 = CCRANDOM_0_1() * 240;
		suiji2 = CCRANDOM_0_1() * 100;
		suiji3 = CCRANDOM_0_1() * 150;
		break;
	default:
		break;
	}
	// 创建yuan
	auto white1 = Sprite::createWithSpriteFrameName("white2.png");
	white1->setPosition(visibleSize.width / 2.0f + 200.0f, visibleSize.height / 2.0f - 200.0f);
	auto whiteBody1 = PhysicsBody::createCircle(white1->getContentSize().width / 2.0f, PHYSICSBODY_MATERIAL_DEFAULT);
	whiteBody1->setDynamic(false);
	whiteBody1->setCategoryBitmask(4);
	whiteBody1->setCollisionBitmask(1 | 2 | 4 | 8);
	whiteBody1->setContactTestBitmask(0);
	white1->setPhysicsBody(whiteBody1);
	this->addChild(white1);

	// 正方形
	auto white1_2 = Sprite::createWithSpriteFrameName("white1.png");
	white1_2->setPosition(visibleSize.width / 2.0f - 200.0f, visibleSize.height / 2.0f + 200.0f);
	auto whiteBody1_2 = PhysicsBody::createBox(white1_2->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT);
	whiteBody1_2->setDynamic(false);
	whiteBody1_2->setCategoryBitmask(4);
	whiteBody1_2->setCollisionBitmask(1 | 2 | 4 | 8);
	whiteBody1_2->setContactTestBitmask(0);
	white1_2->setPhysicsBody(whiteBody1_2);
	this->addChild(white1_2);

	// 创建三角形
	Vec2 arr[] =
	{
		Vec2(-16.50000, 36.00000),
		Vec2(35.50000, -15.00000),
		Vec2(-34.00000, -32.50000)
	};
	auto white3 = Sprite::createWithSpriteFrameName("white3.png");
	white3->setPosition(visibleSize.width / 2.0f + suiji3, visibleSize.height / 2.0f + suiji2);
	auto whiteBody3 = PhysicsBody::createPolygon(arr, 3, PHYSICSBODY_MATERIAL_DEFAULT);
	whiteBody3->setDynamic(false);
	whiteBody3->setCategoryBitmask(4);
	whiteBody3->setCollisionBitmask(1 | 2 | 4 | 8);
	whiteBody3->setContactTestBitmask(0);
	white3->setPhysicsBody(whiteBody3);
	this->addChild(white3);

	
	auto rotation_1 = RotateBy::create(2, 360);
	auto rotationback_1 = rotation_1->reverse();
	auto seq1 = Sequence::create(rotation_1, rotationback_1, nullptr);
	auto repeat1 = RepeatForever::create(seq1);
	white1_2->runAction(repeat1);

	auto yuantong0 = Sprite::createWithSpriteFrameName("yuantong.png");
	yuantong0->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height + yuantong0->getContentSize().height / 2.0f));

	auto yuantongBody = PhysicsBody::createBox(yuantong0->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT);
	yuantongBody->setDynamic(false);
	yuantongBody->setCategoryBitmask(4);
	yuantongBody->setCollisionBitmask(1 | 2 | 4 | 8);
	yuantongBody->setContactTestBitmask(0);
	yuantong0->setPhysicsBody(yuantongBody);
	this->addChild(yuantong0);

	auto moveby0 = MoveBy::create(1.0f, Vec2(0, -90));
	auto moveby0back = moveby0->reverse();
	auto easein = EaseBackIn::create(moveby0);
	auto seq0 = Sequence::create(easein, CallFuncN::create(CC_CALLBACK_1(LevelThirteen::callbackC, this)), moveby0back, nullptr);
	auto repeat0 = RepeatForever::create(seq0);
	yuantong0->runAction(repeat0);

	listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [=](Touch* touch, Event* event){
		auto touchPosition = touch->getLocation();

		Vec2 force = Vec2::ZERO;
		if ((touchPosition.x > visibleSize.width / 2.0f) && (touchPosition.y < visibleSize.height / 2.0f))
		{
			force = Vec2(50000.0f, 0.0f);
		}
		else if ((touchPosition.y < visibleSize.height / 2.0f) && (touchPosition.x < visibleSize.width / 2.0f))
		{
			force = Vec2(-50000.0f, 0.0f);
		}
		else
		{
			force = Vec2(0.0f, 50000.0f);
		}

		ballOne->getPhysicsBody()->applyImpulse(force);

		return true;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	// 时间显示文本
	test = LabelAtlas::create(StringUtils::toString(nGoal), "1.png", 14, 21, '0');
	test->setScale(2.0f);
	test->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	test->setPosition(Vec2(test->getContentSize().width + 10, visibleSize.height - test->getContentSize().height));
	this->addChild(test);

	test2 = LabelAtlas::create(StringUtils::toString(newTimes), "1.png", 14, 21, '0');
	test2->setScale(2.0f);
	test2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	test2->setPosition(Vec2(visibleSize.width - test2->getContentSize().width - 10, visibleSize.height - test2->getContentSize().height));
	this->addChild(test2);

	test3 = LabelAtlas::create(StringUtils::toString(nTimes), "1.png", 14, 21, '0');
	test3->setScale(2.0f);
	test3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	test3->setPosition(Vec2(test3->getContentSize().width*4.0f + 40, visibleSize.height - test3->getContentSize().height));
	this->addChild(test3);

	return true;
}
Beispiel #30
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();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
    
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
    
    // position the label on the center of the screen
    label->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - label->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(label, 1);

    // add "HelloWorld" splash screen"
    auto sprite = Sprite::create("HelloWorld.png");
    
    //
    //  My game code
    //
    
    // create hero sprite
    auto hero = Sprite::create("hero.png");
    
    // position the sprite on the center of the screen
    sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    hero->setPosition(Vec2(origin.x + 200, origin.y + 200));

    // add the sprite as a child to this layer
    this->addChild(sprite, 0);
    this->addChild(hero, 1, kTagSprite);
    
    // move hero (only last action will be run)
    //hero->runAction(MoveTo::create(2, Vec2(50, 50)));
    auto moveBy = MoveBy::create(0.3, Vec2(100, 100));
    auto shrinkSize = ScaleBy::create(0.5f, 0.5f);
    auto growSize = ScaleBy::create(0.5f, 2.0f);
    hero->runAction(Sequence::create(moveBy, shrinkSize, moveBy, growSize, nullptr));
    
    // event listener code for touch events
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = [](cocos2d::Touch* touch, cocos2d::Event  *event) {
        return true;
    };
    listener->onTouchEnded = [=](cocos2d::Touch* touch, cocos2d::Event  *event) {
        hero->runAction( MoveTo::create(0.2, touch->getLocation() ) );
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

    
    //this->schedule(schedule_selector(HelloWorld::update));
    TMXTiledMap *map = TMXTiledMap::create("isometric_grass_and_water.tmx");
    addChild(map, 0);
    
    return true;
}