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


C++ Tileset::add_tile_pattern方法代码示例

本文整理汇总了C++中Tileset::add_tile_pattern方法的典型用法代码示例。如果您正苦于以下问题:C++ Tileset::add_tile_pattern方法的具体用法?C++ Tileset::add_tile_pattern怎么用?C++ Tileset::add_tile_pattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tileset的用法示例。


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

示例1: l_tile_pattern

/**
 * \brief Function called by Lua to add a tile pattern to the tileset.
 *
 * - Argument 1 (table): A table describing the tile pattern to create.
 *
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int Tileset::l_tile_pattern(lua_State* l) {

  lua_getfield(l, LUA_REGISTRYINDEX, "tileset");
  Tileset* tileset = static_cast<Tileset*>(lua_touserdata(l, -1));
  lua_pop(l, 1);

  int x[] = { -1, -1, -1, -1 };
  int y[] = { -1, -1, -1, -1 };

  const std::string& id = LuaTools::check_string_field(l, 1, "id");
  const Ground ground = LuaTools::check_enum_field<Ground>(l, 1, "ground", ground_names);
  const int default_layer = LuaTools::check_layer_field(l, 1, "default_layer");
  const int width = LuaTools::check_int_field(l, 1, "width");
  const int height = LuaTools::check_int_field(l, 1, "height");
  const std::string& scrolling = LuaTools::opt_string_field(l, 1, "scrolling", "");

  int i = 0, j = 0;
  lua_settop(l, 1);
  lua_getfield(l, 1, "x");
  if (lua_isnumber(l, 2)) {
    // Single frame.
    x[0] = luaL_checkint(l, 2);
    i = 1;
  }
  else {
    // Multi-frame.
    lua_pushnil(l);
    while (lua_next(l, 2) != 0 && i < 4) {
      x[i] = luaL_checkint(l, 4);
      ++i;
      lua_pop(l, 1);
    }
  }
  lua_pop(l, 1);
  Debug::check_assertion(lua_gettop(l) == 1, "Invalid stack when parsing tile pattern");

  lua_getfield(l, 1, "y");
  if (lua_isnumber(l, 2)) {
    // Single frame.
    y[0] = luaL_checkint(l, 2);
    j = 1;
  }
  else {
    // Multi-frame.
    lua_pushnil(l);
    while (lua_next(l, 2) != 0 && j < 4) {
      y[j] = luaL_checkint(l, 4);
      ++j;
      lua_pop(l, 1);
    }
  }
  lua_pop(l, 1);
  Debug::check_assertion(lua_gettop(l) == 1, "Invalid stack when parsing tile pattern");

  // Check data.
  if (i != 1 && i != 3 && i != 4) {
    LuaTools::arg_error(l, 1, "Invalid number of frames for x");
  }
  if (j != 1 && j != 3 && j != 4) {
    LuaTools::arg_error(l, 1, "Invalid number of frames for y");
  }
  if (i != j) {
    LuaTools::arg_error(l, 1, "The length of x and y must match");
  }

  // Create the tile pattern.
  TilePattern* tile_pattern = NULL;
  if (i == 1) {
    // Single frame.
    if (scrolling.empty()) {
      tile_pattern = new SimpleTilePattern(ground, x[0], y[0], width, height);
    }
    else if (scrolling == "parallax") {
      tile_pattern = new ParallaxScrollingTilePattern(ground, x[0], y[0], width, height);
    }
    else if (scrolling == "self") {
      tile_pattern = new SelfScrollingTilePattern(ground, x[0], y[0], width, height);
    }
  }
  else {
    // Multi-frame.
    if (scrolling == "self") {
      LuaTools::arg_error(l, 1, "Multi-frame is not supported for self-scrolling tiles");
    }
    bool parallax = scrolling == "parallax";
    AnimatedTilePattern::AnimationSequence sequence = (i == 3) ?
        AnimatedTilePattern::ANIMATION_SEQUENCE_012 : AnimatedTilePattern::ANIMATION_SEQUENCE_0121;
    tile_pattern = new AnimatedTilePattern(ground, sequence, width, height,
        x[0], y[0], x[1], y[1], x[2], y[2], parallax);
  }

  tileset->add_tile_pattern(id, tile_pattern);
//.........这里部分代码省略.........
开发者ID:kenygia,项目名称:solarus,代码行数:101,代码来源:Tileset.cpp


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