本文整理汇总了C++中sf::Sprite类的典型用法代码示例。如果您正苦于以下问题:C++ Sprite类的具体用法?C++ Sprite怎么用?C++ Sprite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sprite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: overlap
bool overlap(sf::Sprite& sprite1, sf::Sprite& sprite2)
{
sf::FloatRect rectangle1 = sprite1.getGlobalBounds();
sf::FloatRect rectangle2 = sprite2.getGlobalBounds();
// Rectangles with negative dimensions are allowed, so we must handle them correctly
// Compute the min and max of the first rectangle on both axes
float r1MinX = std::min(rectangle1.left, rectangle1.left + rectangle1.width); //left
float r1MaxX = std::max(rectangle1.left, rectangle1.left + rectangle1.width);//right
float r1MinY = std::min(rectangle1.top, rectangle1.top + rectangle1.height); // top
float r1MaxY = std::max(rectangle1.top, rectangle1.top + rectangle1.height); // bottom of the maincharactersprite
// Compute the min and max of the second rectangle on both axes
float r2MinX = std::min(rectangle2.left, rectangle2.left + rectangle2.width);//left
float r2MaxX = std::max(rectangle2.left, rectangle2.left + rectangle2.width);//right
float r2MinY = std::min(rectangle2.top, rectangle2.top + rectangle2.height);//top of the blocksprite
float r2MaxY = std::max(rectangle2.top, rectangle2.top + rectangle2.height); // bottom
// Compute the intersection boundaries
float interLeft = std::max(r1MinX, r2MinX);//get the most right one
float interTop = std::max(r1MinY, r2MinY);//get the higher one
float interRight = std::min(r1MaxX, r2MaxX);// get the most left one
float interBottom = std::min(r1MaxY, r2MaxY);// the the lowest one
//want to check if bottom of the mainCharacterSprite and top of the Block sprite are overlaping
// If the intersection is valid (positive non zero area), then there is an intersection
return ((interLeft <= interRight) && (interTop <= interBottom));
}
示例2: GetBoundingBox
/*!
* \param Obj The object
* \return The bounding box of the object
*/
sf::IntRect Collision::GetBoundingBox(const sf::Sprite &Obj)
{
const sf::Vector2f &Position(Obj.GetPosition());
const sf::IntRect &SubRect(Obj.GetSubRect());
return sf::IntRect(Position.x, Position.y, Position.x + SubRect.GetWidth(),
Position.y + SubRect.GetHeight());
}
示例3: distance
float distance(sf::Sprite spA, sf::Sprite spB)
{
return sqrt((spA.getPosition().x - spB.getPosition().x) *
(spA.getPosition().x - spB.getPosition().x) +
(spA.getPosition().y - spB.getPosition().y) *
(spA.getPosition().y - spB.getPosition().y));
}
示例4: Update
void Update(float fTime)
{
FRect.left += dx * fTime;
// x
Collision(0);
if (!bOnGround)
dy = dy + 0.0005f * fTime;
FRect.top += dy * fTime;
bOnGround = false;
// y
Collision(1);
fCurrentFrame += 0.005f * fTime;
if (fCurrentFrame > 3)
fCurrentFrame -= 3;
if(dx > 0)
SSprite.setTextureRect(sf::IntRect(112 + 30 * int(fCurrentFrame), 144, 16, 16));
if(dx < 0)
SSprite.setTextureRect(sf::IntRect(112 + 30 * int(fCurrentFrame) + 16, 144, -16, 16));
SSprite.setPosition(FRect.left - g_fOffsetX, FRect.top - g_fOffsetY);
dx = 0;
}
示例5: 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);*/
}
示例6: 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;
}
示例7: isAbove
bool isAbove(sf::Sprite sp2) {
if ((sp2.getPosition().y < sprite.getPosition().y)!=playerAbove) {
playerAbove=!playerAbove;
return true;
}
return false;
}
示例8: overlap
bool overlap(sf::Sprite& sprite1, sf::Sprite& sprite2)
{
sf::FloatRect rectangle1 = sprite1.getGlobalBounds();
sf::FloatRect rectangle2 = sprite2.getGlobalBounds();
// Rectangles with negative dimensions are allowed, so we must handle them correctly
// Compute the min and max of the first rectangle on both axes
float r1MinX = std::min(rectangle1.left, rectangle1.left + rectangle1.width);
float r1MaxX = std::max(rectangle1.left, rectangle1.left + rectangle1.width);
float r1MinY = std::min(rectangle1.top, rectangle1.top + rectangle1.height);
float r1MaxY = std::max(rectangle1.top, rectangle1.top + rectangle1.height);
// Compute the min and max of the second rectangle on both axes
float r2MinX = std::min(rectangle2.left, rectangle2.left + rectangle2.width);
float r2MaxX = std::max(rectangle2.left, rectangle2.left + rectangle2.width);
float r2MinY = std::min(rectangle2.top, rectangle2.top + rectangle2.height);
float r2MaxY = std::max(rectangle2.top, rectangle2.top + rectangle2.height);
// Compute the intersection boundaries
float interLeft = std::max(r1MinX, r2MinX);
float interTop = std::max(r1MinY, r2MinY);
float interRight = std::min(r1MaxX, r2MaxX);
float interBottom = std::min(r1MaxY, r2MaxY);
// If the intersection is valid (positive non zero area), then there is an intersection
return ((interLeft <= interRight) && (interTop <= interBottom));
}
示例9:
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);
}
示例10: movement
void movement(sf::Sprite& character, sf::RenderWindow& window)
{
float moveSpeed = 0.1, moveSpeedR = -0.1;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift))
{
moveSpeed /= 2.2;
moveSpeedR /= 2.2;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
{
moveSpeed *= 2.2;
moveSpeedR *= 2.2;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
character.move(0, moveSpeedR);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
character.move(0, moveSpeed);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
character.move(moveSpeed, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
character.move(moveSpeedR, 0);
}
}
示例11: 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;
}
示例12: drawSprite
void drawSprite(int x, int y, double w, double h, TextureIndex textureIndex)
{
freeSprite.setPosition(x, y);
freeSprite.setTexture(getTexture(textureIndex));
freeSprite.setScale(w / getTexture(textureIndex).getSize().x, h / getTexture(textureIndex).getSize().y);
window->draw(freeSprite);
}
示例13:
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);
}
示例14: 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;
}
示例15: setTexture
void cursor::setTexture(string cursorPass)
{
sprite.setTexture(textureManager.get(cursorPass));
sprite.setOrigin((Collision::GetSpriteSize(sprite).x / sprite.getScale().x / 2), (Collision::GetSpriteSize(sprite).y / sprite.getScale().y / 2));
sprite.rotate(-90);
sprite.setColor(sf::Color(255, 255, 255, settings.getCursorAplha()));
}