本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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 };
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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)
{
}
示例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;
}
示例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));
}
}
}
}
}