本文整理汇总了C++中sf::RectangleShape::setFillColor方法的典型用法代码示例。如果您正苦于以下问题:C++ RectangleShape::setFillColor方法的具体用法?C++ RectangleShape::setFillColor怎么用?C++ RectangleShape::setFillColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::RectangleShape
的用法示例。
在下文中一共展示了RectangleShape::setFillColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: crossfade
bool Tutorial::crossfade(float elapsedTime, sf::RectangleShape& rect1, sf::RectangleShape& rect2)
{
float temp = alpha1 - elapsedTime * ANIMATION_SPEED;
float temp2 = alpha2 + elapsedTime * ANIMATION_SPEED;
// std::cout << "color " << static_cast<int>(temp) << std::endl;
// std::cout << "color2 " << static_cast<int>(temp2) << std::endl;
// ensure high calc times don't screw up the outcome (drag the window for a sec outputs a too high value)
// maybe just limit it would be better..
if (temp < alpha1)
{
alpha1 = temp;
alpha2 = temp2;
}
if (alpha1 < 1)
{
alpha1 = 0;
alpha2 = 255;
rect1.setFillColor(sf::Color(255, 255, 255, static_cast<sf::Uint8>(alpha1)));
return true;
}
// disabled because it should not be crossfaded only overlayed
//rect1.setFillColor(sf::Color(255, 255, 255, static_cast<sf::Uint8>(alpha1)));
rect2.setFillColor(sf::Color(255, 255, 255, static_cast<sf::Uint8>(alpha2)));
return false;
}
示例2: init
void init() {
this->restart();
// RectangleShapes
sf::Vector2f unit(unit_w, unit_h);
stone_view = sf::RectangleShape(unit);
stone_view.setFillColor(sf::Color(255, 81, 68));
body_view = sf::RectangleShape(unit);
body_view.setFillColor(sf::Color(0, 204, 255));
food_view = sf::RectangleShape(unit);
food_view.setFillColor(sf::Color(19, 169, 136));
// font & msg
if (!font.loadFromFile("Inconsolata-Bold.ttf")) {
puts("fonts loading error!");
this->close();
}
msg1.setFont(font);
msg1.setColor(sf::Color::White);
msg1.setCharacterSize(50);
msg1.setPosition(80, 100);
msg2.setFont(font);
msg2.setColor(sf::Color::White);
msg2.setCharacterSize(25);
msg2.setString("Press <Enter> to Replay");
msg2.setPosition(60, 250);
}
示例3: 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);
}
示例4: init
void WindowCreateThing::init(sf::RenderWindow &window) {
rectTitle.setSize(sf::Vector2f(window.getSize().x*0.45, window.getSize().y*0.07));
rectTitle.setPosition(sf::Vector2f(window.getSize().x/2-(rectTitle.getSize().x/2), window.getSize().x/4-(rectTitle.getSize().y/2)));
rectTitle.setFillColor(sf::Color(158, 158, 158));
rectTitle.setOutlineColor(sf::Color::Black);
rectTitle.setOutlineThickness(1.f);
rectMain.setSize(sf::Vector2f(window.getSize().x*0.45,window.getSize().y*0.45));
rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y));
rectMain.setFillColor(sf::Color::White);
rectMain.setOutlineColor(sf::Color::Black);
rectMain.setOutlineThickness(1.f);
load();
starting_position = sf::Mouse::getPosition(window);
textTitle.setFont(font);
textTitle.setString("CreateThings.txt");
textTitle.setCharacterSize(24);
textTitle.setColor(sf::Color::White);
textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1));
//textTitle.setPosition(sf::Vector2f(400,10));
textClose.setFont(font);
textClose.setString("X");
textClose.setStyle(sf::Text::Bold);
textClose.setCharacterSize(35);
textClose.setColor(sf::Color::White);
textClose.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x-30, rectTitle.getPosition().y+rectTitle.getSize().y*0.05));
///// FOLDER ICONE
textureFolder.setSmooth(true);
spriteFodler.setTexture(textureFolder);
sf::Vector2f targetSize(25.0f, 25.0f);
spriteFodler.setScale(
targetSize.x / spriteFodler.getLocalBounds().width,
targetSize.y / spriteFodler.getLocalBounds().height);
spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-targetSize.x, textTitle.getPosition().y));
///// CLOSE ICONE
/*textureClose.setSmooth(true);
spriteClose.setTexture(textureClose);
sf::Vector2f targetSize2(window.getSize().y*0.07, window.getSize().y*0.07);
spriteClose.setScale(
targetSize2.x / spriteClose.getLocalBounds().width,
targetSize2.y / spriteClose.getLocalBounds().height);
spriteClose.setPosition(rectTitle.getPosition().x+rectTitle.getSize().x-targetSize2.x, rectTitle.getPosition().y);*/
}
示例5: paintLighting
void cWindow::paintLighting()
{
float power;
int tex;
int lightsDisplayed = 0;
int priority = 0;
for (int a = 0; a < 2; a++)
{
priority = 0;
while (priority < LIMIT_PRIORITY_LIGHT && lightsDisplayed < game.unitCounter)
{
for (int i = 0; i < game.unitCounter; i++)
{
if (game.unit[i].light.priority == priority && game.unit[i].light.power > 0 && game.unit[i].light.texture != -1)
{
tex = game.unit[i].light.texture;
brushRect.setTexture(&visual.gameTex[tex].handle);
brushRect.setPosition(game.unit[i].pos);
brushRect.setFillColor(sf::Color(255, 255, 255, max(0.00f, min(255.00f, 300.00f - game.ambientLight))));
if (!settings.enableDynamicLight) {
brushRect.setTexture(&visual.gameTex[visual.addTexture("light_white.png")].handle);
brushRect.setFillColor(sf::Color(255, 255, 255, 50.00f));
}
brushRect.setTextureRect(sf::IntRect(0, 0, visual.gameTex[tex].handle.getSize().x, visual.gameTex[tex].handle.getSize().y));
power = game.unit[i].light.power;
if (game.unit[i].light.flickerMod != 0.00f) {
power += power * (game.unit[i].light.flickerMod * abs(game.unit[i].light.flickerCurTime / game.unit[i].light.flickerTime - 1.00f));
power += math.randf(-5.00f, 5.00f);
}
brushRect.setOrigin(sf::Vector2f(power, power));
brushRect.setSize(sf::Vector2f(power * 2.00f, power * 2.00f));
// Directional
brushRect.setRotation(0.00f);
if (game.unit[i].light.directional) {
brushRect.setRotation(-game.unit[i].facingAngle);
}
// Painting to two textures
if (settings.enableDynamicLight && a == 0) { window.texHandleLight.draw(brushRect, window.matrixHandle); }
else if (settings.enableDynamicLight && a == 1) { window.texHandleLightMult.draw(brushRect, window.matrixHandle); }
else { window.texHandle.draw(brushRect, window.matrixHandle); }
}
}
priority += 1;
}
if (!math.intToBool(settings.enableBetterLight)) { break; }
}
brushRect.setRotation(0.00f);
window.texHandleLight.display();
if (settings.enableBetterLight) { window.texHandleLightMult.display(); }
}
示例6: draw
void Sprited::draw(sf::RenderWindow *window)
{
// Scroll sprite
sf::Vector2i shift = this->currentAnimation->frames[this->currentFrame];
this->sprite.setTextureRect(sf::IntRect(shift.x, shift.y, this->width, this->height));
this->sprite.setRotation((this->getWRotation() - this->camera->getWRotation()) / (2 * M_PI) * 360); // + this->wRotation / (2 * M_PI) * 360);
if (this->camera) {
// Transform sprite wPosition based on camera wPosition & wRotation
this->sprite.setPosition(this->applyCameraTransformation(this->getWPosition()));
} else {
// No camera set, meaning this object's wPosition is not affected by camera.
this->sprite.setPosition(this->getWPosition().x, this->getWPosition().y);
}
window->draw(this->sprite);
Movable::draw(window);
#ifdef DEBUG
static sf::RectangleShape origin;
origin.setOrigin(2, 2);
origin.setSize(sf::Vector2f(5, 5));
origin.setPosition(this->sprite.getPosition());
origin.setFillColor(sf::Color(255, 0, 0, 128));
window->draw(origin);
static sf::RectangleShape rect;
rect.setFillColor(sf::Color::Transparent);
rect.setOutlineThickness(1);
rect.setOutlineColor(sf::Color::Blue);
rect.setOrigin(this->sprite.getOrigin());
rect.setPosition(this->sprite.getPosition());
rect.setRotation(this->sprite.getRotation());
rect.setSize(sf::Vector2f(this->sprite.getTextureRect().width, this->sprite.getTextureRect().height));
window->draw(rect);
sf::FloatRect wHitbox = this->getWHitbox();
static sf::RectangleShape hitboxRect;
hitboxRect.setFillColor(sf::Color::Transparent);
hitboxRect.setOutlineThickness(1);
hitboxRect.setOutlineColor(sf::Color::Red);
hitboxRect.setOrigin(sf::Vector2f(wHitbox.width / 2, wHitbox.height / 2));
hitboxRect.setSize(sf::Vector2f(wHitbox.width, wHitbox.height));
hitboxRect.setPosition(this->applyCameraTransformation(this->getWPosition()));
hitboxRect.setRotation(-this->camera->getWRotation() / M_PI * 180);
window->draw(hitboxRect);
#endif
}
示例7: doMouseMove
void doMouseMove(){
if (rect1.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) rect1.setFillColor(sf::Color(100,100,100));
} else {
rect1.setFillColor(sf::Color(200,200,200));
}
if (rect2.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) rect2.setFillColor(sf::Color(100,100,100));
} else {
rect2.setFillColor(sf::Color(200,200,200));
}
if (rect3.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) rect3.setFillColor(sf::Color(100,100,100));
} else {
rect3.setFillColor(sf::Color(200,200,200));
}
if (rect4.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) rect4.setFillColor(sf::Color(100,100,100));
} else {
rect4.setFillColor(sf::Color(200,200,200));
}
}
示例8: el
el(sf::Vector2f p)
{
r.setSize(sf::Vector2f(50,50));
r.setFillColor(sf::Color(2,136,209));
pos = p;
r.setPosition(pos);
}
示例9: obstacle
obstacle(sf::Vector2f p)
{
pos = p;
r.setPosition(p);
r.setSize(sf::Vector2f(50,50));
r.setFillColor(sf::Color(255, 205, 210));
}
示例10: Render
void Snake::Render(sf::RenderWindow& window) {
if (_body.empty()) { return; }
// Draw head
auto head = _body.begin();
_bodyRect.setFillColor(sf::Color::Yellow);
_bodyRect.setPosition(head->position.x * _size, head->position.y * _size);
window.draw(_bodyRect);
// Draw body
_bodyRect.setFillColor(sf::Color::Green);
for (auto itr = _body.begin() + 1; itr != _body.end(); ++itr) {
_bodyRect.setPosition(itr->position.x * _size, itr->position.y * _size);
window.draw(_bodyRect);
}
}
示例11: setUpBall
void PongGame::setUpBall(int const mainWindowWidth, int const mainWindowHeight, sf::RectangleShape &ball) {
ball.setPosition(mainWindowWidth / 2, mainWindowHeight / 2);
ball.setSize(sf::Vector2f(20, 20));
ball.setFillColor(sf::Color::Red);
ball.setOutlineColor(sf::Color::Yellow);
ball.setOutlineThickness(2);
}
示例12:
Player(sf::Vector2f position, sf::Vector2f size)
{
once = true;
rect.setPosition(position);
rect.setSize(size);
rect.setFillColor(sf::Color::Green);
}
示例13: IsSelected
void IsSelected(Selection s, sf::RenderWindow &Window)
{
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
if(rect.getGlobalBounds().intersects(s.rect.getGlobalBounds()) || (sf::Mouse::getPosition(Window).x > rect.getPosition().x && sf::Mouse::getPosition(Window).x < rect.getPosition().x + rect.getSize().x && sf::Mouse::getPosition(Window).y > rect.getPosition().y && sf::Mouse::getPosition(Window).y < rect.getPosition().y + rect.getSize().y))
{
selected = true;
rect.setFillColor(sf::Color::Magenta);
}
else
{
selected = false;
rect.setFillColor(sf::Color::Green);
}
}
}
示例14: Board
Board(int n, sf::Vector2f pos){
boardSprite.setSize(sf::Vector2f(n, 2));
boardSprite.setFillColor(sf::Color::Blue);
boardSprite.setPosition(pos);
}
示例15: Paddle
// As with the ball, we construct the paddle with
// arguments for the initial position and initialize
// the SFML rectangle shape.
Paddle(float mX, float mY)
{
shape.setPosition(mX, mY);
shape.setSize({defWidth, defHeight});
shape.setFillColor(defColor);
shape.setOrigin(defWidth / 2.f, defHeight / 2.f);
}