本文整理汇总了C++中sf::Texture::loadFromImage方法的典型用法代码示例。如果您正苦于以下问题:C++ Texture::loadFromImage方法的具体用法?C++ Texture::loadFromImage怎么用?C++ Texture::loadFromImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Texture
的用法示例。
在下文中一共展示了Texture::loadFromImage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
sgb::Chip8 chip8;
chip8.loadGame("PONG2");
back.create(64, 32, sf::Color::Black);
backshape.setPosition(0, 0);
backtext.loadFromImage(back);
backshape.setTexture(&backtext);
while(window.isOpen()){
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
// emulate one cycle
chip8.emulateCycle();
// if drawflag is set, update screen;
if (chip8.drawFlag)
updateGraphics(chip8);
//query keys
chip8.setKeys();
sf::sleep(sf::seconds(1.0f/500.0f));
}
return 0;
}
示例2: init
//initialize muparser and graphics
void init() {
p.DefineVar("theta", &t);
p.DefineConst("pi", pi);
graph.create(size,size,sf::Color::Transparent);
graphTx.loadFromImage(graph);
graphSpr.setTexture(graphTx);
//center on screen
graphSpr.setOrigin(size/2,size/2);
graphSpr.setPosition(windowsize.x/2, windowsize.y/2);
}
示例3: CreateTextureAndBitmask
bool CreateTextureAndBitmask(sf::Texture &LoadInto, const std::string& Filename)
{
sf::Image img;
if (!img.loadFromFile(Filename))
return false;
if (!LoadInto.loadFromImage(img))
return false;
Bitmasks.CreateMask(&LoadInto, img);
return true;
}
示例4: loadSprite
sf::Sprite GraphicEngine::loadSprite(sf::Texture &texture, sf::Sprite &sprite, std::string filename, sf::Vector2i position)
{
string name = "data/images/" + filename + "";
sf::Image img;
img.loadFromFile(name);
img.createMaskFromColor(sf::Color::White);
texture.loadFromImage(img);
sprite.setTexture(texture);
sprite.setPosition(position.x, position.y);
return sprite;
}
示例5: LoadFromFile
bool Level::LoadFromFile(std::string filename)
{
TiXmlDocument levelFile(filename.c_str());
// Загружаем XML-карту
if(!levelFile.LoadFile())
{
std::cout << "Loading level \"" << filename << "\" failed." << std::endl;
return false;
}
// Работаем с контейнером map
TiXmlElement *map;
map = levelFile.FirstChildElement("map");
// Пример карты: <map version="1.0" orientation="orthogonal"
// width="10" height="10" tilewidth="34" tileheight="34">
width = atoi(map->Attribute("width"));
height = atoi(map->Attribute("height"));
tileWidth = atoi(map->Attribute("tilewidth"));
tileHeight = atoi(map->Attribute("tileheight"));
// Берем описание тайлсета и идентификатор первого тайла
TiXmlElement *tilesetElement;
tilesetElement = map->FirstChildElement("tileset");
firstTileID = atoi(tilesetElement->Attribute("firstgid"));
// source - путь до картинки в контейнере image
TiXmlElement *image;
image = tilesetElement->FirstChildElement("image");
std::string imagepath = image->Attribute("source");
// Пытаемся загрузить тайлсет
sf::Image img;
if(!img.loadFromFile(imagepath))
{
std::cout << "Failed to load tile sheet." << std::endl;
return false;
}
img.createMaskFromColor(sf::Color(255, 255, 255));
tilesetImage.loadFromImage(img);
tilesetImage.setSmooth(false);
// Получаем количество столбцов и строк тайлсета
int columns = tilesetImage.getSize().x / tileWidth;
int rows = tilesetImage.getSize().y / tileHeight;
// Вектор из прямоугольников изображений (TextureRect)
std::vector<sf::Rect<int>> subRects;
for(int y = 0; y < rows; y++)
for(int x = 0; x < columns; x++)
{
sf::Rect<int> rect;
rect.top = y * tileHeight;
rect.height = tileHeight;
rect.left = x * tileWidth;
rect.width = tileWidth;
subRects.push_back(rect);
}
// Работа со слоями
TiXmlElement *layerElement;
layerElement = map->FirstChildElement("layer");
while(layerElement)
{
Layer layer;
// Если присутствует opacity, то задаем прозрачность слоя, иначе он полностью непрозрачен
if (layerElement->Attribute("opacity") != NULL)
{
float opacity = strtod(layerElement->Attribute("opacity"), NULL);
layer.opacity = 255 * opacity;
}
else
{
layer.opacity = 255;
}
// Контейнер <data>
TiXmlElement *layerDataElement;
layerDataElement = layerElement->FirstChildElement("data");
if(layerDataElement == NULL)
{
std::cout << "Bad map. No layer information found." << std::endl;
}
// Контейнер <tile> - описание тайлов каждого слоя
TiXmlElement *tileElement;
tileElement = layerDataElement->FirstChildElement("tile");
if(tileElement == NULL)
{
std::cout << "Bad map. No tile information found." << std::endl;
//.........这里部分代码省略.........
示例6: drawFrame
void FractalVis::drawFrame(sf::Texture& screen) {
frame.create(256, 256, &(*colors1DUint8)); //set the Image frame to the known display array
frame.setPixel(128, 128, sf::Color::Yellow); //put a dot in the center
screen.loadFromImage(frame); //display the image
};