本文整理汇总了C++中Animation::addFrame方法的典型用法代码示例。如果您正苦于以下问题:C++ Animation::addFrame方法的具体用法?C++ Animation::addFrame怎么用?C++ Animation::addFrame使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Animation
的用法示例。
在下文中一共展示了Animation::addFrame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Entity
Bee::Bee(TextureManager &textureManager, b2Body *enemyBody, float moveVelocity, std::vector<sf::Vector2f> waypoints, float steering) :
Entity(enemyBody),
mMoveVelocity(moveVelocity),
mSteering(steering),
mSeeking(false) {
sf::Texture &spriteSheet = textureManager.get(TextureID::EnemiesSpriteSheet);
Animation animation;
animation.setSpriteSheet(spriteSheet);
animation.addFrame(sf::IntRect(315, 353, 56, 48));
animation.addFrame(sf::IntRect(140, 23, 61, 42));
mAnimation = animation;
mSprite = AnimatedSprite(sf::seconds(0.15f));
mSprite.setAnimation(mAnimation);
sf::FloatRect bounds = mSprite.getLocalBounds();
mSprite.setOrigin(bounds.width/2, bounds.height/2);
mCurrentFacingDirection = Entity::FacingDirection::Left;
if (waypoints.empty())
mSeeking = true;
//Position waypoints according to the bee center
//Rather than absolute top-left coordinates
else {
for (auto &waypoint : waypoints) {
sf::Vector2f platformWaypoint(
waypoint.x + 35.f,
waypoint.y + PX_PER_M - bounds.height / 2.f);
mWaypoints.push_back(platformWaypoint);
}
mCurrentWaypoint = mWaypoints.begin();
}
}
示例2: load
void FlashSpell::load(const SpellData& data, LevelMovableGameObject* mob, const sf::Vector2f& target) {
setSpriteOffset(sf::Vector2f(-10.f, 0.f));
m_mob = mob;
Animation* spellAnimation = new Animation(sf::milliseconds(200));
spellAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_spell_flash));
spellAnimation->addFrame(sf::IntRect(0, 0, 120, 120));
spellAnimation->addFrame(sf::IntRect(120, 0, 120, 120));
addAnimation(GameObjectState::Idle, spellAnimation);
// initial values
setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
playCurrentAnimation(true);
Spell::load(data, mob, target);
m_isFlashingRight = mob->isFacingRight();
m_flashingTime = FLASHING_TIME;
m_flashDuration = FLASH_DURATION;
sf::Vector2f position(m_mob->getPosition());
position.x += (m_mob->getBoundingBox()->width / 2.f);
position.y += m_mob->getBoundingBox()->height - 20;
position.x = m_isFlashingRight ? position.x - data.range : position.x + data.range;
loadParticleSystem();
m_posGenerator->center = position;
}
示例3: loadAnimation
void UnstableTile::loadAnimation(int skinNr) {
m_isCollidable = true;
Animation* idleAnimation = new Animation(sf::seconds(10.f));
idleAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_tile_unstable));
idleAnimation->addFrame(sf::IntRect(BORDER, BORDER + ((skinNr - 1) * (TILE_SIZE + 2 * BORDER)), TILE_SIZE, TILE_SIZE));
addAnimation(GameObjectState::Idle, idleAnimation);
Animation* tremblingAnimation = new Animation(sf::seconds(0.1f));
tremblingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_tile_unstable));
tremblingAnimation->addFrame(sf::IntRect(BORDER + 1 * (2 * BORDER + TILE_SIZE), BORDER + ((skinNr - 1) * (TILE_SIZE + 2 * BORDER)), TILE_SIZE, TILE_SIZE));
tremblingAnimation->addFrame(sf::IntRect(BORDER + 2 * (2 * BORDER + TILE_SIZE), BORDER + ((skinNr - 1) * (TILE_SIZE + 2 * BORDER)), TILE_SIZE, TILE_SIZE));
addAnimation(GameObjectState::Trembling, tremblingAnimation);
Animation* crumblingAnimation = new Animation();
crumblingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_tile_destructible));
for (int i = 1; i < 5; i++) {
crumblingAnimation->addFrame(sf::IntRect(
BORDER + i * (2 * BORDER + TILE_SIZE),
BORDER,
TILE_SIZE,
TILE_SIZE));
}
addAnimation(GameObjectState::Crumbling, crumblingAnimation);
// initial values
m_state = GameObjectState::Idle;
setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
playCurrentAnimation(true);
}
示例4: AnimatedSprite
pacman::pacman(sf::Texture spr)
{
//ctor
xpos = 250;
ypos = 500;
xvel = 0;
yvel = 0;
text = spr;
upan.setSpriteSheet(text);
upan.addFrame(sf::IntRect(0, 0, 25, 25));
upan.addFrame(sf::IntRect(75, 0, 25, 25));
downan.setSpriteSheet(text);
downan.addFrame(sf::IntRect(0, 0, 25, 25));
downan.addFrame(sf::IntRect(25, 0, 25, 25));
leftan.setSpriteSheet(text);
leftan.addFrame(sf::IntRect(0, 0, 25, 25));
leftan.addFrame(sf::IntRect(100, 0, 25, 25));
rightan.setSpriteSheet(text);
rightan.addFrame(sf::IntRect(0, 0, 25, 25));
rightan.addFrame(sf::IntRect(50, 0, 25, 25));
currentanim = &leftan;
anspr = AnimatedSprite(sf::seconds(.2f), false, true);
anspr.setPosition(sf::Vector2f(xpos, ypos));
//std::cout << "1 pacman" << std::endl;
anspr.play(*currentanim);
//sprite.setPosition(xpos, ypos);
collision_box = sprite.getGlobalBounds();
dir = 3;
}
示例5: readAnimatedTile
void TileMap::readAnimatedTile(int tileNumber, int layerNr, int i, int j, const WorldData& data) {
for (auto& tile : data.animatedTiles) {
if (tile.tileID == tileNumber) {
AnimatedTile* animatedTile = new AnimatedTile();
Animation* idleAnimation = new Animation(tile.frames.at(0).second);
idleAnimation->setSpriteSheet(m_tileset);
for (auto& frame : tile.frames) {
int frameTileID = frame.first - 1;
int tu = frameTileID % (m_tileset->getSize().x / (TILE_SIZE + 2 * TILE_BORDER));
int tv = frameTileID / (m_tileset->getSize().x / (TILE_SIZE + 2 * TILE_BORDER));
idleAnimation->addFrame(sf::IntRect(
tu * (TILE_SIZE + 2 * TILE_BORDER) + TILE_BORDER,
tv * (TILE_SIZE + 2 * TILE_BORDER) + TILE_BORDER,
TILE_SIZE,
TILE_SIZE));
}
animatedTile->addAnimation(GameObjectState::Idle, idleAnimation);
sf::Vector2f position(i * TILE_SIZE_F, j * TILE_SIZE_F);
// initial values
animatedTile->playCurrentAnimation(true);
animatedTile->setPosition(position);
m_animatedTiles[layerNr].push_back(animatedTile);
break;
}
}
}
示例6: loadTargetCursor
void LocalPlayer::loadTargetCursor(const std::string &filename,
const int width, const int height,
const bool outRange,
const TargetCursorSize &size)
{
assert(size > -1);
assert(size < 3);
ResourceManager *resman = ResourceManager::getInstance();
ImageSet *currentImageSet = resman->getImageSet(filename, width, height);
Animation *anim = new Animation();
for (unsigned int i = 0; i < currentImageSet->size(); ++i)
{
anim->addFrame(currentImageSet->get(i), 75,
(16 - (currentImageSet->getWidth() / 2)),
(16 - (currentImageSet->getHeight() / 2)));
}
SimpleAnimation *currentCursor = new SimpleAnimation(anim);
const int index = outRange ? 1 : 0;
mTargetCursorImages[index][size] = currentImageSet;
mTargetCursor[index][size] = currentCursor;
}
示例7: Entity
SnakeSlime::SnakeSlime(TextureManager &textureManager, b2Body *enemyBody) :
Entity(enemyBody){
sf::Texture &spriteSheet = textureManager.get(TextureID::EnemiesSpriteSheet);
Animation wiggleAnimation;
wiggleAnimation.setSpriteSheet(spriteSheet);
wiggleAnimation.addFrame(sf::IntRect(424, 187, 53, 147));
wiggleAnimation.addFrame(sf::IntRect(425, 40, 52, 147));
mAnimation = wiggleAnimation;
mSprite = AnimatedSprite(sf::seconds(0.15f));
mSprite.setAnimation(mAnimation);
sf::FloatRect bounds = mSprite.getLocalBounds();
mSprite.setOrigin(bounds.width/2, bounds.height/2);
}
示例8: initialize
void Blood::initialize(Engine& engine, double x, double y)
{
m_jumping = true;
m_velocityX = engine.getRandomNumber(-Config::BloodMaxSpeedX, Config::BloodMaxSpeedX);
m_velocityY = engine.getRandomNumber(-Config::BloodMaxSpeedY, Config::BloodMaxSpeedY);
m_movingBehavior = new GibMovingBehavior();
m_fallingBehavior = new DefaultFallingBehavior();
m_collidingBehavior = new DefaultCollidingBehavior();
addCollisionRectangle(new Square(x - 1.0, y - 1.0, 2.0, 2.0));
m_sprite = new Sprite();
int type = engine.getRandomNumber(1, 2);
Image* image = NULL;
switch (type) {
case 2: image = engine.loadImage("Resources/Gibs/blood-02.png"); break;
case 1: default: image = engine.loadImage("Resources/Gibs/blood-01.png"); break;
}
Animation* defaultAnimation = new Animation();
defaultAnimation->addFrame(new AnimationFrame(100.0, image));
m_sprite->addAnimation("default", defaultAnimation);
m_sprite->playAnimation("default");
}
示例9: frame
Animation
ToneAnimationFactoryLoudestSmooth::createToneAnimation(unsigned int nLEDs, const ToneData& toneData)
{
Animation animation;
Frame frame(nLEDs);
for (unsigned int i = 0; i < nLEDs; ++i)
{
double r = 0.0;
double g = 0.0;
double b = 0.0;
for (const auto& toneAmplitude : toneData.currentTones)
{
if (toneAmplitude.first == Tone::C)
{
r += toneAmplitude.second;
}
else if (toneAmplitude.first == Tone::D)
{
r += toneAmplitude.second/2.0;
}
else if (toneAmplitude.first == Tone::E)
{
g += toneAmplitude.second;
}
else if (toneAmplitude.first == Tone::F)
{
g += toneAmplitude.second/2.0;
}
else if (toneAmplitude.first == Tone::G)
{
b += toneAmplitude.second;
}
else if (toneAmplitude.first == Tone::A)
{
b += toneAmplitude.second/2.0;
}
else if (toneAmplitude.first == Tone::B)
{
r += toneAmplitude.second;
}
}
double norm = std::sqrt(r*r+g*g+b*b);
int rNorm = static_cast<int>(r/norm*255);
int gNorm = static_cast<int>(g/norm*255);
int bNorm = static_cast<int>(b/norm*255);
Color color(rNorm, gNorm, bNorm);
LED led(i, color);
frame.addLED(led);
}
animation.addFrame(frame);
return animation;
}
示例10: loadAnimations
void EntityResourceManager::loadAnimations(Entity &entity, Json::Value &root)
{
//Lets just confirm that the entity is an animated entity...
AnimatedEntity *animatedEntityPtr = dynamic_cast<AnimatedEntity*>(&entity);
//If it's null, then either the entity type is wrong or they have accidentally
//provided an animation file for a non-animated entity
if(animatedEntityPtr == NULL)
{
return;
}
Json::Value animations = root.get("animations", NULL);
if(animations == NULL)
{
return;
}
std::map<std::string, Animation*> *animationListPtr = new std::map<std::string, Animation*>();
//if the entity has no animation, size will be 0, which is a problem since it's an animated entity!
for(unsigned int i = 0; i < animations.size(); i++)
{
Animation *animationPtr = new Animation();
Json::Value animation = animations[i];
std::string name = animation["name"].asString();
//first see if there are any rows, if there isn't, size will be 0
Json::Value rows = animation["rows"];
for(unsigned int j = 0; j < rows.size(); j++)
{
Json::Value row = rows[j];
sf::Vector2i origin(row["origin"]["x"].asInt(), row["origin"]["y"].asInt());
unsigned int numFrames = row["frameCount"].asUInt();
sf::Vector2i frameSize(row["frameSize"]["width"].asInt(), row["frameSize"]["height"].asInt());
sf::Time duration = sf::milliseconds(row["frameDuration"].asInt());
animationPtr->addRow(origin, numFrames, frameSize, duration);
}
//now check for any individual frames
Json::Value frames = animation["frames"];
for(unsigned int j = 0; j < frames.size(); j++)
{
Json::Value frame = frames[j];
Json::Value rect = frame["rect"];
sf::Time duration = sf::milliseconds(frame["duration"].asUInt());
sf::IntRect frameRect(rect["left"].asInt(), rect["top"].asInt(),
rect["width"].asInt(), rect["height"].asInt());
animationPtr->addFrame(duration, frameRect);
}
(*animationListPtr)[name] = animationPtr;
animatedEntityPtr->setFrame(animationListPtr->at(name)->getFrameAt(0)->rect);
}
animatedEntityPtr->initAnimation(animationListPtr);
}
示例11: loadAnimation
void GargoyleEnemy::loadAnimation(int skinNr) {
m_animations.clear();
setBoundingBox(sf::FloatRect(0.f, 0.f, 50.f, 80.f));
setSpriteOffset(sf::Vector2f(-127.f, -42.f));
Animation* flyingAnimation = new Animation();
flyingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_gargoyle));
for (int i = 0; i < 8; i++) {
flyingAnimation->addFrame(sf::IntRect(195 * i, 0, 195, 180));
}
addAnimation(GameObjectState::Flying, flyingAnimation);
Animation* idleAnimation = new Animation();
idleAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_gargoyle));
for (int i = 0; i < 8; i++) {
idleAnimation->addFrame(sf::IntRect(195 * i, 0, 195, 180));
}
addAnimation(GameObjectState::Idle, idleAnimation);
// TODO: create other animations
Animation* fightingAnimation = new Animation();
fightingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_gargoyle));
for (int i = 0; i < 3; i++) {
fightingAnimation->addFrame(sf::IntRect(195 * i, 180, 195, 180));
}
fightingAnimation->setLooped(false);
addAnimation(GameObjectState::Fighting, fightingAnimation);
Animation* deadAnimation = new Animation();
deadAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_gargoyle));
for (int i = 0; i < 10; i++) {
deadAnimation->addFrame(sf::IntRect(195 * i, 360, 195, 180));
}
deadAnimation->setLooped(false);
addAnimation(GameObjectState::Dead, deadAnimation);
// initial values
setState(GameObjectState::Idle);
playCurrentAnimation(true);
}
示例12: rand
EnemyCrawler::EnemyCrawler(float x, float y)
:EnemyPatroller(x, y, 40.0f, 16.0f)
{
setImage("crawler.png");
walk_speed = 70.f;
shape->u = 0.1f;
dying = false;
life = 2;
setDrawOffset(33, 26);
setFrameSize(64, 32);
Animation * tmp;
actorName = "Crawler";
//pick a random death sound
int sound_num = rand() % 19;
sound_num += 1;
std::string s;
std::stringstream out;
out << sound_num;
s = out.str();
std::string sound_file = s + "-BugSplat.ogg";
//cout << sound_file;
fireSound = soundCache[sound_file];
facing_direction = Facing::Left;
tmp = addAnimation("walk");
tmp->addFrame(2, .2f);
tmp->addFrame(3, .2f);
tmp->setDoLoop(true);
tmp = addAnimation("die");
tmp->addFrame(8, .07f);
tmp->addFrame(7, .07f);
tmp->addFrame(6, .07f);
tmp->addFrame(5, .07f);
tmp = addAnimation("hurt");
tmp->addFrame(4, 0.07f);
setCurrentAnimation("walk");
}
示例13: load
void AureolaSpell::load(const SpellData& bean, LevelMovableGameObject* mob, const sf::Vector2f& target) {
setSpriteOffset(sf::Vector2f(-10.f, -10.f));
Animation* spellAnimation = new Animation(sf::seconds(0.3f));
spellAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_spell_aureola));
spellAnimation->addFrame(sf::IntRect(0, 0, 40, 40));
spellAnimation->addFrame(sf::IntRect(40, 0, 40, 40));
addAnimation(GameObjectState::Idle, spellAnimation);
// initial values
setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
playCurrentAnimation(true);
m_rangeLeft = bean.range;
Spell::load(bean, mob, target);
}
示例14: loadAnimation
void SkeletonEnemy::loadAnimation() {
setBoundingBox(sf::FloatRect(0.f, 0.f, 40.f, 135.f));
setSpriteOffset(sf::Vector2f(-35.f, -15.f));
Animation* walkingAnimation = new Animation(sf::seconds(0.1f));
walkingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
for (int i = 0; i < 8; i++) {
walkingAnimation->addFrame(sf::IntRect(i * 150, 0, 150, 150));
}
addAnimation(GameObjectState::Walking, walkingAnimation);
Animation* jumpingAnimation = new Animation();
jumpingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
jumpingAnimation->addFrame(sf::IntRect(0, 0, 150, 150));
addAnimation(GameObjectState::Jumping, jumpingAnimation);
Animation* idleAnimation = new Animation();
idleAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
idleAnimation->addFrame(sf::IntRect(00, 150, 150, 150));
addAnimation(GameObjectState::Idle, idleAnimation);
Animation* fightingAnimation = new Animation(sf::seconds(0.05f));
fightingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
for (int i = 0; i < 8; i++) {
fightingAnimation->addFrame(sf::IntRect(i * 150, 300, 150, 150));
}
addAnimation(GameObjectState::Fighting, fightingAnimation);
Animation* deadAnimation = new Animation();
deadAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
for (int i = 0; i < 2; i++) {
deadAnimation->addFrame(sf::IntRect(i * 150, 450, 150, 150));
}
deadAnimation->setLooped(false);
addAnimation(GameObjectState::Dead, deadAnimation);
// initial values
setState(GameObjectState::Idle);
playCurrentAnimation(true);
}
示例15: load
void FearSpell::load(const SpellBean& bean, LevelMovableGameObject* mob, const sf::Vector2f& target)
{
setSpriteOffset(sf::Vector2f(-10.f, -10.f));
Animation spellAnimation;
spellAnimation.setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_spell_fear));
spellAnimation.addFrame(sf::IntRect(0, 0, 30, 30));
spellAnimation.addFrame(sf::IntRect(30, 0, 30, 30));
addAnimation(GameObjectState::Idle, spellAnimation);
setFrameTime(sf::seconds(0.1f));
// initial values
setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
playCurrentAnimation(true);
Spell::load(bean, mob, target);
}