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


C++ Image::LoadFromFile方法代码示例

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


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

示例1: init

void init(){
  _backgroundImage.LoadFromFile("assets/wood-puzzle-floor.png");
  _backgroundSprite.SetImage(_backgroundImage);
  
  _robotImage.LoadFromFile("assets/roomba.png");
  _robotSprite.SetImage(_robotImage);
  _robotSprite.SetCenter(_robotSprite.GetSize().x/2, _robotSprite.GetSize().y/2);
  _fakeRobotSprite.SetImage(_robotImage);
  _fakeRobotSprite.SetCenter(_fakeRobotSprite.GetSize().x/2, _fakeRobotSprite.GetSize().y/2);
  _fakeRobotSprite.SetColor(sf::Color(100,100,255));

  _landmarkImage.LoadFromFile("assets/landmark.png");
  _landmarkSprite.SetImage(_landmarkImage);
  _landmarkSprite.SetCenter(_landmarkSprite.GetSize().x/2, _landmarkSprite.GetSize().y/2);

  _rangeImage.LoadFromFile("assets/range.png");
  _rangeSprite.SetImage(_rangeImage);
  original_range_sprite_size_x = _rangeSprite.GetSize().x;
  original_range_sprite_size_y = _rangeSprite.GetSize().y;
  updateRangeSpriteScale();
  _rangeSprite.SetCenter((original_range_sprite_size_x/2), (original_range_sprite_size_y/2));

  _window.Create(sf::VideoMode(window_width,window_height,32), "Bearing simulator");

  move_amount = 0;
  rotation_amount = 0;
  time_to_capture = false;
  
  walk = 0;
  rotation = 0;
}
开发者ID:ieatmosquitos,项目名称:bearingsimulator,代码行数:31,代码来源:simulator.cpp

示例2: main

int main()
{
	img_r.LoadFromFile("..\\Imagenes\\rcircle.png");
	img_b.LoadFromFile("..\\Imagenes\\bcircle.png");
	
	sprite_b.SetImage(img_b);
	sprite_r.SetImage(img_r);

	sf::RenderWindow App(sf::VideoMode(800,600,32),"ventana");
	
	const sf::Input& in = App.GetInput();

	sprite_b.Scale(sprite_r.GetSize().x/sprite_b.GetSize().x,sprite_r.GetSize().y/sprite_b.GetSize().y);

	while(App.IsOpened())
	{

		while(App.GetEvent(Event))
		{
			if(Event.Type == sf::Event::Closed)
				App.Close();

			if(Event.Type == sf::Event::MouseMoved){
			//	cursor.SetPosition(Event.MouseMove.X,Event.MouseMove.Y);
			}

		}

		if(in.IsKeyDown(sf::Key::Escape))
			App.Close();

		//cursor.SetPosition(in.GetMouseX(),in.GetMouseY());

		App.Clear();
		sprite_r.SetPosition(0,0);
		App.Draw(sprite_r);

		sprite_r.SetPosition(App.GetWidth()-img_r.GetWidth(),0);
		App.Draw(sprite_r);

		sprite_r.SetPosition(0,App.GetHeight()-img_r.GetHeight());
		App.Draw(sprite_r);

		sprite_r.SetPosition(App.GetWidth()-img_r.GetWidth(),App.GetHeight()-img_r.GetHeight());
		App.Draw(sprite_r);
		
		sprite_b.SetPosition((App.GetWidth()-sprite_b.GetSize().x)/2,(App.GetHeight()-sprite_b.GetSize().y)/2);
		App.Draw(sprite_b);
		App.Display();
	}

	return 0;
}
开发者ID:dexter1986,项目名称:unli,代码行数:53,代码来源:main.cpp

示例3: drawAtributes

void Player::drawAtributes(sf::RenderWindow& rw) const
{
	static bool firstRun = true;
	static sf::Image tlo;
	static sf::Font font;
	if(firstRun)
	{
		tlo.LoadFromFile("Images/tlo.png");
		firstRun = false;
		font.LoadFromFile("silesiana.otf", 50,  L"A�BC�DE�FGHIJKL�MN�O�PRS�TUWYZ��a�bc�de�fghijkl�mn�o�prs�tuwyz��[email protected]#$%^&*()_-[]\\;',./{}:\"<>?=-+ ");
	}
	sf::Sprite tloH(tlo);
	rw.Draw(tloH);
	
	std::wstringstream ss;
	if(selectedAttribute == 0)
	{
		ss << L"Exp: " << xp << L"\n";
		ss << L"> Poziom obrony: " << defLevel << L"\n";
		ss << L"Poziom ataku: " << attLevel << L"\n";
	}
	else
	{
		ss << L"Exp: " << xp << L"\n";
		ss << L"Poziom obrony: " << defLevel << L"\n";
		ss << L"> Poziom ataku: " << attLevel << L"\n";
	}
	sf::String t(ss.str(), font, 30.f);
	t.SetColor(sf::Color(20, 18, 160));
	t.SetPosition(20.f, 20.0);
	rw.Draw(t);
}
开发者ID:khaiduk,项目名称:rogalik,代码行数:32,代码来源:Player.cpp

示例4: AbstractLoadFromFile

void ImageManager::AbstractLoadFromFile(sf::Image &image, std::string name, bool transparency, sf::Color color)
{
    if (!image.LoadFromFile(name))
        std::cerr << "Impossible d'ouvrir le fichier " << name << " !" << std::endl;

    if(transparency)
    {
        image.SetSmooth(false);
        image.CreateMaskFromColor(color);
    }
}
开发者ID:BBazard,项目名称:old-stuff,代码行数:11,代码来源:imageManager.cpp

示例5: drawInventory

void Player::drawInventory(sf::RenderWindow& rw) const
{
	static bool firstRun = true;
	static sf::Image tlo;
	static sf::Font font;
	if(firstRun) 
	{
		tlo.LoadFromFile("Images/inv.png");
		firstRun = false;
		font.LoadFromFile("silesiana.otf", 50,  L"A�BC�DE�FGHIJKL�MN�O�PRS�TUWYZ��a�bc�de�fghijkl�mn�o�prs�tuwyz��[email protected]#$%^&*()_-[]\\;',./{}:\"<>?=-+ ");
	}

	sf::Sprite tloH(tlo);
	rw.Draw(tloH);
	
	std::stringstream ss;
	ss<<"Masz " << coins << " $";
	sf::String t(ss.str(), font, 30.f);
	t.SetColor(sf::Color(20, 18, 160));
	t.SetPosition(600.f, 30.f);
	rw.Draw(t);

	float posy = 30.0;
	int i = 0;
	for(std::vector<Item>::const_iterator it = inventory.begin(); it != inventory.end(); it++)
	{
		std::wstring name = it->getName();
		if(i == weapon)
		{
			name += L" (uzbrojny - bro�)";
		}
		if(i == armor)
		{
			name += L" (uzbrojny - zbroja)";
		}
		sf::String t(name, font, 30.f);
		t.SetColor(sf::Color(20, 18, 160));
		if(selectedItem == i)
			t.SetColor(sf::Color(200, 18, 160));
		t.SetPosition(20.f, posy);
		rw.Draw(t);
		posy += 30.0;
		i++;
	}
	if(0 <= selectedItem && selectedItem < inventory.size())
	{
		TextArea desc(inventory[selectedItem].getDesc(), 400, font);
		desc.SetPosition(300, 50);
		rw.Draw(desc);
		Item::Type type = inventory[selectedItem].getProperty();
		if(type == 0)
		{
			TextArea desc1(L"Bron - Atak + " +inventory[selectedItem].getBoost(), 400,font);
			desc1.SetPosition(350,250);
			rw.Draw(desc1);
		}
		else if(type == 1)
		{
			TextArea desc1(L"Zbroja - Obrona + " +inventory[selectedItem].getBoost(), 400,font);
			desc1.SetPosition(350,250);
			rw.Draw(desc1);
		}
		else if(type == 2)
		{
			TextArea desc1(L"Helm - Obrona + " +inventory[selectedItem].getBoost(), 400,font);
			desc1.SetPosition(350,250);
			rw.Draw(desc1);
		}
		else if(type == 3)
		{
			TextArea desc1(L"Mikstura", 460,font);
			desc1.SetPosition(350,250);
			rw.Draw(desc1);
		}

		
	}
}
开发者ID:khaiduk,项目名称:rogalik,代码行数:78,代码来源:Player.cpp

示例6: main

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    srand((unsigned)time(0));
    bool spaceIsPressed = false;
    bool finishedEnteringName = false;
    bool savedToFile = false;

    sf::Clock clock;
    float currentTime, deathTime = 0.0f;

    sf::String whatever;
    whatever.SetPosition(300, 300);
    sf::String youMadeIt("You made it to the high score list! Enter your name:");
    youMadeIt.SetPosition(300, 275);
    std::string inputString;
    initHighScores(highScoreList);
    sf::String highScoreString(convertScoresToString(highScoreList));

    bool gameOver = false;

    sf::Music backgroundMusic;
    if ( !backgroundMusic.OpenFromFile("Music/02 - Salt In The Wounds.ogg"))
        return -9;
    backgroundMusic.Play();


    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(1280, 720, 32), "Space Invaders!");
    App.UseVerticalSync(true);

    // Load the sprite image from a file
    sf::Image PlayerImage;
    if (!PlayerImage.LoadFromFile("Images/player.psd"))
        return EXIT_FAILURE;

    sf::Sprite Player(PlayerImage);
    Player.SetPosition(200.f, 100.f);
    Player.SetCenter(32.f, 32.f);

    sf::Image BackgroundImage;
    if ( !BackgroundImage.LoadFromFile("Images/space.psd"))
        return -1;
    sf::Sprite Background(BackgroundImage);

    std::vector<sf::Sprite> missiles;
    sf::Image MissileImage;
    if ( !MissileImage.LoadFromFile("Images/Missle.psd"))
        return -1;

    std::vector<Enemy> enemies;
    if ( !EnemyImage.LoadFromFile("Images/Bad Guy!.psd"))
        return -2;
    createWave(enemies);

    std::vector<sf::Sprite> enemyMissiles;
    if ( !EnemyMissileSprite.LoadFromFile("Images/BadGuyMissile.psd") )
        return -3;

    sf::String help("Use WASD to move and change your direction.\nUse the arrow keys to move without changing your direction.\nPress space to fire.");
    help.SetSize(16.0f);
    help.SetColor(sf::Color::Red);
    help.SetPosition(848, 0);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            if (Event.Key.Code == sf::Key::F1)
            {
                sf::Image Screen = App.Capture();
                Screen.SaveToFile("screenshot.png");
            }

            if ( gameOver && score > getLastScore(highScoreList))
            {

                if (Event.Type == sf::Event::TextEntered)
                {
                    char c = Event.Text.Unicode;

                    if (c == 8)//8 is backspace
                    {
                        if (inputString.size() > 0)//check that there is something to delete
                        {
                            inputString.erase(inputString.end() - 1);//delete the last character
                        }
                    }
//.........这里部分代码省略.........
开发者ID:krej,项目名称:Space-Invaders,代码行数:101,代码来源:main.cpp


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