本文整理汇总了C++中sf::Image::GetWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::GetWidth方法的具体用法?C++ Image::GetWidth怎么用?C++ Image::GetWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Image
的用法示例。
在下文中一共展示了Image::GetWidth方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2:
Bala::Bala(float _v, sf::Sprite& _cannon, sf::Image& imagen)
{
float cannonA, cannonX, cannonY, cannonH;
//Cargo sprite
sprite.SetImage(imagen);
sprite.SetCenter(imagen.GetWidth()/2, imagen.GetHeight()/2);
//Inicializo variables
dt = 0.0f;
cannonA = _cannon.GetRotation();
cannonX = _cannon.GetPosition().x;
cannonY = _cannon.GetPosition().y;
//Tomo el tamaño sobre el eje x como el largo del cañon
//porque sin rotar la misma se encuentra en horizontal
cannonH = _cannon.GetSize().x;
//Descompongo la velocidad inicial
vx = _v * (cos(cannonA/180*PI));
vy = _v * (sin(cannonA/180*PI));
//Posicion inicial bala según la posición del cañon
//usando trigonometria
xi = cannonX + ((cos(cannonA/180*PI) * cannonH));
yi = cannonY - ((sin(cannonA/180*PI) * cannonH));
sprite.SetPosition(xi, yi);
}
示例3:
// Constructor
ParallaxLayer::ParallaxLayer(const sf::Image &img, float factor_x, bool repeat_x, float offset_x, float factor_y, bool repeat_y, float offset_y){
SetImage(img);
// calculamos el ancho y alto de la imagen, esto
// nos va a servir para evitar desbordes en el desplazamiento
ancho_img=img.GetWidth();
alto_img=img.GetHeight();
// inicializamos las variables internas
despl_x=despl_y=0;
this->factor_x=factor_x;
this->factor_y=factor_y;
this->repeat_x=repeat_x;
this->repeat_y=repeat_y;
this->offset_x=offset_x;
this->offset_y=offset_y;
// seleccionamos la textura y habilitamos la repeticion
// segun corresponda
img.Bind();
if(repeat_x)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
if(repeat_y)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// ajustamos la posicion de la capa
Sprite::SetPosition(offset_x, offset_y);
SetScale(0.5,0.5);
}
示例4:
Obstacle::Obstacle(float x, float y, const sf::Image& image)
{
mSprite.SetImage(image);
mSprite.SetPosition(x, y);
mRect = sf::FloatRect(x, y, x+image.GetWidth(), y+image.GetHeight());
mHitPlayer = false;
}
示例5: draw
void ColorScale::draw(sf::Image& img,const sf::Vector2f& start,const sf::Vector2f& end,GradientStyle::GradientStyle style, int size) const
{
sf::Color (*pFunction)(sf::Color*,int,const sf::Vector2f&,const sf::Vector2f&,int,int);
sf::Color* tab =new sf::Color[size];
fillTab(tab,size);
switch (style)
{
case GradientStyle::Linear : pFunction = GradientLinear; break;
case GradientStyle::Circle : pFunction = GradientCircle; break;
case GradientStyle::Radial : pFunction = GradientRadial; break;
case GradientStyle::Reflex : pFunction = GradientReflex; break;
default: pFunction = GradientLinear; break;
}
for(int i=0;i<img.GetWidth();i++)
{
for(int j=0;j<img.GetHeight();j++)
{
img.SetPixel(i,j,pFunction(tab,size,start,end,i,j));
}
}
delete[] tab;
}
示例6: SetSize
void SFMLTexture_c::SetSize(uint16_t w, uint16_t h)
{
if (texture.GetWidth() != w && texture.GetHeight() != h)
{
texture.Create(w, h);
}
}
示例7: 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);
}
示例8: makeBlendMap
//uploads the blendmaps to the GFX, getting a handle to the GFX side tex
void Terrain::makeBlendMap(GLuint& handle, sf::Image img)
{
glDeleteTextures(1,&handle);
glGenTextures(1,&handle);
glBindTexture(GL_TEXTURE_2D,handle);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,img.GetWidth(),img.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,img.GetPixelsPtr());
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
示例9: 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);
}
}
}
示例10:
Player::Player(sf::Image& image, sf::Image& impulse)
{
mLife = 1.0f;
mEnergyBar = 1.0f;
mYDir = 0.0f;
mXAdvancement = 0;
mDestroyed=false;
mSprite.SetImage(image);
mSprite.SetPosition(350, 400);
mSprite.SetCenter(image.GetWidth()/2, image.GetHeight()/2);
mImpulse.SetImage(impulse);
mImpulse.SetBlendMode(sf::Blend::Add);
}
示例11: uploadTextureGFX
GLuint Terrain::uploadTextureGFX(sf::Image img)
{
GLuint handle;
glGenTextures(1,&handle);
glBindTexture(GL_TEXTURE_2D,handle);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,img.GetWidth(),img.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,img.GetPixelsPtr());
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST );
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glGenerateMipmap( GL_TEXTURE_2D);
return handle;
}
示例12: 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));
}
}
}
}
示例13: replacePartTexture
void Terrain::replacePartTexture(GLint xoffset, GLint yoffset, sf::Image img,GLuint handle)
{
glBindTexture(GL_TEXTURE_2D,handle);
glTexSubImage2D(GL_TEXTURE_2D,0,xoffset,yoffset,img.GetWidth(),img.GetHeight(),GL_RGBA,GL_UNSIGNED_BYTE,img.GetPixelsPtr());
}
示例14: setTileQueueBtns
void setTileQueueBtns( cp::cpImageButton *b1,
cp::cpImageButton *b2,
cp::cpImageButton *b3,
cp::cpImageButton *b4,
cp::cpImageButton *b5, sf::Image placeHolder)
{
if( tileQueue.size() > 0 )
{
int btnIndex = 0;
//create a temp tile to make code look cleaner.
Tile *tmptile = &tileQueue.at(tileQueueIndex + btnIndex);
b1->SetImage(
&chipsetImages.at(
getChipsetIndex(tmptile->chipSetName)));
//set the buttons sprite subrec.
sf::IntRect subrec(tmptile->srcX,
tmptile->srcY,
tmptile->srcX + tmptile->width,
tmptile->srcY + tmptile->height);
b1->SetSubRect(subrec);
b1->SetSize(placeHolder.GetWidth(),
placeHolder.GetHeight());
b1->SetBackgroundColor(sf::Color::Black);
float x = (placeHolder.GetWidth() / 2) - (tmptile->width / 2);
float y = (placeHolder.GetHeight() / 2) - (tmptile->height / 2);
b1->SetSpritePos( x, y);
}
if( tileQueue.size() > 1 )
{
int btnIndex = 1;
//create a temp tile to make code look cleaner.
Tile *tmptile = &tileQueue.at(tileQueueIndex + btnIndex);
b2->SetImage(
&chipsetImages.at(
getChipsetIndex(tmptile->chipSetName)));
//set the buttons sprite subrec.
sf::IntRect subrec(tmptile->srcX,
tmptile->srcY,
tmptile->srcX + tmptile->width,
tmptile->srcY + tmptile->height);
b2->SetSubRect(subrec);
b2->SetSize(placeHolder.GetWidth(),
placeHolder.GetHeight());
b2->SetBackgroundColor(sf::Color::Black);
float x = (placeHolder.GetWidth() / 2) - (tmptile->width / 2);
float y = (placeHolder.GetHeight() / 2) - (tmptile->height / 2);
b2->SetSpritePos( x, y);
}
if( tileQueue.size() > 2 )
{
int btnIndex = 2;
//create a temp tile to make code look cleaner.
Tile *tmptile = &tileQueue.at(tileQueueIndex + btnIndex);
b3->SetImage(
&chipsetImages.at(
getChipsetIndex(tmptile->chipSetName)));
//set the buttons sprite subrec.
sf::IntRect subrec(tmptile->srcX,
tmptile->srcY,
tmptile->srcX + tmptile->width,
tmptile->srcY + tmptile->height);
b3->SetSubRect(subrec);
b3->SetSize(placeHolder.GetWidth(),
placeHolder.GetHeight());
b3->SetBackgroundColor(sf::Color::Black);
float x = (placeHolder.GetWidth() / 2) - (tmptile->width / 2);
float y = (placeHolder.GetHeight() / 2) - (tmptile->height / 2);
b3->SetSpritePos( x, y);
}
if( tileQueue.size() > 3 )
{
int btnIndex = 3;
//create a temp tile to make code look cleaner.
Tile *tmptile = &tileQueue.at(tileQueueIndex + btnIndex);
b4->SetImage(
&chipsetImages.at(
getChipsetIndex(tmptile->chipSetName)));
//set the buttons sprite subrec.
sf::IntRect subrec(tmptile->srcX,
tmptile->srcY,
tmptile->srcX + tmptile->width,
tmptile->srcY + tmptile->height);
b4->SetSubRect(subrec);
b4->SetSize(placeHolder.GetWidth(),
placeHolder.GetHeight());
b4->SetBackgroundColor(sf::Color::Black);
float x = (placeHolder.GetWidth() / 2) - (tmptile->width / 2);
float y = (placeHolder.GetHeight() / 2) - (tmptile->height / 2);
b4->SetSpritePos( x, y);
}
if( tileQueue.size() > 4 )
{
int btnIndex = 4;
//create a temp tile to make code look cleaner.
//.........这里部分代码省略.........