当前位置: 首页>>代码示例>>C++>>正文


C++ SpriteSheet类代码示例

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


在下文中一共展示了SpriteSheet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DrawSprite

void DrawSprite ( const std::string& sheetname, int sheet_x, int sheet_y, vec2 position, vec2 size, float rotation, colour col )
{
	SetShader("Sprite");
	EnableTexturing();
	EnableBlending();
	ClearColour();
	SetColour(col);
	SpriteSheet* sheet;
	SheetMap::iterator iter = spriteSheets.find(sheetname);
	if (iter == spriteSheets.end())
	{
		// load it
		sheet = new SpriteSheet(sheetname);
		spriteSheets[sheetname] = sheet;
	}
	else
	{
		sheet = iter->second;
	}
	Matrices::SetViewMatrix(matrix2x3::Translate(position));
	Matrices::SetModelMatrix(matrix2x3::Identity());
	if (sheet->IsRotational())
	{
		assert(sheet_x == 0);
		assert(sheet_y == 0);
		sheet->DrawRotation(size, rotation);
	}
	else
	{
		glRotatef(RAD2DEG(rotation), 0.0f, 0.0f, 1.0f);
		sheet->Draw(sheet_x, sheet_y, size);
	}
}
开发者ID:prophile,项目名称:xsera,代码行数:33,代码来源:Graphics.cpp

示例2: DrawSpriteFrame

void DrawSpriteFrame ( const std::string& sheetname, vec2 position, vec2 size, int index, float rotation, colour col )
{
	SetShader("Sprite");
	EnableTexturing();
	EnableBlending();
	ClearColour();
	SetColour(col);
	SpriteSheet* sheet;
	SheetMap::iterator iter = spriteSheets.find(sheetname);
	if (iter == spriteSheets.end())
	{
		sheet = new SpriteSheet(sheetname);
		spriteSheets[sheetname] = sheet;
	}
	else
	{
		sheet = iter->second;
	}
	Matrices::SetViewMatrix(matrix2x3::Translate(position));
	Matrices::SetModelMatrix(matrix2x3::Identity());
	glRotatef(RAD2DEG(rotation), 0.0f, 0.0f, 1.0f);
	
	int x = index % sheet->SheetTilesX();
	int y = (index - x) / sheet->SheetTilesX();
	sheet->Draw(x, y, size);
}
开发者ID:prophile,项目名称:xsera,代码行数:26,代码来源:Graphics.cpp

示例3:

Sprite::Sprite(SpriteSheet& spriteSheet, std::string spriteKey, float scale) :
	texture_(spriteSheet.texture()),
	source_(spriteSheet.getRegion(spriteKey))
{
	width_ = (int)(source_->w * scale);
	height_ = (int)(source_->h * scale);
}
开发者ID:Natman64,项目名称:Icarus,代码行数:7,代码来源:Sprite.cpp

示例4:

std::vector<Halley::Path> Halley::SpriteSheetImporter::import(const ImportingAsset& asset, Path dstDir, ProgressReporter reporter, AssetCollector collector)
{
	SpriteSheet sheet;
	Path dstFile = asset.inputFiles[0].name.replaceExtension("");
	sheet.loadJson(gsl::as_bytes(gsl::span<const Byte>(asset.inputFiles.at(0).data)));
	FileSystem::writeFile(dstDir / dstFile, Serializer::toBytes(sheet));
	return { dstFile };
}
开发者ID:amzeratul,项目名称:halley,代码行数:8,代码来源:spritesheet_importer.cpp

示例5: SpriteSheet

SpriteSheet* SpriteSheet::CloneTo( std::string Filename )
{
	SpriteSheet* result = new SpriteSheet( Filename );

	for( int i = 0; i < frames.size(); i++ )
	{
		SpriteSheetRegion* r = frames.at( i );
		result->AddSprite( r->X, r->Y, r->Width, r->Height );
	}

	return result;
}
开发者ID:pmprog,项目名称:TugOfWar,代码行数:12,代码来源:spritesheet.cpp

示例6: SpriteSheet

SpriteSheet* RenderManager::createSpriteSheet(
	int _layer, std::wstring _filename, int _width, int _height, int _delay)
{
	SpriteSheet *isheet = new SpriteSheet( _filename, _width, _height, _delay );
	isheet->setLayer(_layer);

	isheet->m_prev = NULL;
	isheet->m_next = m_rendlist;
	if (m_rendlist)
		m_rendlist->m_prev = isheet;
	m_rendlist = isheet;
	return isheet;
}
开发者ID:ChadyG,项目名称:MUGE,代码行数:13,代码来源:RenderManager.cpp

示例7: carregarSpriteSheet

SpriteSheet* GerenciadorDeRecursos::carregarSpriteSheet(const string& nome, const string& caminho, int num_animacoes, int num_max_frames)
{
	SpriteSheet* sheet = new SpriteSheet;
	if(sheet->carregar(caminho, num_animacoes, num_max_frames))
	{
		mSpriteSheets.insert(pair<string, SpriteSheet*>(nome, sheet));
	}
	else
	{
		delete sheet;
		sheet = NULL;
	}

	return sheet;
}
开发者ID:Capiroti,项目名称:Pokemon,代码行数:15,代码来源:GerenciadorDeRecursos.cpp

示例8: shrinkAtlas

std::unique_ptr<Image> SpriteImporter::makeAtlas(const std::vector<BinPackResult>& result, Vector2i origSize, SpriteSheet& spriteSheet)
{
	Vector2i size = shrinkAtlas(result);

	auto image = std::make_unique<Image>(Image::Format::RGBA, size);
	image->clear(0);

	for (auto& packedImg: result) {
		ImageData* img = reinterpret_cast<ImageData*>(packedImg.data);
		image->blitFrom(packedImg.rect.getTopLeft(), *img->img, img->clip, packedImg.rotated);

		const auto borderTL = img->clip.getTopLeft();
		const auto borderBR = img->img->getSize() - img->clip.getSize() - borderTL;

		const auto offset = Vector2f(0.0001f, 0.0001f);

		SpriteSheetEntry entry;
		entry.size = Vector2f(img->clip.getSize());
		entry.rotated = packedImg.rotated;
		entry.pivot = Vector2f(img->pivot - img->clip.getTopLeft()) / entry.size;
		entry.origPivot = img->pivot;
		entry.coords = (Rect4f(Vector2f(packedImg.rect.getTopLeft()) + offset, Vector2f(packedImg.rect.getBottomRight()) + offset)) / Vector2f(size);
		entry.trimBorder = Vector4s(short(borderTL.x), short(borderTL.y), short(borderBR.x), short(borderBR.y));
		entry.slices = img->slices;

		for (auto& filename: img->filenames) {
			spriteSheet.addSprite(filename, entry);
		}
	}

	return image;
}
开发者ID:DanMillward,项目名称:halley,代码行数:32,代码来源:sprite_importer.cpp

示例9: SpriteSheet

bool Haste::load(File* file){
	static SpriteSheet ssHaste;
	static bool loaded = false;
	if (!loaded){
		ssHaste = SpriteSheet(Vec2i(1, 1));
		if (!ssHaste.load("haste.png")){
			return false;
		}
		loaded = true;
	}
	m_sprite.setSpriteSheet(&ssHaste);
	m_sprite.loadAnimation(&ssHaste, 0, 0, 1);
	m_duration = 5.0f;
	m_timeRemaining = m_duration;

	return true;
}
开发者ID:AD87,项目名称:Super-Smash-TV,代码行数:17,代码来源:Haste.cpp

示例10: SpriteDimensions

vec2 SpriteDimensions ( const std::string& sheetname )
{
	SpriteSheet* sheet;
	SheetMap::iterator iter = spriteSheets.find(sheetname);
	if (iter == spriteSheets.end())
	{
		// load it
		sheet = new SpriteSheet(sheetname);
		spriteSheets[sheetname] = sheet;
	}
	else
	{
		sheet = iter->second;
	}
	assert(sheet);
	return vec2(sheet->TileSizeX(), sheet->TileSizeY());
}
开发者ID:prophile,项目名称:xsera,代码行数:17,代码来源:Graphics.cpp

示例11: Load

bool Jelly::Load(File* file)
{
	static SpriteSheet mySpriteSheet;
	if (!mySpriteSheet.Load("jelly.png"))
	{
		return false;
	}
	mySpriteSheet.SetNumCells(2, 1);
	m_sprite.SetSpriteSheet(&mySpriteSheet);
	m_sprite.SetMaxCellTime(0.1f);
	m_sprite.SetStartCell(0);
	m_sprite.SetEndCell(1);
	m_sprite.SetPos(Vec2f(ThePlatformManager::Instance()->m_posX, ThePlatformManager::Instance()->m_posY));
	m_sprite.SetVel(Vec2f(-70, 0));
	
	return true;
}
开发者ID:mrfriedfish,项目名称:ggj13-framework-cardiacplusplus,代码行数:17,代码来源:Jelly.cpp

示例12: Load

bool BossBullet::Load(File* file)
{
	static SpriteSheet mySpriteSheet;
	if (!mySpriteSheet.Load("bossbullet.png"))
	{
		return false;
	}
	mySpriteSheet.SetNumCells(2, 1);
	m_sprite.SetSpriteSheet(&mySpriteSheet);
    
	m_sprite.SetCurrentCell(0);
    m_sprite.SetStartCell(0);
    m_sprite.SetEndCell(1);
	m_sprite.SetPos(Vec2f(TheBulletManager::Instance()->GetBulletPos().GetX(), TheBulletManager::Instance()->GetBulletPos().GetY() + rand() % 100));
	m_sprite.SetVel(Vec2f(-100, 0));

	return true;
}
开发者ID:mrfriedfish,项目名称:ggj13-framework-cardiacplusplus,代码行数:18,代码来源:BossBullet.cpp

示例13:

Particle::Particle(const AABB2& boundingBox, const Vector2& position, float orientation, float duration, const RGBA& color, const SpriteSheet& m_spriteSheet)
: m_spriteSheet(m_spriteSheet)
, m_animation(m_spriteSheet, duration, AnimMode::ONE_SHOT, 0, m_spriteSheet.GetNumSprites() - 1)
, m_position(position)
, m_orientation(orientation)
, m_boundingBox (boundingBox)
, m_color(color)
{

}
开发者ID:picoriley,项目名称:BoneMasks,代码行数:10,代码来源:Particle.cpp

示例14: createSpriteSheet

SpriteSheet TexturePacker::createSpriteSheet(SpriteArray& sprites)
{
    SpriteSheet sheet;

    QImage& image = sheet.newImage(2048, 2048);
    QPainter painter(&image);
    QPoint border(1, 1);

    const int baselength = Project::getActiveProject().getImagePath().length() + 1;

    for ( const Sprite& sprite : sprites )
    {
        QImage image(sprite.mName);
        assert(!image.isNull());

        Sprite newSprite;
        newSprite.mName = sprite.mName.right(sprite.mName.length() - baselength);
        newSprite.mCoordinates = sprite.mCoordinates;
        newSprite.mOriginalSize = sprite.mOriginalSize;
        newSprite.mRotated = sprite.mRotated;
        newSprite.translate(border);
        sheet.addSprite(newSprite);

        if ( newSprite.mRotated )
        {
            RotateImagePainter rpainter(painter);
            rpainter.drawImage(newSprite.mCoordinates.topLeft(),
                               90,
                               image.width(),
                               image.height(),
                               newSprite.mCoordinates.width(),
                               newSprite.mCoordinates.height(),
                               image);
        }
        else
        {
            painter.drawImage(newSprite.mCoordinates, image);
        }
    }

    return sheet;
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:42,代码来源:texturepacker.cpp

示例15: LOG

    void SpriteAnimationRepository::initialize(std::string filename) {
        LOG(INFO) << "Loading sprite animation repository from " << filename;
        string animationContent = FILESYS.getFileContent(filename);

        string parseError;
        auto json = Json::parse(animationContent, parseError);
        if (!parseError.empty()) {
            LOG(FATAL) << "Error while parsing JSON content from " << filename << ". Error: " << parseError;
        } else {
            for (auto& k : json["spriteSheets"].array_items()) {
                SpriteSheet* sheet = new SpriteSheet();
                sheet->texture = GFXSYS.loadTexture(k["texture"].string_value());
                sheet->autoAdd(k["spriteWidth"].int_value(), k["spriteHeight"].int_value());
                spriteSheets[k["name"].string_value()] = sheet;
            }

            for (auto& k : json["animations"].array_items()) {
                AnimationData* animData = new AnimationData();
                animationData[k["name"].string_value()] = animData;

                animData->frameTimeInMilliseconds = (float) k["frameTimeInMilliseconds"].number_value();
                animData->loopType = animationLoopType(k["loopType"].string_value());

                for (auto& f : k["frames"].array_items()) {
                    string spriteSheetName = f["spriteSheet"].string_value();
                    if (spriteSheets.find(spriteSheetName) == spriteSheets.end())
                        LOG(FATAL) << "Animation " << k["name"].string_value() << " refers to unexistent spritesheet \"" << spriteSheetName << "\"";

                    int index = f["index"].int_value();
                    int indexTo = f["indexTo"].int_value();

                    if (indexTo > index) {
                        for (int i = index; i <= indexTo; i++)
                            animData->frames.push_back(Sprite(spriteSheets[spriteSheetName], i));
                    } else {
                        animData->frames.push_back(Sprite(spriteSheets[spriteSheetName], index));
                    }
                }
            }
        }
    }
开发者ID:rdemoparty,项目名称:stardust,代码行数:41,代码来源:SpriteAnimationRepository.cpp


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