本文整理汇总了C++中sf::Sprite::getTextureRect方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::getTextureRect方法的具体用法?C++ Sprite::getTextureRect怎么用?C++ Sprite::getTextureRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::getTextureRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PixelPerfectTest
bool PixelPerfectTest(const sf::Sprite& Object1, const sf::Sprite& Object2, sf::Uint8 AlphaLimit) {
sf::FloatRect Intersection;
if (Object1.getGlobalBounds().intersects(Object2.getGlobalBounds(), Intersection)) {
sf::IntRect O1SubRect = Object1.getTextureRect();
sf::IntRect O2SubRect = Object2.getTextureRect();
sf::Uint8* mask1 = Bitmasks.GetMask(Object1.getTexture());
sf::Uint8* mask2 = Bitmasks.GetMask(Object2.getTexture());
// Loop through our pixels
for (int i = Intersection.left; i < Intersection.left+Intersection.width; i++) {
for (int j = Intersection.top; j < Intersection.top+Intersection.height; j++) {
sf::Vector2f o1v = Object1.getInverseTransform().transformPoint(i, j);
sf::Vector2f o2v = Object2.getInverseTransform().transformPoint(i, j);
// Make sure pixels fall within the sprite's subrect
if (o1v.x > 0 && o1v.y > 0 && o2v.x > 0 && o2v.y > 0 &&
o1v.x < O1SubRect.width && o1v.y < O1SubRect.height &&
o2v.x < O2SubRect.width && o2v.y < O2SubRect.height) {
if (Bitmasks.GetPixel(mask1, Object1.getTexture(), (int)(o1v.x)+O1SubRect.left, (int)(o1v.y)+O1SubRect.top) > AlphaLimit &&
Bitmasks.GetPixel(mask2, Object2.getTexture(), (int)(o2v.x)+O2SubRect.left, (int)(o2v.y)+O2SubRect.top) > AlphaLimit)
return true;
}
}
}
}
return false;
}
示例2: afficheConstructible
void afficheConstructible (sf::RenderWindow &App, sf::Sprite &SpriteTower ,sf::Shape &PolygonPorte,Constructible* maCons,int cote, int offSetX, int offSetY )
{
// affichage du sprite de la construction
int i = maCons->getPosition()->getI();
int j = maCons->getPosition()->getJ();
drawHexagoneIJ ( i,j, SpriteTower, cote, offSetX, offSetY);
//SpriteTower.SetCenter(SpriteTower.GetSize().x/2,SpriteTower.GetSize().y/2);
sf::Vector2f positionAvant = SpriteTower.getPosition();
SpriteTower.setPosition(positionAvant.x-SpriteTower.getTextureRect().height,positionAvant.y-SpriteTower.getTextureRect().width);
App.draw(SpriteTower);
// affichage de la porté
std::set<Case *> cibles = maCons->getCaseAPorteDEffet();
std::set<Case *>::iterator its;
for ( its= cibles.begin() ; its != cibles.end() ; ++its )
{
drawHexagoneIJ ( (*its)->getI() , (*its)->getJ(), PolygonPorte, cote, offSetX, offSetY);
App.draw(PolygonPorte);
}
// les point de vue ( mon dieu c'est moche le code graphique )
double centreX = SpriteTower.getTextureRect().width /2 ;// SpriteTower.getTexture().getSize().x/2;
double centreY = SpriteTower.getTextureRect().height/2 ;
/*sf::Shape pv = sf::Shape::Line (0,0, 0+maCons->getPV()/2 ,0,5,sf::Color::Black);
drawHexagoneIJ ( i,j, pv, cote, offSetX, offSetY);
pv.Move(0-centreX,0-centreY);
App.draw(pv);*/
}
示例3: SetSprite
void Animation::SetSprite(const sf::Sprite& sprite, const int frameCount)
{
m_frameWidth = sprite.getTextureRect().width/frameCount;
m_frameHeight = sprite.getTextureRect().height;
m_sprite = sprite;
m_frameCount = frameCount;
Reset();
}
示例4:
KeyObject::KeyObject(float x, float y, sf::Sprite sprite, sf::Color outline, sf::String word, key_callback_t callback, bool active, bool visible) :
GameObject(x, y, (float)sprite.getTexture()->getSize().x, (float)sprite.getTexture()->getSize().y),
outline_(outline),
word_(word),
active_(active),
focused_(false),
visible_(visible),
callback_(callback),
state_(DEFAULT)
{
this->rect_.width = sprite.getTextureRect().width;
this->rect_.height = sprite.getTextureRect().height;
SetSprite(sprite);
}
示例5: getCenter
sf::Vector2f getCenter(const sf::Sprite& sprite)
{
sf::Vector2f center = sprite.getPosition();
center.x += sprite.getTextureRect().width / 2.f;
center.y += sprite.getTextureRect().height / 2.f;
return center;
}
示例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;
}
}
示例7: testForStanding
bool testForStanding(sf::Sprite sp2) {
if ((sp2.getGlobalBounds().left+sp2.getGlobalBounds().width > sprite.getPosition().x) &&
(sp2.getGlobalBounds().left < sprite.getPosition().x+sprite.getTextureRect().width*sprite.getScale().x)) {
return true;
}
return false;
}
示例8:
sf::Vector2f Collision2D::GetSize(const sf::Sprite& sprite)
{
// Return the size of the sprite adjusting for scale
const sf::IntRect iOriginalSize = sprite.getTextureRect();
const sf::Vector2f fScale = sprite.getScale();
return sf::Vector2f(iOriginalSize.width * fScale.x, iOriginalSize.height * fScale.y);
}
示例9: ImageButton
bool ImageButton(const sf::Sprite& sprite, const sf::Vector2f& size,
const int framePadding, const sf::Color& bgColor, const sf::Color& tintColor)
{
const sf::Texture* texturePtr = sprite.getTexture();
if (!texturePtr) { return false; }
return ::imageButtonImpl(*texturePtr, static_cast<sf::FloatRect>(sprite.getTextureRect()), size, framePadding, bgColor, tintColor);
}
示例10: resize
void resize(sf::Sprite& sprite, float width, float height)
{
int local_width = sprite.getTextureRect().width;
int local_height = sprite.getTextureRect().height;
if ((local_width > 0) && (local_height > 0))
sprite.setScale(width / local_width, height / local_height);
}
示例11: draw
void Graphics::draw(sf::Vector2f position, sf::Vector2f hitbox, sf::Sprite sprite)
{
sprite.setOrigin(0, hitbox.y);
sf::Vector2f roundedPosition = sf::Vector2f(position.x - 0.5, position.y - 0.5);
//Translate position
translatePosition(roundedPosition, window_);
//Set Position
sprite.setPosition(roundedPosition);
//Scale if necessary
sprite.scale(hitbox.x / sprite.getTextureRect().width, hitbox.y / sprite.getTextureRect().height);
window_->draw(sprite);
return;
}
示例12: Animator
SpriteAnimator::SpriteAnimator(sf::Sprite &sprite)
: Animator()
, invertXOffset(false)
, invertYOffset(false)
, sprite(sprite)
, sourceRectangle(sprite.getTextureRect()) {
}
示例13: OrientedBoundingBox
OrientedBoundingBox (const sf::Sprite& Object) // Calculate the four points of the OBB from a transformed (scaled, rotated...) sprite
{
sf::Transform trans = Object.getTransform();
sf::IntRect local = Object.getTextureRect();
Points[0] = trans.transformPoint(0.f, 0.f);
Points[1] = trans.transformPoint(local.width, 0.f);
Points[2] = trans.transformPoint(local.width, local.height);
Points[3] = trans.transformPoint(0.f, local.height);
}
示例14: Image
void Image(const sf::Sprite& sprite, const sf::Vector2f& size,
const sf::Color& tintColor, const sf::Color& borderColor)
{
const sf::Texture* texturePtr = sprite.getTexture();
// sprite without texture cannot be drawn
if (!texturePtr) { return; }
Image(*texturePtr, size, static_cast<sf::FloatRect>(sprite.getTextureRect()), tintColor, borderColor);
}
示例15: Flip
// The flip function works well TODO MOVE THIS SHIT
void Player::Flip(sf::Sprite& sprite)
{
if (Player::Direction==-1)
{
sprite.setTextureRect(
sf::IntRect(
sprite.getTextureRect().width, //TODO left+width?
0,
-sprite.getTextureRect().width,
sprite.getTextureRect().height
)
);
}
else
{
sprite.setTextureRect(Player::TextureRect);
}
}