• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sf::Texture类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中sf::Texture的典型用法代码示例。如果您正苦于以下问题:C++ Texture类的具体用法?C++ Texture怎么用?C++ Texture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Texture类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:GuildMasterInfinite,项目名称:SpaceExplorer,代码行数:19,代码来源:AnimatedSphere.cpp


示例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;

}
开发者ID:olijf,项目名称:Gerald-BeyondEvil,代码行数:19,代码来源:Animation.cpp


示例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);
}
开发者ID:MORTAL2000,项目名称:xygine,代码行数:20,代码来源:UIButton.cpp


示例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);

}
开发者ID:kaitokidi,项目名称:androidSpaceTongue,代码行数:21,代码来源:Background.hpp


示例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;
}
开发者ID:The-Cunning-Folk,项目名称:barbarian-quest,代码行数:38,代码来源:animation.cpp


示例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;
}
开发者ID:Mman13,项目名称:CourseWork,代码行数:23,代码来源:Animation.cpp


示例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;
	}
开发者ID:Ostkaka,项目名称:MGE,代码行数:23,代码来源:TextureHandler.cpp


示例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;
}
开发者ID:15kingben,项目名称:ChallengeProject,代码行数:37,代码来源:FractalPerlinNoise.cpp


示例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;
}
开发者ID:fallahn,项目名称:xyRacer,代码行数:37,代码来源:MGSelector.cpp


示例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);

}
开发者ID:anthonybjturner,项目名称:YasuosQuests,代码行数:39,代码来源:Entity.cpp


示例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 );

	}
开发者ID:rmxhaha,项目名称:phantasia,代码行数:24,代码来源:VN_1.0.cpp


示例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 );
	*/
}
开发者ID:niems,项目名称:Multiplayer-Shooter,代码行数:24,代码来源:Actor.cpp


示例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;
}
开发者ID:Wajiimalik,项目名称:GamePlayground,代码行数:42,代码来源:JointPlatform.cpp


示例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));
}
开发者ID:dsc5085,项目名称:Gunfire,代码行数:5,代码来源:Sprite.cpp


示例15: H_VECTOR2F

sf::Vector2f Fonction::centerCorner(const sf::Texture& texture)		{ return H_VECTOR2F(texture.getSize()); }
开发者ID:FlorianPO,项目名称:SpriteEditor,代码行数:1,代码来源:FonctionPosition.cpp


示例16:

sf::Vector2f Fonction::bottomLeftCorner(const sf::Texture& texture)		{ return sf::Vector2f(0, texture.getSize().y); }
开发者ID:FlorianPO,项目名称:SpriteEditor,代码行数:1,代码来源:FonctionPosition.cpp


示例17: VECTOR2F

sf::Vector2f Fonction::bottomRightCorner(const sf::Texture& texture)	{ return VECTOR2F(texture.getSize()); }
开发者ID:FlorianPO,项目名称:SpriteEditor,代码行数:1,代码来源:FonctionPosition.cpp


示例18: makeGuardAnimation

std::map<std::string, sf::IntRect> makeGuardAnimation(Video::Render::Animation &animation) {
    static sf::Texture texture;
    if(!texture.loadFromFile("assets/dummy_guard_spritesheet.png")) {
        throw std::runtime_error("Error loading guard animation texture");
    }

    Video::Render::AnimatedSprite idleSequence(texture);
    Video::Render::AnimatedSprite fallSequence(texture);
    Video::Render::AnimatedSprite slashSequence(texture);
    Video::Render::AnimatedSprite runSequence(texture);
    Video::Render::AnimatedSprite hurtSequence(texture);
    Video::Render::AnimatedSprite jumpSequence(texture);
    
    Video::Render::Sprite::Frame frameBuffer[15];

    std::map<std::string, sf::IntRect> seq_solids;
    
    //idle
    frameBuffer[0].setTextureSegment(sf::IntRect(9, 8, 67, 92));
    frameBuffer[1].setTextureSegment(sf::IntRect(89, 8, 67, 92));
    frameBuffer[2].setTextureSegment(sf::IntRect(169, 8, 67, 92));
    frameBuffer[3].setTextureSegment(sf::IntRect(249, 8, 67, 92));
    frameBuffer[4].setTextureSegment(sf::IntRect(329, 8, 67, 92));
    seq_solids.insert(std::pair<std::string, sf::IntRect>("idle", sf::IntRect(12, 10, 40, 82)));
    
    //fall
    frameBuffer[5].setTextureSegment(sf::IntRect(17, 133, 64, 90));
    seq_solids.insert(std::pair<std::string, sf::IntRect>("fall", sf::IntRect(2, 10, 40, 78)));
    
    //slash
    frameBuffer[6].setTextureSegment(sf::IntRect(123, 135, 100, 92));
    frameBuffer[7].setTextureSegment(sf::IntRect(220, 135, 100, 92));
    seq_solids.insert(std::pair<std::string, sf::IntRect>("slash", sf::IntRect(25, 12, 40, 79)));
    
    //run
    frameBuffer[8].setTextureSegment(sf::IntRect(132, 271, 75, 92));
    frameBuffer[9].setTextureSegment(sf::IntRect(216, 271, 75, 92));
    frameBuffer[10].setTextureSegment(sf::IntRect(292, 271, 75, 92));
    frameBuffer[11].setTextureSegment(sf::IntRect(372, 271, 75, 92));
    seq_solids.insert(std::pair<std::string, sf::IntRect>("run", sf::IntRect(20, 10, 40, 82)));
    
    //hurt
    frameBuffer[12].setTextureSegment(sf::IntRect(8, 281, 68, 89));
    seq_solids.insert(std::pair<std::string, sf::IntRect>("hurt", sf::IntRect(16, 7, 40, 82)));
    
    //jump
    frameBuffer[13].setTextureSegment(sf::IntRect(22, 395, 56, 96));
    frameBuffer[14].setTextureSegment(sf::IntRect(107, 395, 56, 96));
    seq_solids.insert(std::pair<std::string, sf::IntRect>("jump", sf::IntRect(14, 8, 40, 85)));
    
    for(int i = 0; i < 15; ++i) {
        frameBuffer[i].setDuration(sf::seconds(1.0f/15.0f));
    }
    
    int famt[] = {5, 1, 2, 4, 1, 2};
    Video::Render::AnimatedSprite *seq[] = {&idleSequence, &fallSequence, &slashSequence,
        &runSequence, &hurtSequence, &jumpSequence};
        
    for(int i = 0, j = 0; i < 6; ++i) {
        for(int k = 0; k < famt[i]; ++k) {
            seq[i]->insertFrame(frameBuffer[j]);
            j += 1;
        }
    }
    
    animation.addSequence("idle", idleSequence, true);
    animation.addSequence("fall", fallSequence, true);
    animation.addSequence("slash", slashSequence, true);
    animation.addSequence("run", runSequence, true);
    animation.addSequence("hurt", hurtSequence, true);
    animation.addSequence("jump", jumpSequence, true);
    
    return seq_solids;
}
开发者ID:michlord,项目名称:team-project-2014,代码行数:74,代码来源:CreateAnimation.cpp


示例19: getFullRect

	sf::IntRect getFullRect(const sf::Texture& texture)
	{
		return sf::IntRect(0, 0, texture.getSize().x, texture.getSize().y);
	}
开发者ID:Shinao,项目名称:JustAGame,代码行数:4,代码来源:ParticleSystem.cpp


示例20: chargerTexture

void chargerTexture(sf::Texture& Texture, std::string filePath)
{
    Texture.setSmooth(false);
    if(!Texture.loadFromFile(filePath))
        std::cerr << "Erreur durant chargement de la texture " << filePath << std::endl;
}
开发者ID:RedDragons,项目名称:v0.1,代码行数:6,代码来源:chargement.cpp



注:本文中的sf::Texture类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sf::Time类代码示例发布时间:2022-05-31
下一篇:
C++ sf::Text类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap