void ofxSpriteAnimation::SetSequence(unsigned short index)
{
	m_SequenceIndex = index;
	m_FrameIndex = m_SequenceBegin[m_SequenceIndex];
	SetTextureRect(
		m_TextureRectTable[m_FrameIndex][0],
		m_TextureRectTable[m_FrameIndex][1],
		m_TextureRectTable[m_FrameIndex][2],
		m_TextureRectTable[m_FrameIndex][3]);
	SetSpriteRect(
		m_SpriteRectTable[m_FrameIndex][0],
		m_SpriteRectTable[m_FrameIndex][1],
		m_SpriteRectTable[m_FrameIndex][2],
		m_SpriteRectTable[m_FrameIndex][3]);
}
void Barrier::Animate()
{
	currentFrame++;
	if (currentFrame > maxFrame)
	{
		currentFrame = 1;
	}

	if (tiled) // Barrier type 4
	{
		// Manually repeat the texture; sf::Texture.setRepeated() will not work because it interferes with animation
		for (int i = 0; i < tiledSize.x; ++i)
		{
			for (int j = 0; j < tiledSize.y; ++j)
			{
				// get a pointer to the current tile's quad
				sf::Vertex* quad = &VerticeList[(j + i * tiledSize.y) * 4];

				// define its 4 corners
				// We subtract GetHitBox().width and height in order for GetPosition() to return the top-left corner
				quad[0].position = sf::Vector2f(GetPosition().x - GetHitBox().width / 2 + i * 16, GetPosition().y - GetHitBox().height / 2 + j * 16);
				quad[1].position = sf::Vector2f(GetPosition().x - GetHitBox().width / 2 + (i + 1) * 16, GetPosition().y - GetHitBox().height / 2 + j * 16);
				quad[2].position = sf::Vector2f(GetPosition().x - GetHitBox().width / 2 + (i + 1) * 16, GetPosition().y - GetHitBox().height / 2 + (j + 1) * 16);
				quad[3].position = sf::Vector2f(GetPosition().x - GetHitBox().width / 2 + i * 16, GetPosition().y - GetHitBox().height / 2 + (j + 1) * 16);

				// define its 4 texture coordinates
				// With animated barriers the textures should be in a straight, horizontal line, so y values do not change
				// Frames are 1-indexed, but the textures are 0-indexed, hence the (currentFrame - 1)
				quad[0].texCoords = sf::Vector2f((currentFrame - 1) * 16, 0);
				quad[1].texCoords = sf::Vector2f((currentFrame) * 16, 0);
				quad[2].texCoords = sf::Vector2f((currentFrame) * 16, 16);
				quad[3].texCoords = sf::Vector2f((currentFrame - 1) * 16, 16);
			}
		}
	}
	else // Barrier type 2
	{
		// Size of one frame
		sf::Vector2i frameSize(GetSprite().getTexture()->getSize().x / maxFrame, GetSprite().getTexture()->getSize().y);
		SetTextureRect(frameSize.x * (currentFrame - 1), 0, GetTextureRect().width, GetTextureRect().height);
	}
	collided = false;
}
Esempio n. 3
0
void sfSprite_SetTextureRect(sfSprite* sprite, sfIntRect rectangle)
{
    CSFML_CALL(sprite, SetTextureRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)));
}
void ofxSpriteQuad::SetTextureRect(const float x, const float y, const float w, const float h)
{
	SetTextureRect(ofRectangle(x, y, w, h));
}
	void Sprite::SetSourceRect(sf::IntRect &rect){
		SetTextureRect(&rect);
	}