本文整理汇总了C++中sf::Sprite::GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::GetPosition方法的具体用法?C++ Sprite::GetPosition怎么用?C++ Sprite::GetPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::GetPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CircleTest
bool Collision::CircleTest(const sf::Sprite& Object1, const sf::Sprite& Object2) {
//Simplest circle test possible
//Distance between points <= sum of radius
float Radius1 = (Object1.GetSize().x + Object1.GetSize().y) / 4;
float Radius2 = (Object2.GetSize().x + Object2.GetSize().y) / 4;
float xd = Object1.GetPosition().x - Object2.GetPosition().x;
float yd = Object1.GetPosition().y - Object2.GetPosition().y;
return sqrt(xd * xd + yd * yd) <= Radius1 + Radius2;
}
示例2: contains
//returns true if (x,y) is inside sprite fiure
bool contains(float x, float y, const sf::Sprite& sprite)
{
float minX = sprite.GetPosition().x;
float minY = sprite.GetPosition().y;
float maxX = sprite.GetPosition().x + sprite.GetSize().x;
float maxY = sprite.GetPosition().y + sprite.GetSize().y;
//return if x and y falls in between sprite's range
return isBetween(x,minX, maxX) && isBetween(y,minY, maxY);
}
示例3: isInside
bool Mouse::isInside(sf::Sprite &sprite) {
float x1, x2, y1, y2;
x1 = sprite.GetPosition().x;
x2 = x1 + sprite.GetSize().x;
y1 = sprite.GetPosition().y;
y2 = y1 + sprite.GetSize().y;
if ((this->x < x2) && (this->x > x1)) {
if ((this->y < y2) && (this->y > y1)) {
return true;
}
}
return false;
}
示例4: sourisAuDessusBoutons
bool sourisAuDessusBoutons(sf::Event &Event, sf::Sprite &Bouton)
{
//test la position actuelle du curseur ainsi que sa position future
//si le curseur est au-dessus du sprite, alors on l'affiche !
if((Event.MouseMove.X < Bouton.GetPosition().x+Bouton.GetSize().x && Event.MouseMove.X>Bouton.GetPosition().x &&
Event.MouseMove.Y<Bouton.GetPosition().y+Bouton.GetSize().y && Event.MouseMove.Y>Bouton.GetPosition().y) ||
(Event.MouseButton.X < Bouton.GetPosition().x+Bouton.GetSize().x && Event.MouseButton.X>Bouton.GetPosition().x &&
Event.MouseButton.Y<Bouton.GetPosition().y+Bouton.GetSize().y && Event.MouseButton.Y>Bouton.GetPosition().y))
{
return true;
}
else
return false;
}
示例5:
bool np::Collision::BoundingBoxColl(sf::Sprite &object1, sf::Sprite &object2)
{
leftA = object1.GetPosition().x;
rightA = object1.GetPosition().x + object1.GetSubRect().GetWidth();
topA = object1.GetPosition().y;
bottomA = object1.GetPosition().y + object1.GetSubRect().GetHeight();
leftB = object2.GetPosition().x;
rightB = object2.GetPosition().x + object2.GetSubRect().GetWidth();
topB = object2.GetPosition().y;
bottomB = object2.GetPosition().y + object2.GetSubRect().GetHeight();
if(bottomA <= topB)
return false;
if(topA >= bottomB)
return false;
if(leftA >= rightB)
return false;
if(rightA <= leftB)
return false;
return true;
}
示例6: contains
bool Utility::contains(sf::Sprite sp, int x, int y){
float posX1 = sp.GetPosition().x - sp.GetSize().x/2;
float posY1 = sp.GetPosition().y - sp.GetSize().y/2;
//sf::Vector2f center = sp.GetCenter();
float posX2 = sp.GetPosition().x + sp.GetSize().x/2;
float posY2 = sp.GetPosition().y + sp.GetSize().y/2;
//sf::Vector2f
//if(s
if(x > posX1 && x < posX2 && y > posY1 && y < posY2)
return true;
return false;
}
示例7: 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());
}
示例8:
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);
}
示例9: cliqueBouton
bool cliqueBouton(sf::Event &Event, sf::Sprite &BoutonJ)
{
if ((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.X > BoutonJ.GetPosition().x) && (Event.MouseButton.X < BoutonJ.GetPosition().x+BoutonJ.GetSize().x) && (Event.MouseButton.Y > BoutonJ.GetPosition().y) && (Event.MouseButton.Y < BoutonJ.GetPosition().y+BoutonJ.GetSize().y))
return true;
else
return false;
}
示例10: getIntRect
sf::IntRect Colision::getIntRect(const sf::Sprite &sprite)
{
const sf::Vector2f &pos(sprite.GetPosition());
const sf::IntRect &sub_rect(sprite.GetSubRect());
sf::IntRect int_rect((int)pos.x, (int)pos.y, (int)(pos.x + sub_rect.GetWidth()), (int)(pos.y + sub_rect.GetHeight()));
return (int_rect);
}
示例11: setXYCheckeur
void setXYCheckeur(sf::Sprite &Checkeur, Fenetre Fen, sf::Sprite &Case1, sf::Sprite &Case2, sf::Sprite &Case3)
{
if(Fen.getLargeur()==1152)
{
Checkeur.SetX(Case1.GetPosition().x);
Checkeur.SetY(Case1.GetPosition().y);
}
else if(Fen.getLargeur()==1024)
{
Checkeur.SetX(Case2.GetPosition().x);
Checkeur.SetY(Case2.GetPosition().y);
}
else
{
Checkeur.SetX(Case3.GetPosition().x);
Checkeur.SetY(Case3.GetPosition().y);
}
}
示例12:
sf::Sprite RectangleBlock::CopySprite(sf::Sprite& sprite,sf::Vector2<float> offSet) {
sf::Sprite ret = sf::Sprite(sprite);
sf::Vector2<float> new_coord = sprite.GetPosition() - offSet;
ret.SetPosition(new_coord);
return ret;
}
示例13: boutonValiderParametres
void Fenetre::boutonValiderParametres(sf::RenderWindow &App, sf::Event &Event, sf::Sprite &Checkeur, sf::Sprite &ValiderReso, sf::Sprite &Case1, sf::Sprite &Case2, sf::Sprite &Case3, string &code)
{
int x, y;
if (cliqueBouton(Event, ValiderReso)){
if(Checkeur.GetPosition().y==Case1.GetPosition().y){
x=1152; y=864;
}else if(Checkeur.GetPosition().y==Case2.GetPosition().y){
x=1024; y=768;
}else{
x=800; y=600;
}
code="accueil";
ecrireResolutionRD(x, y);
//App.Create(sf::VideoMode(x, y), "Jeu du morpion par Romain Dauby");
//changerResolution(x, y);
//si l'on décommente ces deux lignes, il faudrait relancer le gestionnaire de ressources.
}
}
示例14: getCoordinates
void cCollider::getCoordinates(sf::Sprite& thisSprite)
{
setMinX(thisSprite.GetPosition().x);
setMaxY(thisSprite.GetPosition().y);
if (maxY > 763) {
setOnGround(true);
//rThisSprite.SetY(763);
}
else {
setOnGround(false);
}
maxX = minX + width;
minY = maxY - height;
}
示例15: boxCollision
bool boxCollision(const sf::Sprite& a, const sf::Sprite& b)
{
sf::IntRect aRect(a.GetPosition().x - a.GetSize().x/2,
a.GetPosition().y - a.GetSize().y/2,
a.GetPosition().x + a.GetSize().x/2,
a.GetPosition().y + a.GetSize().y/2);
sf::IntRect bRect(b.GetPosition().x - b.GetSize().x/2,
b.GetPosition().y - b.GetSize().y/2,
b.GetPosition().x + b.GetSize().x/2,
b.GetPosition().y + b.GetSize().y/2);
return aRect.Intersects(bRect);
}