本文整理汇总了C++中sf::Sprite::setColor方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::setColor方法的具体用法?C++ Sprite::setColor怎么用?C++ Sprite::setColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::setColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_color
void set_color()
{
int opaque{abs(static_cast<int>(m_strength*255.0f))};
if (opaque > 255)
{
opaque = 255;
}
if (m_strength < 0.0f)
{
sf::Color light_red{m_light_red};
light_red.a = opaque;
m_sprite.setColor(light_red);
}
else
{
sf::Color light_blue{m_light_blue};
light_blue.a = opaque;
m_sprite.setColor(light_blue);
}
}
示例2: manageHit
void cursor::manageHit()
{
if(hit)
{
hitSprite.setColor(sf::Color(255, 255, 255, 255));
hit = false;
}
else if(hitSprite.getColor().a > 0)
{
int currentAlpha = hitSprite.getColor().a;
a += timeModifier;
while(a > 1)
{
currentAlpha -= 15;
a -= 15;
}
if(a < 0)
a = 0;
if(currentAlpha < 0)
currentAlpha = 0;
hitSprite.setColor(sf::Color(255, 255, 255, currentAlpha));
}
hitSprite.setPosition(sprite.getPosition());
hitSprite.setRotation(sprite.getRotation());
}
示例3: buttonHighlightDetect
// Initialising functions
// Detects if a mouse is hovering over a button based on the mouse position, and if it is, tints the button slightly grey.
// If it isn't then the tint is removed.
// This version of the function is for sprites
void cScreen::buttonHighlightDetect(sf::Vector2i &mousePos, sf::Sprite &button) {
// If the mouse's current position is within the bounds of the button
if (button.getGlobalBounds().contains(mousePos.x, mousePos.y)) {
// Set the tint of the button to RGB color 200,200,200
button.setColor(sf::Color(200, 200, 200));
}
// If not set the tint of the button to white
else button.setColor(sf::Color::White);
}
示例4: begin
void begin(sf::Sprite &s, float x, float y)
{
s.setColor(sf::Color(lightMap->valueAt(x, y),lightMap->valueAt(x, y),lightMap->valueAt(x, y),255));
/*;
float dist = sqrtf(powf(std::abs(s.getPosition().x - x), 2) + powf(std::abs(s.getPosition().y - y), 2));
const int maxRadius = 6;
const int lowestLight = 20;
const int gradient = 200/maxRadius;
for (int i = 1; i < maxRadius; i++)
{
int flicker = flickerSeed - TILESIZE*i;
if (dist > i*TILESIZE && dist < (i+2)*TILESIZE)
{
int gray = abs((255-i*gradient)+flicker);
gray = gray < lowestLight ? lowestLight : gray;
s.setColor(sf::Color(gray,gray,gray,255));
}
}
if (dist > maxRadius*TILESIZE)
{
s.setColor(sf::Color(lowestLight,lowestLight,lowestLight,255));
}
*/
}
示例5: setTexture
void cursor::setTexture(string cursorPass)
{
sprite.setTexture(textureManager.get(cursorPass));
sprite.setOrigin((Collision::GetSpriteSize(sprite).x / sprite.getScale().x / 2), (Collision::GetSpriteSize(sprite).y / sprite.getScale().y / 2));
sprite.rotate(-90);
sprite.setColor(sf::Color(255, 255, 255, settings.getCursorAplha()));
}
示例6: update
//Player sprite render.
void update(float deltaTime, char** levelMap, struct config* config) {
//Player controls (testing).
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) mMovement.y -= mSpeed;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) mMovement.y += mSpeed;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) mMovement.x -= mSpeed;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) mMovement.x += mSpeed;
mRect.left += mMovement.x * deltaTime;
collision(0, levelMap, config);
mRect.top += mMovement.y * deltaTime;
collision(1, levelMap, config);
//Player animation.
mCurrentFrame += mAnimationSpeed * deltaTime;
if(mCurrentFrame > mFrameCount) mCurrentFrame -= mFrameCount;
if(mMovement.x > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 925, mRect.width, mRect.height));
if(mMovement.x < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 667, mRect.width, mRect.height));
if(mMovement.y > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 535, mRect.width, mRect.height));
if(mMovement.y < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 787, mRect.width, mRect.height));
mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY);
//HP.
if(mHP / mMaxHp >= 0.6)
mHpSprite.setColor(sf::Color::Green);
else if((mHP / mMaxHp >= 0.35) && (mHP / mMaxHp < 0.6))
mHpSprite.setColor(sf::Color::Yellow);
else if(mHP / mMaxHp < 0.35)
mHpSprite.setColor(sf::Color::Red);
mHpSprite.setTextureRect(sf::IntRect(100 * (1 - mHP / mMaxHp), 0, 100, 10));
mHpSprite.setPosition(mRect.left - offsetX, mRect.top + mRect.height - offsetY);
mTextName.setPosition(mRect.left - offsetX, mRect.top - mTextName.getCharacterSize() - offsetY); //-
//Camera scrolling.
if(mRect.left > config->screenWidth / 2 - mRect.width / 2) offsetX = mRect.left - (config->screenWidth / 2 - mRect.width / 2);
if(mRect.top > config->screenHeight / 2 - mRect.height / 2) offsetY = mRect.top - (config->screenHeight / 2 - mRect.height / 2);
//Stopping the player.
mMovement.x = 0;
mMovement.y = 0;
}
示例7: 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;
}
示例8: setSprite
void AnimatableSprite::setSprite(sf::Sprite sprite)
{
sf::Vector2f center = getCenterPosition();
sf::Vector2f scale = _sprite.getScale();
sf::Color color = _sprite.getColor();
sprite.setScale(scale);
sprite.setColor(color);
_sprite = sprite;
setCenterPosition(center);
}
示例9: LowAmmo
void cursor::LowAmmo(int current, int maximum)
{
lowAmmoSprite.setPosition(sprite.getPosition());
lowAmmoSprite.setRotation(sprite.getRotation());
double ammoLimit = 0.3 * maximum;
double ammoPseudoPercentage = static_cast <float> (current) / ammoLimit;
ammoPseudoPercentage *= 255;
lowAmmoSprite.setColor(sf::Color(255, 255, 255, 255 - ammoPseudoPercentage));
}
示例10: fadeSpriteIn
void SplashScreen::fadeSpriteIn(sf::RenderWindow & renderWindow, sf::Sprite& sprite)
{
if((int)sprite.getColor().a < 255)
{
sf::Color color = sprite.getColor();
color.a++;
sprite.setColor(color);
}else{
fadeIn = false;
}
}
示例11: fadeSpriteOut
void SplashScreen::fadeSpriteOut(sf::RenderWindow & renderWindow, sf::Sprite& sprite)
{
if(sprite.getColor().a > 0)
{
sf::Color color = sprite.getColor();
color.a--;
sprite.setColor(color);
}else{
stopSplash = true;
}
}
示例12: update
void Checkbox::update(Event event)
{
if(!event.type == sf::Event::MouseButtonPressed and !event.type == sf::Event::MouseMoved)
return;
sf::Vector2f mouseCoords = sf::Vector2f(sf::Mouse::getPosition().x * viewScale + screenCornerX, sf::Mouse::getPosition().y * viewScale + screenCornerY);
if(event.type == sf::Event::MouseMoved)
focus = box.getGlobalBounds().contains(mouseCoords);
if(event.type == sf::Event::MouseButtonPressed and focus)
state = !state;
if(state)
check.setColor(sf::Color(255, 255, 255, 255));
else if(focus)
check.setColor(sf::Color(255, 255, 255, 127));
else
check.setColor(sf::Color(255, 255, 255, 0));
}
示例13: transformSprite
void GraphicEngine::transformSprite(sf::Sprite& sprite, const Transformation& t, const Color& color)
{
if (t.hasPosition())
sprite.setPosition((float)t.getX(), (float)t.getY());
if (t.hasRotation())
sprite.rotate(t.getRotation());
if (color.isUsed())
sprite.setColor(sf::Color(color.getColor()));
if (t.hasScale())
sprite.setScale(t.getScaleX(), t.getScaleY());
}
示例14: HighAmmo
void cursor::HighAmmo(int current, int maximum)
{
highAmmoSprite.setPosition(sprite.getPosition());
highAmmoSprite.setRotation(sprite.getRotation());
double pseudoAmmo = current - (0.7 * maximum);
double pseudoAmmoMax = maximum - (0.7 * maximum);
double ammoPseudoPercentage = static_cast <float> (pseudoAmmo) / pseudoAmmoMax;
ammoPseudoPercentage *= 255;
highAmmoSprite.setColor(sf::Color(255, 255, 255, ammoPseudoPercentage));
}
示例15: updateWarp
void Warp::updateWarp(Player* p, sf::Sprite& s){
static int _alpha = 0;
s.setColor(sf::Color(0, 0, 0, 255));
if (!playerWarped){
_alpha = transition.get_ticks() / 10;
s.setColor(sf::Color(0, 0, 0, _alpha));
if (_alpha >= 255){
_alpha = 255;
s.setColor(sf::Color(0, 0, 0, _alpha));
p->setHardPosition(warpToX, warpToY);
playerWarped = true;
transition.stop();
transition.start();
}
}
if (playerWarped){
_alpha = -75 + (transition.get_ticks() / 10);
if (_alpha > 0){
s.setColor(sf::Color(0, 0, 0, 255 - _alpha));
if (255 - _alpha <= 0){
_alpha = 255;
s.setColor(sf::Color(0, 0, 0, 255 - _alpha));
transition.stop();
playerWarped = false;
bIsActive = false;
}
}
}
s.setPosition(p->getX() - SCREEN_WIDTH / 2, p->getY() - SCREEN_HEIGHT / 2);
p->setXVel(0);
p->setYVel(0);
return;
}