本文整理汇总了C++中sf::Sprite::GetSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::GetSize方法的具体用法?C++ Sprite::GetSize怎么用?C++ Sprite::GetSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::GetSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_image
void _Log::load_image(){
if( image_loaded == false && image_path.length() != 0 ) {
Sprite.SetImage( VNImageManager.get_image( image_path ) );
Sprite.SetY( WINDOW_HEIGHT - Sprite.GetSize().y );
switch( align ){
case 1:
Sprite.SetX( 0.f );
break;
case 2:
Sprite.SetX( 100.f );
break;
case 3:
Sprite.SetX( WINDOW_WIDTH/2 - Sprite.GetSize().x /2 );
break;
case 4:
Sprite.SetX( WINDOW_WIDTH - 100.f - Sprite.GetSize().x );
break;
case 5:
Sprite.SetX( WINDOW_WIDTH - Sprite.GetSize().x );
break;
}
image_loaded = true;
}
}
示例2: detectCollision
bool Bullet::detectCollision(sf::Vector2f p, const sf::Sprite& sprite) const
{
/* collide if the pixel is not transparent */
int img_width = sprite.GetSize().x, img_height = sprite.GetSize().y;
int img_x = pos.x - p.x + img_width / 2, img_y = pos.y - p.y + img_height / 2;
if (img_x < 0 || img_x >= img_width)
return false;
if (img_y < 0 || img_y >= img_height)
return false;
return sprite.GetPixel(img_x, img_y).a != 0;
}
示例3: 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;
}
示例4: GetSpriteEnemy
void ImageManager::GetSpriteEnemy(sf::Sprite &sprite, int whichEnemy)
{
if(whichEnemy == ENEMY1)
{
sprite.SetImage(m_enemy1);
sprite.SetSubRect(sf::IntRect(1, 1, sprite.GetSize().x-1, sprite.GetSize().y-1));//To do avec le charset
}
else
std::cerr << "erreur fonction ImageManager.GetSpriteEnemy appelée avec whichEnemy = " << whichEnemy << std::endl;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例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: init
void init(){
_backgroundImage.LoadFromFile("assets/wood-puzzle-floor.png");
_backgroundSprite.SetImage(_backgroundImage);
_robotImage.LoadFromFile("assets/roomba.png");
_robotSprite.SetImage(_robotImage);
_robotSprite.SetCenter(_robotSprite.GetSize().x/2, _robotSprite.GetSize().y/2);
_fakeRobotSprite.SetImage(_robotImage);
_fakeRobotSprite.SetCenter(_fakeRobotSprite.GetSize().x/2, _fakeRobotSprite.GetSize().y/2);
_fakeRobotSprite.SetColor(sf::Color(100,100,255));
_landmarkImage.LoadFromFile("assets/landmark.png");
_landmarkSprite.SetImage(_landmarkImage);
_landmarkSprite.SetCenter(_landmarkSprite.GetSize().x/2, _landmarkSprite.GetSize().y/2);
_rangeImage.LoadFromFile("assets/range.png");
_rangeSprite.SetImage(_rangeImage);
original_range_sprite_size_x = _rangeSprite.GetSize().x;
original_range_sprite_size_y = _rangeSprite.GetSize().y;
updateRangeSpriteScale();
_rangeSprite.SetCenter((original_range_sprite_size_x/2), (original_range_sprite_size_y/2));
_window.Create(sf::VideoMode(window_width,window_height,32), "Bearing simulator");
move_amount = 0;
rotation_amount = 0;
time_to_capture = false;
walk = 0;
rotation = 0;
}
示例10: 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);
}
示例11: main
int main()
{
img_r.LoadFromFile("..\\Imagenes\\rcircle.png");
img_b.LoadFromFile("..\\Imagenes\\bcircle.png");
sprite_b.SetImage(img_b);
sprite_r.SetImage(img_r);
sf::RenderWindow App(sf::VideoMode(800,600,32),"ventana");
const sf::Input& in = App.GetInput();
sprite_b.Scale(sprite_r.GetSize().x/sprite_b.GetSize().x,sprite_r.GetSize().y/sprite_b.GetSize().y);
while(App.IsOpened())
{
while(App.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
App.Close();
if(Event.Type == sf::Event::MouseMoved){
// cursor.SetPosition(Event.MouseMove.X,Event.MouseMove.Y);
}
}
if(in.IsKeyDown(sf::Key::Escape))
App.Close();
//cursor.SetPosition(in.GetMouseX(),in.GetMouseY());
App.Clear();
sprite_r.SetPosition(0,0);
App.Draw(sprite_r);
sprite_r.SetPosition(App.GetWidth()-img_r.GetWidth(),0);
App.Draw(sprite_r);
sprite_r.SetPosition(0,App.GetHeight()-img_r.GetHeight());
App.Draw(sprite_r);
sprite_r.SetPosition(App.GetWidth()-img_r.GetWidth(),App.GetHeight()-img_r.GetHeight());
App.Draw(sprite_r);
sprite_b.SetPosition((App.GetWidth()-sprite_b.GetSize().x)/2,(App.GetHeight()-sprite_b.GetSize().y)/2);
App.Draw(sprite_b);
App.Display();
}
return 0;
}
示例12: 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);
}
示例13: GetAABB
sf::IntRect Collision::GetAABB(const sf::Sprite& Object) {
//Get the top left corner of the sprite regardless of the sprite's center
//This is in Global Coordinates so we can put the rectangle back into the right place
sf::Vector2f pos = Object.TransformToGlobal(sf::Vector2f(0, 0));
//Store the size so we can calculate the other corners
sf::Vector2f size = Object.GetSize();
float Angle = Object.GetRotation();
//Bail out early if the sprite isn't rotated
if (Angle == 0.0f) {
return sf::IntRect(static_cast<int> (pos.x),
static_cast<int> (pos.y),
static_cast<int> (pos.x + size.x),
static_cast<int> (pos.y + size.y));
}
//Calculate the other points as vectors from (0,0)
//Imagine sf::Vector2f A(0,0); but its not necessary
//as rotation is around this point.
sf::Vector2f B(size.x, 0);
sf::Vector2f C(size.x, size.y);
sf::Vector2f D(0, size.y);
//Rotate the points to match the sprite rotation
B = RotatePoint(B, Angle);
C = RotatePoint(C, Angle);
D = RotatePoint(D, Angle);
//Round off to int and set the four corners of our Rect
int Left = static_cast<int> (MinValue(0.0f, B.x, C.x, D.x));
int Top = static_cast<int> (MinValue(0.0f, B.y, C.y, D.y));
int Right = static_cast<int> (MaxValue(0.0f, B.x, C.x, D.x));
int Bottom = static_cast<int> (MaxValue(0.0f, B.y, C.y, D.y));
//Create a Rect from out points and move it back to the correct position on the screen
sf::IntRect AABB = sf::IntRect(Left, Top, Right, Bottom);
AABB.Offset(static_cast<int> (pos.x), static_cast<int> (pos.y));
return AABB;
}
示例14: collide
bool Collision::collide(sf::Sprite& obj, float dx, float dy, CollisionResult& result) {
//assert(_map->tileFromPixel(obj.GetPosition().x, obj.GetPosition().y)->isWalkable());
//assert(_map->tileFromPixel(obj.GetPosition().x + obj.GetSize().x, obj.GetPosition().y)->isWalkable());
std::cout << "posx: " << obj.GetPosition().x << std::endl;
std::cout << "posy: " << obj.GetPosition().y << std::endl;
std::cout << "dx: " << dx << std::endl;
std::cout << "dy: " << dy << std::endl;
result.left = false;
result.right = false;
result.floor = false;
result.ceil = false;
result.dx = dx;
result.dy = dy;
if(dx != 0.f) { //if moving horizontal
bool left = dx < 0;
float forwardX;
if(left)
forwardX = obj.GetPosition().x;
else
forwardX = obj.GetPosition().x + obj.GetSize().x;
float newX = forwardX + dx;
float topY = obj.GetPosition().y + constants::COLLISION_MARGIN;
float botY = obj.GetPosition().y + obj.GetSize().y - constants::COLLISION_MARGIN;
Tile* topTile = _map->tileFromPixel(newX, topY);
Tile* botTile = _map->tileFromPixel(newX, botY);
if(!topTile->isWalkable() || !botTile->isWalkable()) {
result.left = left;
result.right = !left;
float limit;
if(left)
limit = topTile->GetPosition().x + topTile->GetSize().x;
else
limit = topTile->GetPosition().x;
result.dx = limit - forwardX;
}
std::cout << "res.dx=" << result.dx << std::endl;
assert(left || result.dx <= dx);
assert(!left || result.dx >= dx);
//assert(result.dx * dx >= 0); //same direction
}
float objPosX = obj.GetPosition().x + result.dx;
if(dy != 0.f) { //if moving vertically
bool down = dy > 0;
float forwardY;
if(down)
forwardY = obj.GetPosition().y + obj.GetSize().y;
else
forwardY = obj.GetPosition().y;
float newY = forwardY + dy;
Tile* leftTileY = _map->tileFromPixel(objPosX + constants::COLLISION_MARGIN, newY);
Tile* rightTileY = _map->tileFromPixel(objPosX + obj.GetSize().x - constants::COLLISION_MARGIN, newY);
if(!leftTileY->isWalkable() || !rightTileY->isWalkable()) {
result.floor = down;
result.ceil = !down;
float limit;
if(down)
limit = leftTileY->GetPosition().y;// - constants::COLLISION_MARGIN;
else
limit = leftTileY->GetPosition().y + leftTileY->GetSize().y;// + constants::COLLISION_MARGIN;
result.dy = limit - forwardY;
}
std::cout << "res.dy=" << result.dy << std::endl;
assert(down || result.dy >= dy);
assert(!down || result.dy <= dy);
//assert(result.dy * dy >= 0); //same direction
}
return result.floor || result.ceil || result.left || result.right;
}
示例15: isPointOverSprite
bool Table::isPointOverSprite(const sf::Vector2f Position, sf::Sprite &Sprite){
return (Position.x < Sprite.GetPosition().x + Sprite.GetSize().x) && (Sprite.GetPosition().x < Position.x) && (Position.y < Sprite.GetPosition().y + Sprite.GetSize().y) && (Sprite.GetPosition().y < Position.y);
}