当前位置: 首页>>代码示例>>C++>>正文


C++ Sprite::setScale方法代码示例

本文整理汇总了C++中sf::Sprite::setScale方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::setScale方法的具体用法?C++ Sprite::setScale怎么用?C++ Sprite::setScale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::Sprite的用法示例。


在下文中一共展示了Sprite::setScale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: drawSprite

void drawSprite(int x, int y, double w, double h, TextureIndex textureIndex)
{
	freeSprite.setPosition(x, y);
	freeSprite.setTexture(getTexture(textureIndex));
	freeSprite.setScale(w / getTexture(textureIndex).getSize().x, h / getTexture(textureIndex).getSize().y);
	window->draw(freeSprite);
}
开发者ID:MatthewBregg,项目名称:TraderGame,代码行数:7,代码来源:GlobalValues.cpp

示例2: resize

void resize(sf::Sprite& sprite, float width, float height)
{
    int local_width  = sprite.getTextureRect().width;
    int local_height = sprite.getTextureRect().height;

    if ((local_width > 0) && (local_height > 0))
        sprite.setScale(width / local_width, height / local_height);
}
开发者ID:abodelot,项目名称:cosmoscroll,代码行数:8,代码来源:SFML_Helper.cpp

示例3: init

void WindowCreateThing::init(sf::RenderWindow &window) {

    rectTitle.setSize(sf::Vector2f(window.getSize().x*0.45, window.getSize().y*0.07));
    rectTitle.setPosition(sf::Vector2f(window.getSize().x/2-(rectTitle.getSize().x/2), window.getSize().x/4-(rectTitle.getSize().y/2)));
    rectTitle.setFillColor(sf::Color(158, 158, 158));
    rectTitle.setOutlineColor(sf::Color::Black);
    rectTitle.setOutlineThickness(1.f);

    rectMain.setSize(sf::Vector2f(window.getSize().x*0.45,window.getSize().y*0.45));
    rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y));
    rectMain.setFillColor(sf::Color::White);
    rectMain.setOutlineColor(sf::Color::Black);
    rectMain.setOutlineThickness(1.f);

    load();


    starting_position = sf::Mouse::getPosition(window);



    textTitle.setFont(font);
    textTitle.setString("CreateThings.txt");
    textTitle.setCharacterSize(24);
    textTitle.setColor(sf::Color::White);
    textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1));
    //textTitle.setPosition(sf::Vector2f(400,10));

    textClose.setFont(font);
    textClose.setString("X");
    textClose.setStyle(sf::Text::Bold);
    textClose.setCharacterSize(35);
    textClose.setColor(sf::Color::White);
    textClose.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x-30, rectTitle.getPosition().y+rectTitle.getSize().y*0.05));


    ///// FOLDER ICONE
    textureFolder.setSmooth(true);
    spriteFodler.setTexture(textureFolder);
    sf::Vector2f targetSize(25.0f, 25.0f);
    spriteFodler.setScale(
        targetSize.x / spriteFodler.getLocalBounds().width,
        targetSize.y / spriteFodler.getLocalBounds().height);
    spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-targetSize.x, textTitle.getPosition().y));




    ///// CLOSE ICONE
    /*textureClose.setSmooth(true);
    spriteClose.setTexture(textureClose);
    sf::Vector2f targetSize2(window.getSize().y*0.07, window.getSize().y*0.07);
    spriteClose.setScale(
        targetSize2.x / spriteClose.getLocalBounds().width,
        targetSize2.y / spriteClose.getLocalBounds().height);
    spriteClose.setPosition(rectTitle.getPosition().x+rectTitle.getSize().x-targetSize2.x, rectTitle.getPosition().y);*/
}
开发者ID:3991,项目名称:Game-25486,代码行数:57,代码来源:WindowCreateThing.hpp

示例4: init

	virtual void init()
	
	
	{
		dt=0;
		select_switch = 0.2;
		
		if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
    // error...
}
	//	darken = sf::RectangleShape(sf::Vector2f(800,400));
		
//sfx
if (!buffer.loadFromFile("sfx/Blip 007.wav"))

{
     //error
}
blip.setBuffer(buffer);


		if(!title.loadFromFile("gfx/title.png"))std::cout<<"Error"<<std::endl;

		tits.setTexture(title);
		tits.setOrigin(50,8);
		tits.setScale(sf::Vector2f(3,3));
		tits.setPosition(400,100);
		
		sf::FloatRect tempt ;
		
		for(int i =0 ; i<4;i++)
		{
			selector[i].setFont(standard_font);
			selector[i].setCharacterSize(28);
			 
		
		// dla centrowania obiektow
		
			tempt = selector[i].getGlobalBounds();
			selector[i].setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
			
			selector[i].setPosition(350,150+30*i);
		}
		
		selector[0].setString("Start game");
		selector[1].setString("Info");
		selector[2].setString("Highscores");
		selector[3].setString("Exit");
		
		
		selector[0].setColor(sf::Color(0,127,127));
		
		timer.restart();
		
		};
开发者ID:TarasJan,项目名称:Sleepwalker,代码行数:56,代码来源:menu.cpp

示例5: setSprite

 void AnimatableSprite::setSprite(sf::Sprite sprite)
 {
     sf::Vector2f center = getCenterPosition();
     sf::Vector2f scale = _sprite.getScale();
     sf::Color color = _sprite.getColor();
     sprite.setScale(scale);
     sprite.setColor(color);
     _sprite = sprite;
     setCenterPosition(center);
 }
开发者ID:ZwodahS,项目名称:z_framework,代码行数:10,代码来源:AnimatableSprite.cpp

示例6:

	Goomba(float i, float j) {
		_rect.setSize(sf::Vector2f(32, 32));
		_rect.setFillColor(sf::Color::Blue);
		if (_textureG.loadFromFile("goomba.png")) {
			_textureG.setSmooth(true);
			_spriteG.setTexture(_textureG);
			_spriteG.setScale(1.9, 1.9);
		}
		_spriteG.setPosition(50, 350);
	}
开发者ID:W0Z4,项目名称:ProjetMario,代码行数:10,代码来源:Goomba.hpp

示例7: transformSprite

void GraphicEngine::transformSprite(sf::Sprite& sprite, const Transformation& t, const Color& color)
{
	if (t.hasPosition())
		sprite.setPosition((float)t.getX(), (float)t.getY());
	if (t.hasRotation())
		sprite.rotate(t.getRotation());
	if (color.isUsed())
		sprite.setColor(sf::Color(color.getColor()));
	if (t.hasScale())
		sprite.setScale(t.getScaleX(), t.getScaleY());
}
开发者ID:sebastiencs,项目名称:R-Type,代码行数:11,代码来源:GraphicEngine.cpp

示例8: ajouterMissileVaisseau

sf::Sprite Missile::ajouterMissileVaisseau(sf::Sprite sp, float posMissileX, float posMissileY)
{

    if (!missile.loadFromFile("ressource/missile.png", sf::IntRect(0, 0, 100,100)))
    {
        std::cout<<"Erreur durant le chargement de l'image missile"<<std::endl;
        return sp; // On ferme le programme
    }
    else
    {
        sp.setTexture(missile);
        sp.setScale(0.5f, 0.5f);    //setScale peut changer la taille
        sp.setColor(sf::Color(0, 255, 0));
        sp.setPosition(posMissileX, posMissileY);
        return sp;
    }
}
开发者ID:l3info-MBT,项目名称:Space_Wars,代码行数:17,代码来源:Missile.cpp

示例9: StaticBGImpl

 StaticBGImpl(const std::string & src_file, 
     unsigned int wwidth, unsigned int wheight, unsigned int iwidth, unsigned int iheight)
 : m_texture(new sf::Texture), m_sprite(0),
   m_wwidth(wwidth), m_wheight(wheight), m_iwidth(iwidth), m_iheight(iheight)
 {
     if(!m_texture->loadFromFile(src_file))
     {
         std::cerr << "StaticBG, could not load texture from: " << src_file << std::endl;
     }
     m_sprite = new sf::Sprite(*m_texture);
     if(iwidth == 0 || iheight == 0)
     {
         m_iwidth  = m_wwidth;
         m_iheight = m_wheight;
     }
     m_sprite->setScale((float)m_iwidth/(float)m_wwidth, (float)m_iheight/(float)m_wheight);
     m_sprite->setPosition((float)(m_wwidth/2 - m_iwidth/2), (float)(m_wheight/2 - m_iheight/2));
 }
开发者ID:gergondet,项目名称:bci-interface,代码行数:18,代码来源:StaticBG.cpp

示例10: main

int main(int argc, char** argv)
{
	sf::RenderWindow window(sf::VideoMode(1000, 1000), "Physics Game!");

  delete world;
  CreateWorld();

  int currentLevel = 1;

  #pragma region Background Graphics
  // Load the background images, create a sprite and assign the image.
  // Sky
  sf::Texture backgroundTexture;
  backgroundTexture.loadFromFile("assets/Sky.png");
  backgroundTexture.setSmooth(true);
  backgroundTexture.setRepeated(true);
  sf::Sprite background;
  background.setPosition(0,0);
  background.setScale((float)window.getSize().x,1.0f);
  background.setTexture(backgroundTexture);

  // Sun
  sf::Texture sunTexture;
  sunTexture.loadFromFile("assets/Sun.png");
  sunTexture.setSmooth(true);
  sunTexture.setRepeated(true);
  sf::Sprite sun;
  sun.setPosition((window.getSize().x - (250*0.6f)) - window.getSize().x * 0.1f , 100);
  sun.setScale(0.6f,0.6f);
  sun.setTexture(sunTexture);

  // Cloud
  sf::Texture cloud1Texture;
  cloud1Texture.loadFromFile("assets/Cloud1.png");
  cloud1Texture.setSmooth(true);
  cloud1Texture.setRepeated(false);
  sf::Sprite cloud1;
  cloud1.setPosition(window.getSize().x*0.15f,80);
  cloud1.setScale(1.0f,1.0f);
  cloud1.setTexture(cloud1Texture);

  // Hills
  sf::Texture hillsTexture;
  hillsTexture.loadFromFile("assets/Hills.png");
  hillsTexture.setSmooth(false);
  hillsTexture.setRepeated(true);
  sf::Sprite hills1;
  hills1.setPosition(0,(float)window.getSize().y - 184);
  hills1.setScale(1.0f ,1.0f);
  hills1.setTexture(hillsTexture);
  sf::Sprite hills2;
  hills2.setPosition(766,(float)window.getSize().y - 184);
  hills2.setScale(1.0f,1.0f);
  hills2.setTexture(hillsTexture);
  sf::Sprite hills3;
  hills3.setPosition(766*2,(float)window.getSize().y - 184);
  hills3.setScale(1.0f,1.0f);
  hills3.setTexture(hillsTexture);
  #pragma endregion

	// Prepare for simulation. Typically we use a time step of 1/60 of a
	// second (60Hz) and 10 iterations. This provides a high quality simulation
	// in most game scenarios.
	float32 timeStep = 1.0f / 30.0f;
	int32 velocityIterations = 8;
	int32 positionIterations = 3;

  std::vector<shape> lines;

  sf::Texture wheel;
  wheel.loadFromFile("assets/Wheel.png");
  wheel.setSmooth(true);

  sf::Texture bikeWheel;
  bikeWheel.loadFromFile("assets/BikeWheel.png");
  bikeWheel.setSmooth(true);

  sf::Texture bikeFrame_t;
  bikeFrame_t.loadFromFile("assets/BikeFrame.png");
  bikeFrame_t.setSmooth(true);

  #pragma region events
  while (window.isOpen()) {

    static sf::Clock deltaClock;
    sf::Time deltaTime = deltaClock.restart();

    static float time;
    time += deltaTime.asSeconds() * 5;

    sf::Event event;
    while (window.pollEvent(event))
    {
      // If the window is closed, close the SFML window
      switch (event.type) {

      case sf::Event::Closed:
          window.close();
          break;

//.........这里部分代码省略.........
开发者ID:DaveRune,项目名称:SFML-Box2D,代码行数:101,代码来源:main.cpp

示例11: setToolTipScale

inline void ManageLevel::setToolTipScale (sf::Vector2f _scale)
{
    m_tooltip.setScale(_scale);
}
开发者ID:guillaume-gomez,项目名称:MathGame,代码行数:4,代码来源:ManageLevel.hpp

示例12: supprimerMissile

sf::Sprite Missile::supprimerMissile(sf::Sprite sp)
{
    sp.setScale(0.0f, 0.0f);
    sp.setPosition(0.0f, 0.0f);
    return sp;
}
开发者ID:l3info-MBT,项目名称:Space_Wars,代码行数:6,代码来源:Missile.cpp

示例13: resize

void resize(sf::Sprite& sprite, float x, float y)
{
  sprite.setScale( x / sprite.getGlobalBounds().width,
                   y / sprite.getGlobalBounds().height );
}
开发者ID:bdajeje,项目名称:Squares,代码行数:5,代码来源:graphics.cpp

示例14: update

void update(sf::RectangleShape floor[], sf::RectangleShape road[], int floorWidth, int floorHeightPosition, sf::Sprite& rrSprite, double &pos, bool &jumpStatus,
     bool& isoverlap, std::stringstream &ss, sf::Clock &clock, sf::Text &textTime, sf::Music& roadrunnerMusic, sf::Music& sanicMusic, sf::Sound& squawkSound, 
     bool& deathStatus, sf::Sprite& sanicSprite, sf::Sprite& sanicPowerupSprite, bool& sanicPowerupStatus, int& globalSpeed, sf::Time& sanicTime, bool& powerupSpawnStatus, 
     sf::Time& powerupSpawnTimer, sf::Sprite arrayOfObjectSprite[], bool& boulderSpawnStatus, int numObject, int objStop, sf::Sound& jumpSound, sf::RectangleShape backgroundbox[])
{
	//game timer
     if (!isoverlap)
	{
		sf::Time time1 = clock.getElapsedTime();
		ss.str(std::string());
		ss << setprecision(2) << fixed << static_cast<double>(time1.asSeconds());
		textTime.setString(ss.str().c_str());
	}

     // Return to roadrunner character
     if (clock.getElapsedTime() >= sanicTime && sanicPowerupStatus)
     {
          sanicMusic.pause();
          roadrunnerMusic.play();
          sanicPowerupStatus = false;
     }

     // How fast everything moves
     if (sanicPowerupStatus && (clock.getElapsedTime() <= sanicTime - sf::seconds(1)))         //sanic run speed
          globalSpeed = 100;
     else
          globalSpeed = 15;                                                                    //roadrunner run speed

     // Powerup spawner, checks every 10 seconds
     if (clock.getElapsedTime() >= powerupSpawnTimer)
     {
          powerupSpawnTimer += sf::seconds(10);                       //time to spawn for every consecutive powerup after the first
          powerupSpawnStatus = true;
     }

     // Powerup spawn chance
     if (powerupSpawnStatus)
     {
          if (rand() % 100 <= 33)                                 // 33% chance to spawn
          {
               sanicPowerupSprite.setScale(0.05, 0.05);
               sanicPowerupSprite.setPosition(floorWidth, 250);
          }
          powerupSpawnStatus = false;
     }

     // Sanicpowerup movement, how fast the icon moves
     if (sanicPowerupSprite.getPosition().x >= objStop)
          sanicPowerupSprite.move(-globalSpeed, 0);

     // Roadrunner and sanicpowerup collision
     if (overlap(rrSprite, sanicPowerupSprite) && !sanicPowerupStatus)
     {
          roadrunnerMusic.pause();
          sanicMusic.play();
          sanicPowerupStatus = true;
          sanicTime = clock.getElapsedTime() + sf::seconds(10);
          sanicPowerupSprite.setScale(0, 0);
     }

     //Infinite floor/road
     floor[0].move(-globalSpeed, 0);
     floor[1].move(-globalSpeed, 0);

     road[0].move(-globalSpeed, 0);
     road[1].move(-globalSpeed, 0);
     
     if (floor[0].getPosition().x <= -floorWidth)
	{
		floor[0].setPosition(0, floorHeightPosition);
		floor[1].setPosition(floorWidth, floorHeightPosition);

          road[0].setPosition(0, floorHeightPosition);
          road[1].setPosition(floorWidth, floorHeightPosition);
	}

     //backgroundbox, movement, infinite background
     if (sanicPowerupStatus && (clock.getElapsedTime() <= sanicTime - sf::seconds(1)))
     {
          backgroundbox[0].move(-globalSpeed / 2 + 10, 0);
          backgroundbox[1].move(-globalSpeed / 2 + 10, 0);
     }
     else
     {
          backgroundbox[0].move(-globalSpeed + 10, 0);
          backgroundbox[1].move(-globalSpeed + 10, 0);
     }

     if (backgroundbox[0].getPosition().x <= -floorWidth)
     {
          backgroundbox[0].setPosition(0, -100);
          backgroundbox[1].setPosition(floorWidth, -100);
     }
     
    
	// Roadrunner jump
     if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && rrSprite.getPosition().y >= 505)
	{
		jumpStatus = true;
          jumpSound.play();
//.........这里部分代码省略.........
开发者ID:DevelopersGuild,项目名称:bird-squad,代码行数:101,代码来源:main.cpp

示例15: init

void cursor::init(string cursorFile, string cursorPass)
{
    app.setMouseCursorVisible(false);
    textureManager.add(cursorFile, cursorPass, true);
    sprite.setScale(settings.getCursorScale());
}
开发者ID:KoczurekK,项目名称:Battle-of-Hrubieszow-old,代码行数:6,代码来源:cursor.hpp


注:本文中的sf::Sprite::setScale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。