本文整理汇总了C++中sf::CircleShape::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CircleShape::setPosition方法的具体用法?C++ CircleShape::setPosition怎么用?C++ CircleShape::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::CircleShape
的用法示例。
在下文中一共展示了CircleShape::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setPosition
void Unit::setPosition(float x, float y) {
if(_isLoaded) {
_circle.setPosition(x,y);
_sprite.setPosition(x,y);
}
else {
_circle.setPosition(x,y);
}
}
示例2: initialize
void Particles::initialize() {
int displayxi = int(displayx);
int displayyi = int(displayy);
int radiusi = int(radius);
int wallwidthi = int(wallwidth);
srand(time(NULL));
for( int i = 0; i<Nparticles; i++ ) {
float tempR = rand() % ((displayyi-24)/2);
float tempAngle = rand() % 360;
float tempX = -tempR*sin(tempAngle*conv);
float tempY = tempR*cos(tempAngle*conv);
sf::Vector2f temp(tempX, tempY);
sf::Vector2f placeParticles = temp + centerofmap;
particles.setPosition( placeParticles );
sf::Vector2f currentParticle = particles.getPosition();
sf::Vector2f tempPos(0,0);
sf::Vector2f disVec(0,0);
float distance = 0;
// Need to check if particles overlap during initialization
// if it does overlap, just move it by some amount
// We do not need to check if there is just one particle
if( i==0 ) {
storeParticles.push_back( particles );
}
else {
for( it = storeParticles.begin(); it != storeParticles.end(); it++ ) {
tempPos = (*it).getPosition();
disVec = currentParticle - tempPos;
distance = sqrt(pow(disVec.x,2) + pow(disVec.y,2) );
if( distance < 2.2*radius ) deleted++;
while( distance < 2.2*radius ){
(particles).setPosition( rand()%(displayxi-2*wallwidthi-3*radiusi)+(wallwidthi+1.5*radiusi), rand()%(displayyi-3*radiusi-2*wallwidthi)+(wallwidthi+1.5*radiusi) );
currentParticle = particles.getPosition();
tempPos = (*it).getPosition();
disVec = currentParticle - tempPos;
distance = sqrt(pow(disVec.x,2) + pow(disVec.y,2) );
if( i>=2 ) {
for( bit=storeParticles.begin(); bit != it; bit++ ){
tempPos = (*bit).getPosition();
disVec = currentParticle - tempPos;
distance = sqrt( pow(disVec.x,2)+pow(disVec.y,2));
if( distance < 2.2*radius ){
(particles).setPosition( rand()%(displayxi-2*wallwidthi-3*radiusi)+(wallwidthi+1.5*radiusi), rand()%(displayyi-3*radiusi-2*wallwidthi)+(wallwidthi+1.5*radiusi) );
}
}
}
}
}
storeParticles.push_back(particles);
}
}
}
示例3: Ball
Ball(float mX, float mY)
{
shape.setPosition(mX, mY);
shape.setRadius(defRadius);
shape.setFillColor(defColor);
shape.setOrigin(defRadius, defRadius);
}
示例4: gameWindow
Pong() : gameWindow(sf::VideoMode(600, 480), "Pong")
{
ball.setFillColor(sf::Color::Cyan);
ball.setPosition(100.0, 100.0);
ball.setRadius(10.f);
p1Paddle.setFillColor(sf::Color::Green);
p1Paddle.setPosition(10.0, 100.0);
p1Paddle.setSize(sf::Vector2f(10.0, 100.0));
p2Paddle.setFillColor(sf::Color::Red);
p2Paddle.setPosition(580.0, 100.0);
p2Paddle.setSize(sf::Vector2f(10.0, 100.0));
p1MovingUp = false;
p1MovingDown = false;
p2MovingUp = false;
p2MovingDown = false;
ballMovement = sf::Vector2f(ballSpeed, ballSpeed);
font.loadFromFile("arial.ttf");
p1ScoreText.setPosition(150, 10);
p1ScoreText.setFont(font);
p1ScoreText.setString(std::to_string(p1Score));
p1ScoreText.setColor(sf::Color::Red);
p1ScoreText.setCharacterSize(24);
p2ScoreText.setPosition(450, 10);
p2ScoreText.setFont(font);
p2ScoreText.setString(std::to_string(p2Score));
p2ScoreText.setColor(sf::Color::Red);
p2ScoreText.setCharacterSize(24);
}
示例5: RespawnApple
void World::RespawnApple() {
_msgCallback("Respawning Apple");
int maxX = _windowSize.x / _blockSize - 2;
int maxY = _windowSize.y / _blockSize - 2;
_item = sf::Vector2i(rand() % maxX + 1, rand() % maxY + 1);
_appleShape.setPosition(_item.x * _blockSize, _item.y * _blockSize);
}
示例6: exibeHud
/*
* Mostra na tela os indicadores básicos do jogo:
* vidas restantes, HP e pontuação.
*/
void Jogo::exibeHud()
{
float x = 0.10 * janela.getSize().x;
float y = 0.15 * janela.getSize().y;
/* Desenha vidas extras da nave */
static sf::CircleShape losango(20.0, 4);
for (int i = 0; i < nave->getVidas(); i++) {
double deltaX = 2.5 * losango.getRadius();
losango.setPosition(x + (i * deltaX), y);
janela.draw(losango);
}
/* Desenha caixa da lifebar */
y += 3.0 * losango.getRadius();
static sf::RectangleShape caixa({200.0, 10.0});
caixa.setPosition(x, y);
caixa.setFillColor(sf::Color::Blue);
janela.draw(caixa);
/* Desenha lifebar com parcial do HP */
float k = (float) nave->getHP() / nave->getHPMax();
sf::RectangleShape lifebar({k * caixa.getSize().x,
caixa.getSize().y});
lifebar.setPosition(x, y);
lifebar.setFillColor(k > 0.25 ? sf::Color::Green : sf::Color::Red);
janela.draw(lifebar);
/* Imprime pontuação (e, se for o caso, mensagem de pausa) */
y += 2.5 * lifebar.getSize().y;
sf::String str = "Score: " + std::to_string(nave->getScore());
if (pausado) str += " (pausa)";
sf::Text texto(str, fonte, 20);
texto.setPosition(x, y);
janela.draw(texto);
}
示例7: update
void update(sf::Time timeChange)
{
sf::Vector2f p1Movement(0, 0);
sf::Vector2f p2Movement(0, 0);
if (p1MovingUp)
p1Movement.y -= paddleSpeed;
if (p1MovingDown)
p1Movement.y += paddleSpeed;
if (p2MovingUp)
p2Movement.y -= paddleSpeed;
if (p2MovingDown)
p2Movement.y += paddleSpeed;
p1Paddle.move(p1Movement * timeChange.asSeconds());
p2Paddle.move(p2Movement * timeChange.asSeconds());
// Check collision
if (ball.getPosition().y < 0 || ball.getPosition().y > 480){
ballMovement.y *= -1;
}
if (ball.getGlobalBounds().intersects(p1Paddle.getGlobalBounds()) || ball.getGlobalBounds().intersects(p2Paddle.getGlobalBounds())){
ballMovement.x *= -1;
}
// Scoring
if (ball.getPosition().x > 600){
// P1 scores
ball.setPosition(300, 240);
p1Score++;
p1ScoreText.setString(std::to_string(p1Score));
}
else if (ball.getPosition().x < 0){
// P2 scores
ball.setPosition(300, 240);
p2Score++;
p2ScoreText.setString(std::to_string(p2Score));
}
ball.move(ballMovement * timeChange.asSeconds());
}
示例8: update
void update(EntityFixture &fixture, const sf::Time &delta) {
playerUpdater->update(delta);
velocitiesUpdater->update(delta);
walker->update(delta);
poseUpdater->update(delta);
xformHistorian->update(delta);
dot.setPosition(fixture.GetInput().getCursorPosition());
}
示例9: update
void ColorPalette::update(const sf::Time& dt) {
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
double x = Settings::mouse_position.x;
double y = Settings::mouse_position.y;
if((angular[0]*x+linear[0]-y)<=0 &&
(angular[1]*x+linear[1]-y)>=0 &&
(angular[2]*x+linear[2]-y)<=0) {
rgb_c.setPosition(x, y);
identify(rgb, x, y);
refresh();
} else if((angular[3]*x+linear[3]-y)<=0 &&
(angular[4]*x+linear[4]-y)>=0 &&
(angular[5]*x+linear[5]-y)>=0) {
bw_c.setPosition(x, y);
}
}
}
示例10:
Stone (float x, float y, float a, float b)
{
velocity.x = x;
velocity.y = y;
s.setRadius(radius);
s.setOrigin(radius,radius);
s.setFillColor(sf::Color::Black);
s.setPosition(a,b);
}
示例11: set_circle
void set_circle(sf::CircleShape& circle, const float value, const float norm_radius,
const sf::Vector2f& position, const sf::Color& color)
{
const float radius{sqrt_value_tot_radius(value, norm_radius)};
circle.setRadius(radius);
circle.setOrigin(radius, radius);
circle.setPosition(position);
circle.setFillColor(color);
}
示例12: plot
void ColorPalette::plot(const sf::VertexArray& shape) {
double l = ColorPalette::dist(shape[0].position.x, shape[0].position.y,
shape[1].position.x, shape[1].position.y);
double da = l*(color.r)/255;
double db = l*(color.g)/255;
double x = (linear[1]-linear[2]+da-db)/(angular[2]-angular[1]);
double y = angular[1]*x+linear[1]+da;
rgb_c.setPosition(x, y);
}
示例13: Ball
// Costruttore: prende come parametri la posizione iniziale
// della pallina, sotto forma di due `float`.
Ball(float mX, float mY)
{
// SFML usa un sistema di coordinate avente l'origine
// posizionata nell'angolo in alto a sinistra della
// finestra.
// {Info: coordinate system}
shape.setPosition(mX, mY);
shape.setRadius(defRadius);
shape.setFillColor(defColor);
shape.setOrigin(defRadius, defRadius);
}
示例14: drawParticles
void drawParticles(sf::RenderWindow &window, sf::CircleShape &particle_shape, b2ParticleSystem *particle_system)
{
for(int i = 0; i < particle_system->GetParticleCount(); i++) //loops through all the particles
{
b2Vec2 pos = particle_system->GetPositionBuffer()[i]; //gets the position of the current particle
if( &pos != NULL ) //if the particle exists
{
particle_shape.setPosition( pos.x, pos.y );
window.draw( particle_shape );
}
}
}
示例15: cambiar_posicion_objectos
void Game::cambiar_posicion_objectos(){
int x_player;
int y_player;
int x_obj;
int y_obj;
while(true){
x_player = rand() % 14;
y_player = rand() % 10;
x_obj = rand() % 14;
y_obj = rand() % 10;
if(Game::tabla_de_movimientos[y_obj][x_obj] == true & Game::tabla_de_movimientos[y_player][x_player] == true){
break;
}
}
mPlayerObj.setPosition(x_obj * 50, y_obj * 50);
mPlayer.setPosition(x_player * 50, y_player * 50);
}