查看: 1727|回复: 6

[已经解决] 求帮转成xp自动元件格式

[复制链接]
梦石
0
星屑
50
在线时间
108 小时
注册时间
2015-1-18
回帖
108
发表于 2015-4-21 22:47:45 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 电脑仔 于 2015-4-21 22:52 编辑

转成xp自动元件.png
求帮转成xp自动元件格式并把上图的多余的砖地换成下图的砖地
120254vwfjf6dhrtjhuvfn.png


把这个
多余的地.png
换成图二的地
多余的地2.png
梦石
0
星屑
76
在线时间
1379 小时
注册时间
2012-7-5
回帖
1643

开拓者

发表于 2015-4-22 22:39:01 | 显示全部楼层
本帖最后由 kuerlulu 于 2015-4-23 12:37 编辑

ssss.png
[fold=CACAO 的 save_png(必须)]

  1. #==============================================================================
  2. # ■ Bitmap
  3. #------------------------------------------------------------------------------
  4. #   位图的类。所谓位图即表示图像其本身。
  5. #==============================================================================
  6. class Bitmap
  7.   #--------------------------------------------------------------------------
  8.   # ● 保存成 png 格式
  9.   #     filename : 文件名
  10.   #     alpha    : 透明通道有效
  11.   #--------------------------------------------------------------------------
  12.   def save_png(filename, alpha = true)
  13.     sgnt = "\x89PNG\r\n\x1a\n"
  14.     ihdr = _chunk('IHDR', [width,height,8,(alpha ? 6 : 2),0,0,0].pack('N2C5'))
  15.     data = []
  16.     height.times do |y|
  17.       data << 0
  18.       width.times do |x|
  19.         color = self.get_pixel(x, y)
  20.         data << color.red << color.green << color.blue
  21.         data << color.alpha if alpha
  22.       end
  23.     end
  24.     idat = _chunk('IDAT', Zlib::Deflate.deflate(data.pack('C*')))
  25.     iend = _chunk('IEND', "")
  26.     File.open(filename, 'wb') do |file|
  27.       file.write(sgnt)
  28.       file.write(ihdr)
  29.       file.write(idat)
  30.       file.write(iend)
  31.     end
  32.   end
  33. private
  34.   #--------------------------------------------------------------------------
  35.   # ● チャンクの作成
  36.   #     name : チャンク名
  37.   #     data : チャンクデータ
  38.   #--------------------------------------------------------------------------
  39.   def _chunk(name, data)
  40.     return [data.size, name, data, Zlib.crc32(name + data)].pack('NA4A*N')
  41.   end
  42. end
复制代码
[/fold]
[fold=主代码]
  1. # 2x2 转 3x3
  2. def conv_2x2_3x3(b)
  3.   a = Bitmap.new 96, 96 # 3x3
  4.   a.blt( 0,  0, b, Rect.new( 0,  0, 48, 48))
  5.   a.blt(48,  0, b, Rect.new(16,  0, 48, 48))
  6.   a.blt( 0, 48, b, Rect.new( 0, 16, 48, 48))
  7.   a.blt(48, 48, b, Rect.new(16, 16, 48, 48))
  8.   return a
  9. end

  10. # (动画)自动地图元件(vx/a -> xp) # n 帧数
  11. def conv_tileset(c, n = 1)
  12.   w = c.width / n
  13.   a = Bitmap.new 96 * n, 128 # 3x4xn
  14.   b = Bitmap.new 64,     64  # 2x2
  15.   n.times do |x|
  16.     a.blt(96 * x, 0, c, Rect.new(64 * x, 0, 32, 32))           # A
  17.     a.fill_rect(96 * x + 32, 0, 32, 32, c.get_pixel(64 * x, 0))# B
  18.     a.blt(96 * x + 64, 0, c, Rect.new(32, 0, 32, 32))          # C
  19.     b.blt(0, 0, c, Rect.new(64 * x, 32, 64, 64))               # 2x2
  20.     a.blt(96 * x, 32, conv_2x2_3x3(b), Rect.new(0, 0, 96, 96)) # combine
  21.     b.clear
  22.   end
  23.   b.dispose
  24.   return a
  25. end

  26. =begin 为了替换"砖块"随手写的【最终目的是装逼+省字数
  27. class Bitmap
  28.   def reblt(x, y, b, r)
  29.     self.fill_rect(x, y, r.width, r.height, Color.new(0, 0, 0, 0))
  30.     self.blt(x, y, b, r)
  31.   end
  32. end
  33. a = Bitmap.new("di.png")
  34. b = Bitmap.new("ss.png")
  35. 3.times do |x|
  36.   b.reblt(64 * x,  0, a, Rect.new(0, 24, 32, 8))
  37.   b.reblt(64 * x, 32, a, Rect.new(0, 88, 64, 8))
  38. end
  39. #b.save_png("mm.png")
  40. =end

  41. conv_tileset(Bitmap.new("mm.png"), 3).save_png("ssss.png")
复制代码
[/fold]
[fold=主代码的食用姿势]
[pre lang="ruby"]conv_tileset(Bitmap.new("文件路径"), 帧数(默认为1)).save_png("输出路径")[/pre]
[/fold]
另外这是我在水区发的一些已经转好的素材和代码

评分

参与人数 1星屑 +200 收起 理由
美丽晨露 + 200 认可答案

查看全部评分


  -fk: -azogi:
回复

使用道具 举报

梦石
0
星屑
50
在线时间
108 小时
注册时间
2015-1-18
回帖
108
 楼主| 发表于 2015-4-27 01:28:10 | 显示全部楼层
thankyouverymuch
回复

使用道具 举报

梦石
0
星屑
50
在线时间
108 小时
注册时间
2015-1-18
回帖
108
 楼主| 发表于 2015-5-1 22:42:28 | 显示全部楼层
kuerlulu 发表于 2015-4-22 22:39
[fold=主代码的食用姿势]
conv_tileset(Bit ...

QQ截图20150501224523.png
帮我看看代码出什么问题了?

点评

conv_tileset(Bitmap.new("file.png"), 1).save_png("file2.png")  发表于 2015-5-3 11:39
回复

使用道具 举报

梦石
0
星屑
50
在线时间
108 小时
注册时间
2015-1-18
回帖
108
 楼主| 发表于 2015-5-3 17:00:37 | 显示全部楼层
kuerlulu 发表于 2015-4-22 22:39
[fold=主代码的食用姿势]
conv_tileset(Bit ...

QQ截图20150503170304.png

已经改了,还是有错误

点评

゚(つд`゚)然而首先你要有file.png这个文件, 或者你改成别的只要这个文件名存在于你的游戏根目录  发表于 2015-5-4 12:27
回复

使用道具 举报

梦石
0
星屑
50
在线时间
108 小时
注册时间
2015-1-18
回帖
108
 楼主| 发表于 2015-5-5 19:12:28 | 显示全部楼层
本帖最后由 电脑仔 于 2015-5-6 23:34 编辑
kuerlulu 发表于 2015-4-22 22:39
[fold=主代码的食用姿势]
conv_tileset(Bit ...


转成xp格式.rar (454.13 KB, 下载次数: 60)

怎么改都还是有错,你来看看工程。

为毛打开的时候是这样的呢.png
为毛打开的时候是这样的呢?

好不容易改好了发现是这样的。

点评

请善用点评和编辑功能,谢谢。  发表于 2015-5-6 22:31
回复

使用道具 举报

梦石
0
星屑
76
在线时间
1379 小时
注册时间
2012-7-5
回帖
1643

开拓者

发表于 2015-5-8 11:56:20 | 显示全部楼层
转成xp格式.zip (626.74 KB, 下载次数: 68)
改好了你自己看

点评

因为代码页某一行是exit 话说你一开始不是要转图咩 代码还是不会用的话随便加个rm群问吧(绝对不是嫌弃而是真没空  发表于 2015-5-9 12:20
我下载了发现一打开就自动关闭,你打开测试过吗  发表于 2015-5-8 23:16
非常感谢  发表于 2015-5-8 16:47

评分

参与人数 1梦石 +1 收起 理由
美丽晨露 + 1 素材区好人卡

查看全部评分


  -fk: -azogi:
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部