Project1
标题: 如何移动(或删除)用【脚本】生成的图片 [打印本页]
作者: cyk070428 时间: 2020-3-17 19:57
标题: 如何移动(或删除)用【脚本】生成的图片
本帖最后由 cyk070428 于 2020-3-18 08:38 编辑
如何移动(或删除)用【脚本】生成的图片
作者: cyk070428 时间: 2020-3-17 20:00
注意,是脚本,不是事件
作者: cyk070428 时间: 2020-3-17 20:16
额,其实就是想问一下bitmap的clear要怎么用
作者: RyanBern 时间: 2020-3-17 23:11
首先欢迎新人加入 P1 站。在论坛发帖可以使用【编辑】功能,不必重复回帖。简短回复他人可使用【点评】功能。
就主楼的问题,脚本生成的图片大多是由 Sprite 类显示的,Bitmap 类只是负责传输数据。想删除图片的话必须对 Sprite 类进行 dispose 操作,但 bitmap 类是否需要释放要根据具体情形。
例子:
# 显示图片
sprite = Sprite.new
sprite.bitmap = RPG::Cache.picture("图片名")
# 删除
sprite.dispose # 使用 RPG::Cache 载入的 bitmap 无需 bitmap.dispose
# 显示图片
sprite = Sprite.new
sprite.bitmap = RPG::Cache.picture("图片名")
# 删除
sprite.dispose # 使用 RPG::Cache 载入的 bitmap 无需 bitmap.dispose
bitmap 的 clear 用法直接调用即可。
bmp = Bitmap.new(32, 32)
bmp.clear
bmp = Bitmap.new(32, 32)
bmp.clear
注意:clear 只是清除内容,bitmap 对象还在,如果想彻底删除请用 dispose
作者: cyk070428 时间: 2020-3-18 07:30
本帖最后由 cyk070428 于 2020-3-18 08:45 编辑
额,为什么这个会显示NameError
#显示移动自机
class Fight
def fight_3
# 显示图片
myplane = Sprite.new
myplane.bitmap = RPG::Cache.picture("myplane")
myplane.ox = myplane.bitmap.width / 2
myplane.oy = myplane.bitmap.height / 2
myplane.x = $actor_x_
myplane.y = $actor_y_
end
end
class Fight
def fight_4
#删除
sprite.dispose
end
end
#补充:最后一图的错误
class Fight
def fight_4
#删除
myplane = Sprite.dispose
end
end
#显示移动自机
class Fight
def fight_3
# 显示图片
myplane = Sprite.new
myplane.bitmap = RPG::Cache.picture("myplane")
myplane.ox = myplane.bitmap.width / 2
myplane.oy = myplane.bitmap.height / 2
myplane.x = $actor_x_
myplane.y = $actor_y_
end
end
class Fight
def fight_4
#删除
sprite.dispose
end
end
#补充:最后一图的错误
class Fight
def fight_4
#删除
myplane = Sprite.dispose
end
end
-
QQ截图20200318073826.png
(15.96 KB, 下载次数: 15)
-
QQ截图20200318081914.png
(2.19 KB, 下载次数: 18)
-
QQ截图20200318084424.png
(15.08 KB, 下载次数: 17)
作者: 1095884734 时间: 2020-3-18 09:18
本帖最后由 1095884734 于 2020-3-18 09:42 编辑
myplane是个对象,Sprite是一个类
由于dispose是一个实例方法,所以不能直接用 类名.实例方法 的方式来调用,应该是 对象.实例方法
所以删除应该是
要在脚本里实现事件效果的话 可以参考Interpreter脚本里的代码
- #--------------------------------------------------------------------------
- # ● 移动图片
- #--------------------------------------------------------------------------
- def command_232
- # 获取图片编号
- number = @parameters[0] + ($game_temp.in_battle ? 50 : 0)
- # 指定方法为 [直接指定] 的情况下
- if @parameters[3] == 0
- x = @parameters[4]
- y = @parameters[5]
- # 指定方法为 [使用变量指定] 的情况下
- else
- x = $game_variables[@parameters[4]]
- y = $game_variables[@parameters[5]]
- end
- # 移动图片
- $game_screen.pictures[number].move(@parameters[1] * 2, @parameters[2],
- x, y, @parameters[6], @parameters[7], @parameters[8], @parameters[9])
- # 继续
- return true
- end
复制代码
我找了一下 事件里移动图片的方法是在Game_Picture里
#--------------------------------------------------------------------------
# ● 移动图片
# duration : 时间
# origin : 原点
# x : X 坐标
# y : Y 坐标
# zoom_x : X 方向放大率
# zoom_y : Y 方向放大率
# opacity : 不透明度
# blend_type : 合成方式
#--------------------------------------------------------------------------
def move(duration, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
@duration = duration
@origin = origin
@target_x = x.to_f
@target_y = y.to_f
@target_zoom_x = zoom_x.to_f
@target_zoom_y = zoom_y.to_f
@target_opacity = opacity.to_f
@blend_type = blend_type
end
#--------------------------------------------------------------------------
# ● 移动图片
# duration : 时间
# origin : 原点
# x : X 坐标
# y : Y 坐标
# zoom_x : X 方向放大率
# zoom_y : Y 方向放大率
# opacity : 不透明度
# blend_type : 合成方式
#--------------------------------------------------------------------------
def move(duration, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
@duration = duration
@origin = origin
@target_x = x.to_f
@target_y = y.to_f
@target_zoom_x = zoom_x.to_f
@target_zoom_y = zoom_y.to_f
@target_opacity = opacity.to_f
@blend_type = blend_type
end
这方法里只是设定了图片移动的末位置什么的 移动图片主要是在update里实现的#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
if @duration >= 1
d = @duration
@x = (@x * (d - 1) + @target_x) / d
@y = (@y * (d - 1) + @target_y) / d
@zoom_x = (@zoom_x * (d - 1) + @target_zoom_x) / d
@zoom_y = (@zoom_y * (d - 1) + @target_zoom_y) / d
@opacity = (@opacity * (d - 1) + @target_opacity) / d
@duration -= 1
end
if @tone_duration >= 1
d = @tone_duration
@tone.red = (@tone.red * (d - 1) + @tone_target.red) / d
@tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
@tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d
@tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d
@tone_duration -= 1
end
if @rotate_speed != 0
@angle += @rotate_speed / 2.0
while @angle < 0
@angle += 360
end
@angle %= 360
end
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
if @duration >= 1
d = @duration
@x = (@x * (d - 1) + @target_x) / d
@y = (@y * (d - 1) + @target_y) / d
@zoom_x = (@zoom_x * (d - 1) + @target_zoom_x) / d
@zoom_y = (@zoom_y * (d - 1) + @target_zoom_y) / d
@opacity = (@opacity * (d - 1) + @target_opacity) / d
@duration -= 1
end
if @tone_duration >= 1
d = @tone_duration
@tone.red = (@tone.red * (d - 1) + @tone_target.red) / d
@tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
@tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d
@tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d
@tone_duration -= 1
end
if @rotate_speed != 0
@angle += @rotate_speed / 2.0
while @angle < 0
@angle += 360
end
@angle %= 360
end
end
还有就是 不知道你在脚本里是怎么写的 一个类(class)里面可以有多个方法的
总的来说可以改成这样
class Fight < Sprite
def fight_3
# 显示图片
myplane = Sprite.new
myplane.bitmap = RPG::Cache.picture("myplane")
myplane.ox = myplane.bitmap.width / 2
myplane.oy = myplane.bitmap.height / 2
myplane.x = $actor_x_
myplane.y = $actor_y_
end
def fight_4
#删除
myplane.dispose
end
end
class Fight < Sprite
def fight_3
# 显示图片
myplane = Sprite.new
myplane.bitmap = RPG::Cache.picture("myplane")
myplane.ox = myplane.bitmap.width / 2
myplane.oy = myplane.bitmap.height / 2
myplane.x = $actor_x_
myplane.y = $actor_y_
end
def fight_4
#删除
myplane.dispose
end
end
作者: cyk070428 时间: 2020-3-18 10:01
本帖最后由 cyk070428 于 2020-3-18 10:26 编辑
$enemy_hp = 1
$fight_over = 1
$fight_time = 1
#防止触发一些奇♂奇♂gay♂gay的东西
class Fight < Sprite
def fight_1
if $switches101 = 1
$actor_hp = 20
#角色HP初始化
###############################################################################
#此处补充内容:根据角色设置伤害,并将其代人
$actor_atk = 1
###############################################################################
$actor_x = 20 #横轴(20*2=40→
$actor_y = 25 #数轴(15*2=30↓
$actor_x_ = 320
$actor_y_ = 400
#角色位置初始化(上为判定,下为显示
$atk_time = 0
#攻击冷却初始化
$fight_time = 20
#回合剩余时间初始化
$zd_1_x = 0
$zd_1_y = 0
$zd_2_x = 0
$zd_2_y = 0
$zd_3_x = 0
$zd_3_y = 0
$zd_4_x = 0
$zd_4_y = 0
$zd_5_x = 0
$zd_5_y = 0
$zd_6_x = 0
$zd_6_y = 0
$zd_7_x = 0
$zd_7_y = 0
$zd_8_x = 0
$zd_8_y = 0
$zd_9_x = 0
$zd_9_y = 0
$zd_10_x = 0
$zd_10_y = 0
$zd_11_x = 0
$zd_11_y = 0
$zd_12_x = 0
$zd_12_y = 0
$zd_13_x = 0
$zd_13_y = 0
$zd_14_x = 0
$zd_14_y = 0
$zd_15_x = 0
$zd_15_y = 0
$zd_16_x = 0
$zd_16_y = 0
$zd_17_x = 0
$zd_17_y = 0
$zd_18_x = 0
$zd_18_y = 0
$zd_19_x = 0
$zd_19_y = 0
$zd_20_x = 0
$zd_20_y = 0
$zd_21_x = 0
$zd_21_y = 0
#编号为1-21的子弹的位置初始化
$atk_time = 0
#攻击冷却初始化
$fight_time = 20
#回合剩余时间初始化
$fight_over = 5
#剩余回合初始化
$enemy_hp = 40
#敌人HP初始化
###############################################################################
#此处补充内容:根据战斗场次设置伤害,并将其代人
$enemy_atk = 1
###############################################################################
end
end
def fight_2
if $zd_1_x = $actor_x
if $zd_1_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_2_x = $actor_x
if $zd_2_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_3_x = $actor_x
if $zd_3_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_4_x = $actor_x
if $zd_4_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_5_x = $actor_x
if $zd_5_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_6_x = $actor_x
if $zd_6_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_7_x = $actor_x
if $zd_7_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_8_x = $actor_x
if $zd_8_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_9_x = $actor_x
if $zd_9_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_10_x = $actor_x
if $zd_10_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_11_x = $actor_x
if $zd_11_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_12_x = $actor_x
if $zd_12_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_13_x = $actor_x
if $zd_13_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_14_x = $actor_x
if $zd_14_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_15_x = $actor_x
if $zd_15_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_16_x = $actor_x
if $zd_16_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_17_x = $actor_x
if $zd_17_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_18_x = $actor_x
if $zd_18_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_19_x = $actor_x
if $zd_19_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_20_x = $actor_x
if $zd_20_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_21_x = $actor_x
if $zd_21_y = $actor_y
$actor_hp -= $enemy_atk
end
end
end
#显示移动自机
def fight_3
# 显示图片
myplane = Sprite.new
myplane.bitmap = RPG::Cache.picture("myplane")
myplane.ox = myplane.bitmap.width / 2
myplane.oy = myplane.bitmap.height / 2
myplane.x = $actor_x_
myplane.y = $actor_y_
end
def fight_4
#删除
myplane.dispose
end
end
alex = Fight.new
alex.fight_1
#Fight攻击系统、移动脚本在Game_Player中(关键词:ukyjthdgfs/mfejnhwn)
#disillusionment by planting bonudary
$enemy_hp = 1
$fight_over = 1
$fight_time = 1
#防止触发一些奇♂奇♂gay♂gay的东西
class Fight < Sprite
def fight_1
if $switches101 = 1
$actor_hp = 20
#角色HP初始化
###############################################################################
#此处补充内容:根据角色设置伤害,并将其代人
$actor_atk = 1
###############################################################################
$actor_x = 20 #横轴(20*2=40→
$actor_y = 25 #数轴(15*2=30↓
$actor_x_ = 320
$actor_y_ = 400
#角色位置初始化(上为判定,下为显示
$atk_time = 0
#攻击冷却初始化
$fight_time = 20
#回合剩余时间初始化
$zd_1_x = 0
$zd_1_y = 0
$zd_2_x = 0
$zd_2_y = 0
$zd_3_x = 0
$zd_3_y = 0
$zd_4_x = 0
$zd_4_y = 0
$zd_5_x = 0
$zd_5_y = 0
$zd_6_x = 0
$zd_6_y = 0
$zd_7_x = 0
$zd_7_y = 0
$zd_8_x = 0
$zd_8_y = 0
$zd_9_x = 0
$zd_9_y = 0
$zd_10_x = 0
$zd_10_y = 0
$zd_11_x = 0
$zd_11_y = 0
$zd_12_x = 0
$zd_12_y = 0
$zd_13_x = 0
$zd_13_y = 0
$zd_14_x = 0
$zd_14_y = 0
$zd_15_x = 0
$zd_15_y = 0
$zd_16_x = 0
$zd_16_y = 0
$zd_17_x = 0
$zd_17_y = 0
$zd_18_x = 0
$zd_18_y = 0
$zd_19_x = 0
$zd_19_y = 0
$zd_20_x = 0
$zd_20_y = 0
$zd_21_x = 0
$zd_21_y = 0
#编号为1-21的子弹的位置初始化
$atk_time = 0
#攻击冷却初始化
$fight_time = 20
#回合剩余时间初始化
$fight_over = 5
#剩余回合初始化
$enemy_hp = 40
#敌人HP初始化
###############################################################################
#此处补充内容:根据战斗场次设置伤害,并将其代人
$enemy_atk = 1
###############################################################################
end
end
def fight_2
if $zd_1_x = $actor_x
if $zd_1_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_2_x = $actor_x
if $zd_2_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_3_x = $actor_x
if $zd_3_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_4_x = $actor_x
if $zd_4_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_5_x = $actor_x
if $zd_5_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_6_x = $actor_x
if $zd_6_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_7_x = $actor_x
if $zd_7_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_8_x = $actor_x
if $zd_8_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_9_x = $actor_x
if $zd_9_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_10_x = $actor_x
if $zd_10_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_11_x = $actor_x
if $zd_11_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_12_x = $actor_x
if $zd_12_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_13_x = $actor_x
if $zd_13_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_14_x = $actor_x
if $zd_14_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_15_x = $actor_x
if $zd_15_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_16_x = $actor_x
if $zd_16_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_17_x = $actor_x
if $zd_17_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_18_x = $actor_x
if $zd_18_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_19_x = $actor_x
if $zd_19_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_20_x = $actor_x
if $zd_20_y = $actor_y
$actor_hp -= $enemy_atk
end
end
if $zd_21_x = $actor_x
if $zd_21_y = $actor_y
$actor_hp -= $enemy_atk
end
end
end
#显示移动自机
def fight_3
# 显示图片
myplane = Sprite.new
myplane.bitmap = RPG::Cache.picture("myplane")
myplane.ox = myplane.bitmap.width / 2
myplane.oy = myplane.bitmap.height / 2
myplane.x = $actor_x_
myplane.y = $actor_y_
end
def fight_4
#删除
myplane.dispose
end
end
alex = Fight.new
alex.fight_1
#Fight攻击系统、移动脚本在Game_Player中(关键词:ukyjthdgfs/mfejnhwn)
#disillusionment by planting bonudary
def fight_3
# 显示图片
@myplane = Sprite.new
@myplane.bitmap = RPG::Cache.picture("myplane")
@myplane.ox = @myplane.bitmap.width / 2
@myplane.oy = @myplane.bitmap.height / 2
@myplane.x = $actor_x_
@myplane.y = $actor_y_
end
def fight_4
#删除
@myplane.dispose
end
def fight_3
# 显示图片
@myplane = Sprite.new
@myplane.bitmap = RPG::Cache.picture("myplane")
@myplane.ox = @myplane.bitmap.width / 2
@myplane.oy = @myplane.bitmap.height / 2
@myplane.x = $actor_x_
@myplane.y = $actor_y_
end
def fight_4
#删除
@myplane.dispose
end
-
QQ截图20200318100317.png
(16.15 KB, 下载次数: 18)
-
QQ截图20200318101238.png
(14.96 KB, 下载次数: 15)
作者: 1095884734 时间: 2020-3-18 11:41
这是我这边测试的 你试试
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |