本文整理汇总了C++中SurfacePtr::hflip方法的典型用法代码示例。如果您正苦于以下问题:C++ SurfacePtr::hflip方法的具体用法?C++ SurfacePtr::hflip怎么用?C++ SurfacePtr::hflip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SurfacePtr
的用法示例。
在下文中一共展示了SurfacePtr::hflip方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
void
SpriteData::parse_action(const ReaderMapping& lisp, const std::string& basedir)
{
auto action = std::unique_ptr<Action>(new Action);
if(!lisp.get("name", action->name)) {
if(!actions.empty())
throw std::runtime_error(
"If there are more than one action, they need names!");
}
std::vector<float> hitbox;
if (lisp.get("hitbox", hitbox)) {
switch(hitbox.size()) {
case 4:
action->hitbox_h = hitbox[3];
action->hitbox_w = hitbox[2];
//fall-through
case 2:
action->y_offset = hitbox[1];
action->x_offset = hitbox[0];
break;
default:
throw std::runtime_error("hitbox should specify 2/4 coordinates");
}
}
lisp.get("z-order", action->z_order);
lisp.get("fps", action->fps);
std::string mirror_action;
if (lisp.get("mirror-action", mirror_action)) {
const Action* act_tmp = get_action(mirror_action);
if(act_tmp == NULL) {
std::ostringstream msg;
msg << "Could not mirror action. Action not found: \"" << mirror_action << "\"\n"
<< "Mirror actions must be defined after the real one!";
throw std::runtime_error(msg.str());
} else {
float max_w = 0;
float max_h = 0;
for(int i = 0; static_cast<unsigned int>(i) < act_tmp->surfaces.size(); i++) {
SurfacePtr surface = act_tmp->surfaces[i]->clone();
surface->hflip();
max_w = std::max(max_w, (float) surface->get_width());
max_h = std::max(max_h, (float) surface->get_height());
action->surfaces.push_back(surface);
}
if (action->hitbox_w < 1) action->hitbox_w = max_w - action->x_offset;
if (action->hitbox_h < 1) action->hitbox_h = max_h - action->y_offset;
}
} else { // Load images
std::vector<std::string> images;
if(!lisp.get("images", images)) {
std::stringstream msg;
msg << "Sprite '" << name << "' contains no images in action '"
<< action->name << "'.";
throw std::runtime_error(msg.str());
} else {
float max_w = 0;
float max_h = 0;
for(std::vector<std::string>::size_type i = 0; i < images.size(); i++) {
SurfacePtr surface = Surface::create(basedir + images[i]);
max_w = std::max(max_w, (float) surface->get_width());
max_h = std::max(max_h, (float) surface->get_height());
action->surfaces.push_back(surface);
}
if (action->hitbox_w < 1) action->hitbox_w = max_w - action->x_offset;
if (action->hitbox_h < 1) action->hitbox_h = max_h - action->y_offset;
}
}
actions[action->name] = std::move(action);
}