本文整理汇总了C++中sf::Texture类的典型用法代码示例。如果您正苦于以下问题:C++ Texture类的具体用法?C++ Texture怎么用?C++ Texture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Texture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
void AnimatedSphere::create(sf::Texture& tex, float radius, const sf::Time& time)
{
circle.setTexture(&tex);
tex.setRepeated(true);
if(radius < 0)
throw std::logic_error{ "Circle's radius cannot be negative! Radius = " + std::to_string(radius) };
float diam = 2 * radius;
texRect = { 0, 0, (int)diam, (int)diam };
circle.setRadius(radius);
passed = sf::Time::Zero;
animTime = time;
texRect = { 0, 0, 2 * (int)radius, 2 * (int)radius };
circle.setTextureRect(texRect);
}
示例2: LoadContent
void Animation::LoadContent(std::string text, sf::Texture image, sf::Vector2f position) {
this->preText = text;
this->image = image;
this->position = position;
alpha = 1.0f;
textColor = sf::Color(114, 77, 255);
if(image.getSize().y > 0) {
sprite.setTexture(image);
}
this->text.setString(text);
active = false;
}
示例3: subrect
Button::Button(const sf::Font& font, const sf::Texture& texture)
: m_texture (texture),
m_text ("", font, 30u),
m_toggleButton (false)
{
sf::IntRect subrect({ 0, 0 }, sf::Vector2i(texture.getSize()));
subrect.height /= State::Count;
for (auto i = 0; i < State::Count; ++i)
{
m_subRects.push_back(subrect);
subrect.top += subrect.height;
}
m_sprite.setTexture(m_texture);
m_sprite.setTextureRect(m_subRects[State::Normal]);
auto bounds = m_sprite.getLocalBounds();
m_text.setPosition(bounds.width / 2.f, bounds.height / 2.f);
}
示例4:
Background(sf::RenderWindow &window) {
background.loadFromFile("res/fondo1_baja.jpg");
sprite.setTexture(background);
width = 1;
height = 1;
actualAnimation = 0;
timeBetweenAnimations = 1;
timeSinceLastAnimation = 0.0;
animationWidth = sprite.getGlobalBounds().width/width;
animationHeight = sprite.getGlobalBounds().height/height;
if(window.getSize().y/animationHeight < window.getSize().x/animationWidth)
sprite.scale(2*window.getSize().y/animationHeight,2*window.getSize().y/animationHeight);
else
sprite.scale(2*window.getSize().x/animationWidth,2*window.getSize().x/animationWidth);
//sprite.setOrigin(sf::Vector2f(animationWidth/2, animationHeight/2));
sprite.setPosition(window.getSize().x/2, window.getSize().y/2.0);
}
示例5: setSimpleReels
void Animation::setSimpleReels(const sf::Texture& Spritesheet, int framex, int framey, int framespersec, int spool)
{
frame.setTexture(Spritesheet);
int i;
sheetSize = Spritesheet.getSize();
numberOfFrames = framex;
numberOfTapes = framey;
xsize = sheetSize.x/framex;
ysize = sheetSize.y/framey;
for(i=0; i<framex; i++)
{
addReel(i*xsize,0,xsize,ysize,framey,boost::lexical_cast<string>(i));
}
activeReel = 0;
if(ysize < ((float)sheetSize.y/framey)) {buffer = 1;}
fps = framespersec;
if(fps>=1)
{
spf = 1.0/fps;
}
else
{
spf = 0;
}
runtime = ( (float) framey)/framespersec;
current_spool = framex;
current_frame = framey;
framebox = reels[activeReel].getRect();
frame.setTextureRect(framebox);
frame.setOrigin(0.5*xsize,0.5*ysize);
return;
}
示例6: LoadContent
void Animation::LoadContent(sf::String string, sf::Texture &texture, sf::Vector2f position)
{
if(!font.loadFromFile("../Fonts/Dead Kansas.ttf"))
{
// error...
}
text.setFont(font);
this->text = text;
this->string = string;
this->texture = texture;
this->position = position;
alpha = 1.0f;
textColour = sf::Color(114, 66, 161);
if(texture.getSize().y > 0);
{
sprite.setTexture(this->texture);
}
this->text = text;
this->string = string;
active = false;
}
示例7: loadFromFile
bool TextureHandler::loadFromFile(const typeAssetID assetID, sf::Texture& asset)
{
// Start with a return result of false
bool succLoad = false;
// Retrieve the filename for this asset
std::string filename = assetID;
// Was a valid filename found? then attempt to load the asset from anFilename
if(filename.length() > 0)
{
// Load the asset from a file
succLoad = asset.loadFromFile(filename);
}
else
{
ELOG() << "TextureHandler::LoadFromFile(" << assetID
<< ") No filename provided!" << std::endl;
}
// Return anResult of true if successful, false otherwise
return succLoad;
}
示例8: main
int main()
{
//check if top and bottom flipped
sf::RenderWindow window = sf::RenderWindow(sf::VideoMode(640, 640, 32), "Perlin Noise", sf::Style::Titlebar | sf::Style::Close);
sf::RenderTexture renderTexture;
glewExperimental = GL_TRUE;
glewInit();
srand(time(NULL));
texture.create(640,640);
const float PERSISTENCE = .5;
float i = 0;
int count = 0;
for( i = 2; i < 129; i /= PERSISTENCE){
std::cout << i;
sf::Vector2f** gradients;
gradients = new sf::Vector2f* [1 + (int)i];
for(int j = 0; j < (int)i + 1; j++){
gradients[j] = new sf::Vector2f[(int)i + 1];
}
genRandom(gradients, i, 1 / i);
drawNoise(window, gradients, i, 1 / i);
for(int j = 0; j < (int)i + 1; j++){
delete[] gradients[j];
}
delete[] gradients;
//std::cin.get();
}
display(window);
std::cout << "draw";
window.display();
std::cin.get();
return 0;
}
示例9: texSize
Selector::Selector(const sf::Texture& t)
: m_texture (t),
m_currentIndex (0),
m_target (0.f)
{
sf::Vector2f texSize(t.getSize());
m_topButton.width = texSize.x / 2.f;
m_topButton.height = texSize.y / 3.f;
m_bottomButton = m_topButton;
m_bottomButton.top = m_bottomButton.height * 2.f;
m_vertices[0].texCoords.x = m_topButton.width;
m_vertices[0].position.y = m_topButton.height;
m_vertices[1].texCoords.x = texSize.x;
m_vertices[1].position = { m_topButton.width, m_topButton.height };
m_vertices[2].texCoords = { texSize.x, m_topButton.height };
m_vertices[2].position = { m_topButton.width, m_topButton.height * 2.f };
m_vertices[3].texCoords = { m_topButton.width, m_topButton.height };
m_vertices[3].position.y = m_topButton.height * 2.f;
m_vertices[5].texCoords.x = m_topButton.width;
m_vertices[5].position.x = m_topButton.width;
m_vertices[6].texCoords = { m_topButton.width, texSize.y };
m_vertices[6].position = m_vertices[6].texCoords;
m_vertices[7].texCoords.y = texSize.y;
m_vertices[7].position.y = texSize.y;
m_localBounds.width = m_topButton.width;
m_localBounds.height = texSize.y;
}
示例10: int
//int row the row of the tilesheet sprite sprite
//int col the col of the tilesheet for sprite
Entity::Entity(sf::Texture& texture, Level* level, int row, int col) {
source.x = 0;
source.y = 0;
kills = 0;
log_message = new sf::Text();
sprite.setTexture(texture);
this->current_level = level;
list = NULL;
m_Font = NULL; // Clear cFont pointer
m_MIL = NULL; // Clear MIL pointer
m_MSL = NULL; // Clear MSL pointer
int single_sprite_width = int(texture.getSize().x / NUM_SPRITES_IN_ROW); //TODO Assumming there are 4 frames
int single_sprite_height = int(sprite.getGlobalBounds().height / NUM_SPRITES_IN_COL);
sprite.setTextureRect(sf::Rect<int>(0, 0, single_sprite_width, single_sprite_height));
//m_thisParent = NULL; // Clear this list
//m_Numthiss = 0;
//m_definitioninitionFile[0] = 0; // Clear definition filename
//m_NumMeshes = 0; // Clear mesh data
//m_Meshes = NULL;
//m_TexturePath[0] = 0;
//m_NumAnimations = 0; // Clear animation data
//m_Animations = NULL;
//m_SpellController = NULL; // Clear spell controller
selectSpriteSet(row, col);
setMessageTimer(1000);
}
示例11:
int log_setup_1(){
//Load Font
if( PTSANS_loaded == false ){
if (!PTSANS.loadFromFile("PTN57F.ttf")) return -1;
PTSANS_loaded = true;
}
texture_3.loadFromFile( "Temp_log.png" );
//Setup Strings
log_string.setFont( PTSANS );
log_string.setCharacterSize(24);
log_string.setColor( sf::Color(255, 255, 255) );
log_string.setPosition(90.f, 600.f);
log_name.setFont( PTSANS );
log_name.setCharacterSize(40);
log_name.setColor( sf::Color(255, 255, 255) );
log_name.setPosition(90.f, 535.f);
log_back.setTexture( texture_3, false );
log_back.setPosition( 0.f, 580.f );
}
示例12: createRobotArm
void Actor::createRobotArm(sf::RenderWindow &window, b2World *world, b2FixtureDef &fixture, sf::Texture &texture, sf::Texture &robot_body_texture, int current_index, int body_type, int shape_type)
{
this->robot_arm = new Object( window, world, fixture, texture, current_index, body_type, shape_type );
this->robot_arm->getSprite()->setOrigin( texture.getSize().x / 2.0, 0 );
sf::Vector2f arm_position;
arm_position.x = this->robot_body->getSprite()->getPosition().x;
arm_position.y = this->robot_body->getSprite()->getPosition().y;
this->robot_arm->getSprite()->setPosition( arm_position );
/*
//arm to body joint
b2RevoluteJointDef revolute_joint_def;
revolute_joint_def.bodyA = this->robot_arm->getBody();
revolute_joint_def.localAnchorA.Set( 0, 1.0 ); //top middle
revolute_joint_def.bodyB = this->robot_body->getBody();
revolute_joint_def.localAnchorB.Set( 0.05, 0.6 ); //upper middle of body
revolute_joint_def.collideConnected = false;
world->CreateJoint( &revolute_joint_def );
*/
}
示例13:
JointPlatform::JointPlatform(sf::Texture& texture, sf::Texture& jointTexture, float initX, float initY, float rotation)
{
_sprite.setTexture( texture );
_sprite.setOrigin( texture.getSize().x / 2.f, texture.getSize().y / 2.f);
_sprite.setRotation( rotation );
_bodyDef.position.Set( MathHelper::ToUnit( initX ), MathHelper::ToUnit( initY ) );
_bodyDef.angle = MathHelper::DegreeToRadian( rotation );
_bodyDef.type = b2_dynamicBody;
_bodyShape.SetAsBox(
MathHelper::ToUnit( texture.getSize().x / 2.f ),
MathHelper::ToUnit( texture.getSize().y / 2.f )
);
cout << "(" << _bodyDef.position.x << "," << _bodyDef.position.y << ")" << endl;
_fixtureDef.shape = &_bodyShape;
_fixtureDef.density = 10.f;
_fixtureDef.friction = 0.5f;
_fixtureDef.restitution = 0.5f;
//texture for the acnhor or joint
_jointBodySprite.setTexture( jointTexture );
_jointBodySprite.setOrigin( jointTexture.getSize().x / 2.f, jointTexture.getSize().y / 2.f);
_jointBodySprite.setRotation( 0.0f );
//setup joint body
_jointBodyDef.type = b2_staticBody;
_jointBodyDef.position.Set( MathHelper::ToUnit( initX ), MathHelper::ToUnit( initY ) );
_jointBodyShape.m_radius = MathHelper::ToUnit( jointTexture.getSize().x / 2.f );
_jointFixtureDef.density = 1.f;
_jointFixtureDef.shape = &_jointBodyShape;
//set up joint
_jointDef.enableMotor = true;
_jointDef.maxMotorTorque = 15;
_jointDef.motorSpeed = MathHelper::DegreeToRadian( 360 );
_jointDef.collideConnected = false;
}
示例14:
gun::Sprite::Sprite(const sf::Texture& texture)
: sprite_(sf::Sprite(texture)), draw_order_(0), is_visible_(true)
{
sprite_.setOrigin((float)(texture.getSize().x / 2), (float)(texture.getSize().y / 2));
}
示例15: H_VECTOR2F
sf::Vector2f Fonction::centerCorner(const sf::Texture& texture) { return H_VECTOR2F(texture.getSize()); }