本文整理汇总了C++中sf::Sprite::setOrigin方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::setOrigin方法的具体用法?C++ Sprite::setOrigin怎么用?C++ Sprite::setOrigin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::setOrigin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SpriteNode
SpriteNode(const sf::Texture& t,
sf::Vector2f pos)
: mSprite(t)
{
sf::FloatRect bounds = mSprite.getLocalBounds();
mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);
mSprite.setPosition(pos);
};
示例2: main
int main() {
sf::RenderWindow App(sf::VideoMode(imageWidth, imageHeight),
"SFML Graphics",sf::Style::Fullscreen);
// This is the SFML application initialization with the app's parameters
cx[0] = 255; cx[1] = 0; cx[2] = 0;
// The initial colors for the shifting
kradius = 0.1;
imagen.create(imageWidth,imageHeight);
mandtex.create(imageWidth,imageHeight);
// The scaling factor, defined by the ranges in Real and Imaginary axis,
// divided by the respective axis real length.
mandelb.setOrigin(imageWidth/2,imageHeight/2);
mandelb.setPosition(640,400);
mandelb.scale(1.5,1.5);
// Set the image positioning, centering and scaling.
k.real = 0;
k.imag = 0;
// Original K seed values.
dir = false;
// Direction of scan over the complex plane
mandel = false;
// false if painting Julia Set, true if Mandelbrot Set.
draw = true;
// To tell the application to pause or continue drawing, its switched by
// pressing the right click.
while (App.isOpen()) {
sf::Event Event;
while (App.pollEvent(Event)) {
// SFML works with an event loop
if (Event.type == sf::Event::Closed){
// If the window is closed, close the application
App.close();
}
if( Event.type == Event.MouseButtonReleased
&& Event.mouseButton.button == sf::Mouse::Left){
// If the left mouse is pressed and released, close the application
App.close();
}
if( Event.type == Event.MouseButtonReleased
&& Event.mouseButton.button == sf::Mouse::Right){
// If the right mouse is pressed and released, toggle randomness.
draw = !draw;
}
}
App.clear();
if(!draw) continue;
// If false, then stop animating and freeze in the last generated frame.
resolve();
//radialScan();
horizontalScan();
mandelb.setColor(sf::Color(cx[0], cx[1], cx[2]));
// Shift the image hue.
App.draw(mandelb);
App.display();
}
return EXIT_SUCCESS;
}
示例3: init
virtual void init()
{
dt=0;
select_switch = 0.2;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
// darken = sf::RectangleShape(sf::Vector2f(800,400));
//sfx
if (!buffer.loadFromFile("sfx/Blip 007.wav"))
{
//error
}
blip.setBuffer(buffer);
if(!title.loadFromFile("gfx/title.png"))std::cout<<"Error"<<std::endl;
tits.setTexture(title);
tits.setOrigin(50,8);
tits.setScale(sf::Vector2f(3,3));
tits.setPosition(400,100);
sf::FloatRect tempt ;
for(int i =0 ; i<4;i++)
{
selector[i].setFont(standard_font);
selector[i].setCharacterSize(28);
// dla centrowania obiektow
tempt = selector[i].getGlobalBounds();
selector[i].setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
selector[i].setPosition(350,150+30*i);
}
selector[0].setString("Start game");
selector[1].setString("Info");
selector[2].setString("Highscores");
selector[3].setString("Exit");
selector[0].setColor(sf::Color(0,127,127));
timer.restart();
};
示例4: Scenery
Scenery(LevelBlock* host
, const sf::Texture& texture)
: mHostBlock(host)
, mSprite(texture)
{
sf::FloatRect bounds = mSprite.getLocalBounds();
mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);
mSprite.move(20.f, 20.f);
};
示例5: init
//initialize muparser and graphics
void init() {
p.DefineVar("theta", &t);
p.DefineConst("pi", pi);
graph.create(size,size,sf::Color::Transparent);
graphTx.loadFromImage(graph);
graphSpr.setTexture(graphTx);
//center on screen
graphSpr.setOrigin(size/2,size/2);
graphSpr.setPosition(windowsize.x/2, windowsize.y/2);
}
示例6: set_origin
void set_origin()
{
const float mult{0.27f};
assert(mult > 0.0f);
const sf::FloatRect m_image_bounds{m_sprite.getLocalBounds()};
m_sprite.setOrigin(0.5f*m_image_bounds.width, 0.5f*m_image_bounds.height);
m_radius = mult*(m_image_bounds.width + m_image_bounds.height);
}
示例7: draw
void Graphics::draw(sf::Vector2f position, sf::Vector2f hitbox, sf::Sprite sprite)
{
sprite.setOrigin(0, hitbox.y);
sf::Vector2f roundedPosition = sf::Vector2f(position.x - 0.5, position.y - 0.5);
//Translate position
translatePosition(roundedPosition, window_);
//Set Position
sprite.setPosition(roundedPosition);
//Scale if necessary
sprite.scale(hitbox.x / sprite.getTextureRect().width, hitbox.y / sprite.getTextureRect().height);
window_->draw(sprite);
return;
}
示例8: Entity
Entity(sf::Texture& sTexture, EntityType type, Collidable::Type colType, sf::SoundBuffer& soundBuf1, sf::SoundBuffer& soundBuf2)
: Collidable(colType)
, mSprite(sTexture)
, mDeathSound(soundBuf1)
, mLaserSound(soundBuf2)
, mType(type)
, mCollected(0)
, mFireProjectile(false)
, mFireCountdown(sf::Time::Zero)
{
sf::FloatRect bounds = mSprite.getLocalBounds();
mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);
switch(type)
{
case EntityType::Player: mHitPoints = PlayerHitPoints; break;
case EntityType::Enemy: mHitPoints = EnemyHitPoints; break;
default: break;
}
mLaserSound.setVolume(75.f);
mDeathSound.setVolume(75.f);
};
示例9:
Application() :
m_window(sf::VideoMode(300, 300), "Flashlight!"),
m_layer(),
m_rect(sf::Vector2f(100.f, 100.f)),
m_pos(0.f, 0.f)
{
m_window.setFramerateLimit(60);
m_window.setMouseCursorVisible(false);
m_layer.create(300, 300);
m_flashlightTexture.create(60, 60);
// We want to have semi-transparent edges.
generateSpot();
m_flashlight.setTexture(m_flashlightTexture.getTexture(), true);
m_flashlight.setPosition(150.f, 150.f);
m_flashlight.setOrigin(30.f, 30.f);
m_rect.setFillColor(sf::Color::Red);
m_rect.setPosition(100.f, 100.f);
m_sprite.setTexture(m_layer.getTexture());
}
示例10: centerOrigin
inline void centerOrigin(sf::Sprite& sprite)
{
sf::FloatRect bounds = sprite.getLocalBounds();
sprite.setOrigin(std::floor(bounds.left + bounds.width / 2.f), std::floor(bounds.top + bounds.height / 2.f));
}
示例11: main
//.........这里部分代码省略.........
sf::ConvexShape cShape;
cShape.setFillColor(sf::Color::Red);
//This loops through every single body in the game world
for(b2Body* b = world->GetBodyList(); b; b = b->GetNext()) {
//This loops through every fixture in the current body
for(b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) {
//This checks to see if the type of the fixture is a polygon, if it is then draw the polygon
if(f->GetType() == b2Shape::e_polygon && currentLevel != 2) {
// Create the convex shape
static sf::ConvexShape cShape;
cShape.setFillColor(sf::Color::Red);
//Stores a pointer to the shape stored in the fixture
b2PolygonShape* s = (b2PolygonShape*)f->GetShape();
//Get the amount of vertices stored in the shape
size = s->GetVertexCount();
//Set the size of the object in SFML so it knows how many vertices the shape should have
cShape.setPointCount(size);
//Loop through the vertices and send them from Box2D to the SFML shape
for(int i = 0; i < size; i++) {
//Stores the current vertex in v
b2Vec2 v = s->GetVertex(i);
//Converts the vertex from its local space to where it is in the world
cShape.setPoint(i, sf::Vector2f((b->GetWorldVector(v).x + b->GetPosition().x), (b->GetWorldVector(v).y + b->GetPosition().y)));
}
//Draws the shape onto the window
window.draw(cShape);
}
else if ((f->GetType() == b2Shape::e_polygon && b->GetType() == b2_dynamicBody)) {
static sf::Sprite bikeFrame;
bikeFrame.setTexture(bikeFrame_t);
bikeFrame.setPosition(f->GetBody()->GetPosition().x, f->GetBody()->GetPosition().y);
bikeFrame.setScale(0.5f,0.5f);
bikeFrame.setRotation(b->GetAngle() * 57.2957795f);
bikeFrame.setOrigin(0,0);
window.draw(bikeFrame);
}
else if (f->GetType() == b2CircleShape::e_circle) {
// // Create A cricle to be drawn
// static sf::CircleShape circle;
// circle.setFillColor(sf::Color::Green);
// //Stores a pointer to the shape stored in the fixture
// b2PolygonShape* s = (b2PolygonShape*)f->GetShape();
// // Calculate the radius for the SFML circle
// circle.setRadius(s->m_radius);
// circle.setPosition(f->GetBody()->GetPosition().x - circle.getRadius(), f->GetBody()->GetPosition().y - circle.getRadius());
// window.draw(circle);
b2PolygonShape* s = (b2PolygonShape*)f->GetShape();
static sf::Sprite sWheel;
sWheel.setScale((s->m_radius*0.01)*2,(s->m_radius*0.01)*2);
sWheel.setPosition (f->GetBody()->GetPosition().x, f->GetBody()->GetPosition().y);
if(currentLevel == 1) sWheel.setTexture(wheel);
if(currentLevel == 2) sWheel.setTexture(bikeWheel);
sWheel.setOrigin(50,50);
sWheel.setRotation(b->GetAngle() * 57.2957795f);
window.draw(sWheel);
}
}
}
#pragma endregion
#pragma region DrawClickedLines
// draw all elements in line vector
for(int i = 0; i != lines.size(); ++i) {
示例12: CenterSpriteHor
void CenterSpriteHor(sf::Sprite& sprite, const sf::RenderTarget& target)
{
sf::FloatRect sprite_bounds = sprite.getLocalBounds();
sprite.setOrigin(sprite_bounds.left + (sprite_bounds.width/2.f), 0);
sprite.setPosition(target.getSize().x/2.f, sprite.getPosition().y);
}
示例13: centerElement
void MameUIsenWindow::centerElement(sf::Sprite& sprite)
{
sf::FloatRect fr = sprite.getLocalBounds();
sprite.setOrigin(fr.left + fr.width/2.0f, fr.top + fr.height/2.0f);
}
示例14: Player
Player () {
PlayerNumber = totalPlayers;
Sprite = loadSpriteData("Player " + intToString(PlayerNumber + 1));
//Get Global width, seperate to rotation
CharacterWidth = Sprite.getGlobalBounds().width;
nameSpacing = 30;
healthBarSpacing = nameSpacing + 15;
Sprite.setOrigin(Sprite.getGlobalBounds().width/2, Sprite.getGlobalBounds().height/2);
Sprite.setPosition((App.getSize().x/2) - (Sprite.getGlobalBounds().width/2), (App.getSize().y/2) - (Sprite.getGlobalBounds().height/2));
//PlayerName.setFont(sf::Font::getDefaultFont());
PlayerName.setCharacterSize(15);
PlayerName.setString("Player: " + intToString(PlayerNumber + 1));
PlayerName.setOrigin(PlayerName.getGlobalBounds().width/2, PlayerName.getGlobalBounds().height/2);
PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing);
NameOutline.setSize(sf::Vector2f(PlayerName.getGlobalBounds().width, PlayerName.getGlobalBounds().height));
NameOutline.setOutlineThickness(2);
NameOutline.setFillColor(sf::Color(0, 0, 0, 120));
NameOutline.setOutlineColor(sf::Color::Black);
NameOutline.setOrigin(NameOutline.getGlobalBounds().width/2, NameOutline.getGlobalBounds().height/2);
NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4);
MaxHealth = Health = 100;
HealthBarSize = 50;
HealthBarRed.setSize(sf::Vector2f(HealthBarSize, 5));
HealthBarRed.setOutlineThickness(1);
HealthBarRed.setFillColor(sf::Color::Red);
HealthBarRed.setOutlineColor(sf::Color::Black);
HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);
HealthBarGreen.setSize(sf::Vector2f(HealthBarSize, 5));
HealthBarGreen.setOutlineThickness(1);
HealthBarGreen.setFillColor(sf::Color::Green);
HealthBarGreen.setOutlineColor(sf::Color::Black);
HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);
if (controllerConnected) {
ControlScheme = ControlSchemes::Joystick;
Key k;
k.InputType = Input::JoystickMovedNeg;
k.KeyCode = sf::Joystick::Axis::Y;
Bindings["Up"] = k;
k.InputType = Input::JoystickMovedPos;
k.KeyCode = sf::Joystick::Axis::Y;
Bindings["Down"] = k;
k.InputType = Input::JoystickMovedNeg;
k.KeyCode = sf::Joystick::Axis::X;
Bindings["Left"] = k;
k.InputType = Input::JoystickMovedPos;
k.KeyCode = sf::Joystick::Axis::X;
Bindings["Right"] = k;
} else {
ControlScheme = ControlSchemes::KeyboardMouse;
Key k;
k.InputType = Input::KeyboardInput;
k.KeyCode = sf::Keyboard::W;
Bindings["Up"] = k;
k.InputType = Input::KeyboardInput;
k.KeyCode = sf::Keyboard::S;
Bindings["Down"] = k;
k.InputType = Input::KeyboardInput;
k.KeyCode = sf::Keyboard::A;
Bindings["Left"] = k;
k.InputType = Input::KeyboardInput;
k.KeyCode = sf::Keyboard::D;
Bindings["Right"] = k;
}
totalPlayers++;
}
示例15: setOrigin
void Unit::setOrigin(float x, float y) {
if(_isLoaded) {
_sprite.setOrigin(x, y);
}
}