本文整理汇总了C++中sf::Image::GetPixel方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::GetPixel方法的具体用法?C++ Image::GetPixel怎么用?C++ Image::GetPixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Image
的用法示例。
在下文中一共展示了Image::GetPixel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: swapImg
void Terrain::swapImg(sf::Image &img)
{
for(unsigned int i=0;i<img.GetWidth();i++)
{
for(unsigned int j=0;j<img.GetHeight()/2;j++)
{
sf::Color tmp = img.GetPixel(i,img.GetHeight()-1-j);
img.SetPixel(i,img.GetHeight()-1-j,img.GetPixel(i,j));
img.SetPixel(i,j,tmp);
}
}
}
示例2: getAverageTexColor
sf::Color Terrain::getAverageTexColor(sf::Image &img)
{
unsigned long r=0;
unsigned long g=0;
unsigned long b=0;
for(unsigned int i=0;i<img.GetHeight();i++)
{
for(unsigned int j=0;j<img.GetWidth();j++)
{
r+=long(img.GetPixel(j,i).r);
g+=long(img.GetPixel(j,i).g);
b+=long(img.GetPixel(j,i).b);
}
}
r=r/(img.GetHeight()*img.GetWidth());
g=g/(img.GetHeight()*img.GetWidth());
b=b/(img.GetHeight()*img.GetWidth());
return sf::Color(r,g,b,0);
}
示例3: while
Level::Level(const sf::Image &lvl, const sf::Texture &tileTex) {
int imgWd = lvl.GetWidth();
int imgHt = lvl.GetHeight();
bool isWall[imgWd][imgHt];
for (int y=0; y<imgHt; ++y)
for (int x=0; x<imgWd; ++x)
isWall[x][y] = false;
for (int y=0; y<imgHt; ++y) {
for (int x=0; x<imgWd; ++x) {
// search for new platfomrs
if (!isWall[x][y] && lvl.GetPixel(x, y) == sf::Color::Black) {
// figure out the collision rectangles
int minHt = imgHt+1;
int wd;
// find the maximum rectangle width
for (wd=0; x+wd<imgWd && lvl.GetPixel(x+wd, y) == sf::Color::Black; ++wd){
// find the minimum rectangle height
int ht=0;
while (y+ht<imgHt && lvl.GetPixel(x+wd, y+ht) == sf::Color::Black) ++ht;
if (ht < minHt) minHt = ht;
}
// mark the platfom area as processed
for (int x2=x; x2<x+wd; ++x2) {
for (int ht=0; ht<minHt; ++ht) {
isWall[x2][y+ht] = true;
}
}
// construct platforms
platforms.push_back(Platform(x*TILE_SIZE, y*TILE_SIZE, wd*TILE_SIZE, minHt*TILE_SIZE, tileTex));
}
}
}
}