Beispiel #1
0
 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;
 }
Beispiel #2
0
	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);
	}
Beispiel #3
0
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);
}
 inline bool operator < (const SpriteDrawClass &t) const
 {
     if(type < t.type) return true;
     else if(type > t.type) return false;
     else if(number < t.number) return true;
     else if(number > t.number) return false;
     return sprite->getTexture() < t.sprite->getTexture();
 }
Beispiel #5
0
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);
}
const std::string	TextureManager::getSpriteName(sf::Sprite sprite)
{
	for(TextureMap::iterator it=getManager().mTextureMap.begin();it!=getManager().mTextureMap.end();it++)
	{
		sf::Texture* temp=&it->second;
		if(temp==sprite.getTexture())
		{
			return	it->first;
		}
	}
	return	"ERROR!";
}
void Animation::create(const sf::Sprite& spritesheet, const sf::IntRect spriteArea, sf::Time duration)
{
    // We get the first's frame rect
    _frameRect = spriteArea;
    // The number of sprites there is on this area
    _numberFrames = spritesheet.getTextureRect().width / spriteArea.width;

    // Setting the texture to own it
    _sprite.setTexture(*spritesheet.getTexture());
    _sprite.setTextureRect(spriteArea);

    // the duration of the animation
    _duration = duration;

    // we can say the animation is ready
    _isLoaded = true;
}
Beispiel #8
0
 static std::vector<sf::Sprite> split4(sf::Sprite sprite)
 {
     std::vector<sf::Sprite> splits = std::vector<sf::Sprite>(0);
     const sf::Texture* texture = sprite.getTexture();
     sf::IntRect baseRect = sprite.getTextureRect();
     sf::Vector2f position = sprite.getPosition();
     splits.push_back(sf::Sprite(*texture, sf::IntRect(baseRect.left,baseRect.top,baseRect.width/2,baseRect.height/2)));
     splits[0].setPosition(position.x,position.y);
     splits[0].setColor(sprite.getColor());
     splits.push_back(sf::Sprite(*texture, sf::IntRect(baseRect.left+(baseRect.width/2), baseRect.top, baseRect.width/2, baseRect.height/2)));
     splits[1].setPosition(position.x+baseRect.width/2,position.y);
     splits[1].setColor(sprite.getColor());
     splits.push_back(sf::Sprite(*texture, sf::IntRect(baseRect.left, baseRect.top+(baseRect.height/2), baseRect.width/2 , baseRect.height/2)));
     splits[2].setPosition(position.x,position.y+baseRect.height/2);
     splits[2].setColor(sprite.getColor());
     splits.push_back(sf::Sprite(*texture, sf::IntRect(baseRect.left+(baseRect.width/2), baseRect.top+(baseRect.height/2), baseRect.width/2 , baseRect.height/2)));
     splits[3].setPosition(position.x+baseRect.width/2,position.y+baseRect.height/2);
     splits[3].setColor(sprite.getColor());
     return splits;
 }