本文整理汇总了C++中DrawingContext::set_drawing_effect方法的典型用法代码示例。如果您正苦于以下问题:C++ DrawingContext::set_drawing_effect方法的具体用法?C++ DrawingContext::set_drawing_effect怎么用?C++ DrawingContext::set_drawing_effect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DrawingContext
的用法示例。
在下文中一共展示了DrawingContext::set_drawing_effect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
BadGuy::draw(DrawingContext& context)
{
if(!sprite.get())
return;
if(state == STATE_INIT || state == STATE_INACTIVE)
return;
if(state == STATE_FALLING) {
DrawingEffect old_effect = context.get_drawing_effect();
context.set_drawing_effect(old_effect | VERTICAL_FLIP);
sprite->draw(context, get_pos(), layer);
context.set_drawing_effect(old_effect);
} else {
sprite->draw(context, get_pos(), layer);
}
}
示例2: roundf
void
TileMap::draw(DrawingContext& context)
{
// skip draw if current opacity is 0.0
if (current_alpha == 0.0) return;
context.push_transform();
if(draw_target != DrawingContext::NORMAL) {
context.push_target();
context.set_target(draw_target);
}
if(drawing_effect != 0) context.set_drawing_effect(drawing_effect);
if (editor_active) {
if(current_alpha != 1.0) {
context.set_alpha(current_alpha);
}
} else {
context.set_alpha(current_alpha/2);
}
/* Force the translation to be an integer so that the tiles appear sharper.
* For consistency (i.e., to avoid 1-pixel gaps), this needs to be done even
* for solid tilemaps that are guaranteed to have speed 1.
* FIXME Force integer translation for all graphics, not just tilemaps. */
float trans_x = roundf(context.get_translation().x);
float trans_y = roundf(context.get_translation().y);
context.set_translation(Vector(int(trans_x * speed_x),
int(trans_y * speed_y)));
Rectf draw_rect = Rectf(context.get_translation(),
context.get_translation() + Vector(SCREEN_WIDTH, SCREEN_HEIGHT));
Rect t_draw_rect = get_tiles_overlapping(draw_rect);
Vector start = get_tile_position(t_draw_rect.left, t_draw_rect.top);
Vector pos;
int tx, ty;
for(pos.x = start.x, tx = t_draw_rect.left; tx < t_draw_rect.right; pos.x += 32, ++tx) {
for(pos.y = start.y, ty = t_draw_rect.top; ty < t_draw_rect.bottom; pos.y += 32, ++ty) {
int index = ty*width + tx;
assert (index >= 0);
assert (index < (width * height));
if (tiles[index] == 0) continue;
const Tile* tile = tileset->get(tiles[index]);
assert(tile != 0);
tile->draw(context, pos, z_pos);
} /* for (pos y) */
} /* for (pos x) */
if(draw_target != DrawingContext::NORMAL) {
context.pop_target();
}
context.pop_transform();
}
示例3: roundf
void
TileMap::draw(DrawingContext& context)
{
// skip draw if current opacity is 0.0
if (current_alpha == 0.0) return;
context.push_transform();
if(draw_target != DrawingContext::NORMAL) {
context.push_target();
context.set_target(draw_target);
}
if(drawing_effect != 0) context.set_drawing_effect(drawing_effect);
if(current_alpha != 1.0) context.set_alpha(current_alpha);
/* Force the translation to be an integer so that the tiles appear sharper.
* For consistency (i.e., to avoid 1-pixel gaps), this needs to be done even
* for solid tilemaps that are guaranteed to have speed 1.
* FIXME Force integer translation for all graphics, not just tilemaps. */
float trans_x = roundf(context.get_translation().x);
float trans_y = roundf(context.get_translation().y);
context.set_translation(Vector(int(trans_x * speed_x),
int(trans_y * speed_y)));
Rectf draw_rect = Rectf(context.get_translation(),
context.get_translation() + Vector(SCREEN_WIDTH, SCREEN_HEIGHT));
Rect t_draw_rect = get_tiles_overlapping(draw_rect);
// Make sure the tilemap is within draw view
if (t_draw_rect.is_valid()) {
Vector start = get_tile_position(t_draw_rect.left, t_draw_rect.top);
Vector pos;
int tx, ty;
for(pos.x = start.x, tx = t_draw_rect.left; tx < t_draw_rect.right; pos.x += 32, ++tx) {
for(pos.y = start.y, ty = t_draw_rect.top; ty < t_draw_rect.bottom; pos.y += 32, ++ty) {
int index = ty*width + tx;
assert (index >= 0);
assert (index < (width * height));
if (tiles[index] == 0) continue;
const Tile* tile = tileset->get(tiles[index]);
assert(tile != 0);
tile->draw(context, pos, z_pos, current_tint);
} /* for (pos y) */
} /* for (pos x) */
/* Make sure that tiles with images larger than 32x32 that overlap
* the draw rect will be drawn, even if their tile position does
* not fall within the draw rect. */
static const int EXTENDING_TILES = 32;
int ex_left = std::max(0, t_draw_rect.left-EXTENDING_TILES);
int ex_top = std::max(0, t_draw_rect.top-EXTENDING_TILES);
Vector ex_start = get_tile_position(ex_left, ex_top);
for (pos.x = start.x, tx = t_draw_rect.left; tx < t_draw_rect.right; pos.x += 32, ++tx) {
for (pos.y = ex_start.y, ty = ex_top; ty < t_draw_rect.top; pos.y += 32, ++ty) {
int index = ty*width + tx;
assert (index >= 0);
assert (index < (width * height));
if (tiles[index] == 0) continue;
const Tile* tile = tileset->get(tiles[index]);
assert(tile != 0);
SurfacePtr image = tile->get_current_image();
if (image) {
int h = image->get_height();
if (h <= 32) continue;
if (pos.y + h > start.y)
tile->draw(context, pos, z_pos, current_tint);
}
}
}
for (pos.x = ex_start.x, tx = ex_left; tx < t_draw_rect.right; pos.x += 32, ++tx) {
for(pos.y = ex_start.y, ty = ex_top; ty < t_draw_rect.bottom; pos.y += 32, ++ty) {
int index = ty*width + tx;
assert (index >= 0);
assert (index < (width * height));
if (tiles[index] == 0) continue;
const Tile* tile = tileset->get(tiles[index]);
assert(tile != 0);
SurfacePtr image = tile->get_current_image();
if (image) {
int w = image->get_width();
int h = image->get_height();
if (w <= 32 && h <= 32) continue;
if (pos.x + w > start.x && pos.y + h > start.y)
tile->draw(context, pos, z_pos, current_tint);
}
}
}
}
//.........这里部分代码省略.........