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


C++ Texture::loadFromFile方法代码示例

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


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

示例1: if

	vector<vector<Tile*>> LoadLevel(const char* filename)
	{
		sf::Color pixCol;
		vector<vector<Tile*>> tils;

		sf::Image image;
		if (!image.loadFromFile(filename)) return tils;

		if (!backGroundTex.loadFromFile("DarkBrick.png")) return tils;
		if (!foreGroundTex.loadFromFile("Brick.png")) return tils;

		tils.resize(image.getSize().x);
		for (int i = 0; i < image.getSize().x; i++)
		{
			tils[i].resize(image.getSize().y);
			for (int j = 0; j < image.getSize().y; j++)
			{
				pixCol = image.getPixel(i, j);

				if (pixCol == sf::Color::White)
					tils[i][j] = new Tile(sf::Vector2f(i * 64, j * 64), backGroundTex, false);
				else if (pixCol == sf::Color::Black)
					tils[i][j] = new Tile(sf::Vector2f(i * 64, j * 64), foreGroundTex, true);
			}
		}

		return tils;
	}
开发者ID:xxAtrain223,项目名称:LD30,代码行数:28,代码来源:MainGame.hpp

示例2: Initialize

void StateGameMenu::Initialize()
{
	menu_pointer_tex.loadFromFile("./Resources/Images/gamemenu_pointer.png");
	menu_pointer_sprt.setTexture(menu_pointer_tex);

	menu_tex.loadFromFile("./Resources/Images/gamemenu.png");
	menu_sprt.setTexture(menu_tex);
	menu_sprt.setPosition(180, 142);
}
开发者ID:vsrz,项目名称:VHH,代码行数:9,代码来源:stategamemenu.cpp

示例3: actualizarImagenExplocionPequenia

			bool actualizarImagenExplocionPequenia(float currentTime){
			float temporal= currentTime - tiempoInicio;
			if(temporal <100){
			imagen.loadFromFile("graphics/SmallExp00.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >100 && temporal < 200){
			imagen.loadFromFile("graphics/SmallExp00.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >200 && temporal < 300){
			imagen.loadFromFile("graphics/SmallExp01.png");
			sprite.setTexture(imagen, true);
			return true;
			}	
			if(temporal >300 && temporal < 400){
			imagen.loadFromFile("graphics/SmallExp01.png");
			sprite.setTexture(imagen, true);
			}
			if(temporal >400 && temporal < 500){
			imagen.loadFromFile("graphics/SmallExp02.png");
			sprite.setTexture(imagen, true);
			}
			if(temporal >500 && temporal < 600){
			imagen.loadFromFile("graphics/SmallExp02.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >600 && temporal < 700){
			imagen.loadFromFile("graphics/SmallExp03.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >700 && temporal < 800){
			imagen.loadFromFile("graphics/SmallExp03.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >800 && temporal < 1200){
			imagen.loadFromFile("graphics/SmallExp04.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >1200 && temporal < 1700){
			imagen.loadFromFile("graphics/SmallExp04.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			else
			{
				return false;
			}
			
		};
开发者ID:luchoman08,项目名称:space_game,代码行数:56,代码来源:ObjetoExplocion.hpp

示例4: load

int Presentation::load() {



    if (!textureFolder.loadFromFile("folder.png")) {
        std::cerr << "Error loading folder.png" << std::endl;
        return (-1);
    }

    if (!textureClose.loadFromFile("close.png")) {
        std::cerr << "Error loading close.png" << std::endl;
        return (-1);
    }
    return 0;
}
开发者ID:3991,项目名称:Game-25486,代码行数:15,代码来源:Presentation.hpp

示例5: loadFromLv

void Level::loadFromLv(b2World& World, std::string levelPath)
{
  std::cout << levelPath << std::endl;
  std::string line;
  std::ifstream myfile (levelPath);
  if (myfile.is_open())
  {
    //current level object init
    while ( getline (myfile,line) )
    {
      std::regex groundRegex("(ground),(.*),(.*),(.*),(.*),(.*)");
      std::smatch groundObject;

      if (std::regex_match(line,groundObject,groundRegex))
      {
        std::cout <<  groundObject[5].str() << std::endl;

        CreateGround(World, std::stof(groundObject[2].str()), stof(groundObject[3].str()), stof(groundObject[4].str()), stof(groundObject[5].str()));
        // CreateGround(World, 5, 5, 5, stof(groundObject[5].str()));
        GroundTexture.loadFromFile(groundObject[6]);

        GroundTexture.setRepeated(true);

      }


    }
    std::cout << levelPath << std::endl;

    myfile.close();
  }
  else std::cout << "Unable to open file" << std::endl;
}
开发者ID:rossgb,项目名称:Zekespuzzle,代码行数:33,代码来源:level.cpp

示例6: load_image

	void _Log::load_image(){
		if( image_loaded == false && image_path.length() != 0 ) {
			texture_1.loadFromFile( image_path );

			Sprite.setTexture( texture_1, false );
			sf::IntRect spr_data = Sprite.getTextureRect();
			float x,y = WINDOW_HEIGHT - spr_data.height;

			switch( align ){

			case 1: x = 0.f; break;
			case 2: x = WINDOW_WIDTH * 0.25 - spr_data.width /2; break;
			case 3: x = WINDOW_WIDTH * 0.5  - spr_data.width /2; break;
			case 4: x = WINDOW_WIDTH * 0.75  - spr_data.width /2; break;
			case 5: x = WINDOW_WIDTH - spr_data.width; break;

			}

			Sprite.setPosition( x, y );

			cout << x << " " << y << endl;

			image_loaded = true;
		}
	}
开发者ID:rmxhaha,项目名称:phantasia,代码行数:25,代码来源:VN_1.0.cpp

示例7: main

int main() {
  int WindowX, WindowY;

  std::string str("Cards/cardback1.png");

  std::cout << str << std::endl;

  if (!back.loadFromFile(str)) { // TODO error
    std::cout << "Couldn't load cardback img" << std::endl;
  }
  WindowX = 700;
  WindowY = 500;
  //Card c(Card::Seven, Card::Spade, true);
  //c.rotate(90.0f);
  Deck deck(true);
  Hand h(true, false, sf::FloatRect(100.0f, 100.0f, static_cast<float>(WindowX / 5), static_cast<float>(WindowY)), Hand::down, deck.getKozer());
  //h.takeCard(c);
  
  // Create the main window
  sf::VideoMode v = sf::VideoMode::getDesktopMode();

  sf::RenderWindow window(sf::VideoMode(v.width, v.height), "SFML window");
  WindowX = v.width;
  WindowY = v.height;
  //c.scale(WindowX, WindowY);
  //c.rotate(90.0f);
  //c.setPos(50.0f, 50.0f);
  deck.scale(WindowX, WindowY);
  deck.setPos(WindowX / 1.5, WindowY / 1.5);
  while (window.isOpen()) {
    // Process events
    sf::Event event;
    while (window.pollEvent(event)) {
      // Close window : exit
      if (event.type == sf::Event::Closed)
        window.close();
      if(event.type == sf::Event::KeyPressed){
	 
	  switch(event.key.code){
	  case sf::Keyboard::Space:
	      if(!deck.empty()){
		  Card temp = deck.takeTop();
		  h.takeCard(temp);
	      }
	      break;
	      
	  default:
	      break;
	  }
      }
    }
    // Clear screen
    window.clear(sf::Color(85, 120, 47, 160));
    window.draw(h);
    window.draw(deck);
    window.display();
  }
  return EXIT_SUCCESS;
}
开发者ID:kennysandbum,项目名称:Durak,代码行数:59,代码来源:Durak.cpp

示例8: Initialize

void StateCharacterSelect::Initialize()
{
	background_tex.loadFromFile("./Resources/Images/character_select_bg.png");
	background.setTexture(background_tex);

	background_activated_tex.loadFromFile("./Resources/Images/character_select_bg_selected.png");
	for(int i=0; i<4; i++)
		activated[i].setTexture(background_activated_tex);
	
	activated[0].setTextureRect(sf::IntRect(0, 0, 160, 480));
	activated[0].setPosition(0, 0);
	activated[1].setTextureRect(sf::IntRect(160, 0, 160, 480));
	activated[1].setPosition(160, 0);
	activated[2].setTextureRect(sf::IntRect(320, 0, 160, 480));
	activated[2].setPosition(320, 0);
	activated[3].setTextureRect(sf::IntRect(480, 0, 160, 480));
	activated[3].setPosition(480, 0);
}
开发者ID:vsrz,项目名称:VHH,代码行数:18,代码来源:statecharacterselect.cpp

示例9: 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

示例10: loadTexture

void TexturesManager::loadTexture(
    sf::Texture& texture,
    const std::string& path
) &
{
    if (!texture.loadFromFile("res/images/" + path + ".png"))
    {
        throw std::invalid_argument("Cannot load texture : " + path);
    }
}
开发者ID:jean553,项目名称:Memoris,代码行数:10,代码来源:TexturesManager.cpp

示例11:

	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

示例12:

ComponentFactory::ComponentFactory()
{
  t.loadFromFile( "../assets/art/unit1.png" );

  m_functionMap[ EComponentTypes::CT_RenderComponent ] = &MakeRenderComponent;
  m_functionMap[ EComponentTypes::CT_PathfindingAgentComponent ] = &MakePathfindingAgentComponent;
  m_functionMap[ EComponentTypes::CT_WanderingComponent ] = &MakeWanderingComponent;


}
开发者ID:Sumethh,项目名称:AIPlayGround,代码行数:10,代码来源:ComponentFactory.cpp

示例13: load

void Unit::load(std::string filename) {
	if(!_texture.loadFromFile(filename)) {
		_filename = "";
		_isLoaded = false;
	} 
	else {
		_filename = filename;
		_sprite.setTexture(_texture);
		_isLoaded = true;
	}
}
开发者ID:ttang1,项目名称:BitGame,代码行数:11,代码来源:Unit.hpp

示例14: load

int WindowCreateThing::load() {
    if(!font.loadFromFile("arial.ttf")){
        std::cerr << "Error loading arial.png" << std::endl;
        return (-1);
    }

    if(!textureFolder.loadFromFile("folder.png")) {
        std::cerr << "Error loading folder.png" << std::endl;
        return (-1);
    }
    return 0;
}
开发者ID:3991,项目名称:Game-25486,代码行数:12,代码来源:WindowCreateThing.hpp

示例15: init

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

		
		tit.setFont(standard_font); 


		tit.setString("Made by");

		explain.setFont(standard_font);
		explain.setString("Just a bored slacker");
		explain.setCharacterSize(36);
		explain.setPosition(260,320);

		tit.setCharacterSize(24);

		
		// dla centrowania obiektow
		
		sf::FloatRect tempt = tit.getGlobalBounds();

		
		tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));

		
		tit.setPosition(400,120);


if (!tex.loadFromFile("gfx/jabslogo.png"))
	
	{
		std::cout<<"Fuckup"<<std::endl;
		}

		spr.setTexture(tex);
		spr.setPosition(334,144);

		
		timer.restart();
		
		};
开发者ID:TarasJan,项目名称:Sleepwalker,代码行数:52,代码来源:jabs.cpp


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