Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Need Help fixing image disposal

Here's what I have (it's taken from a demo I played Utopian Chaos I believe), then I added some stuff. Right now the bullets from one character (basically a visual display of their SP) and the combo display for the enemies won't leave after battle. The combo display references the enemy sp. The sp increases as they take a hit and resets to 0 when it's their turn.
Two other problems...
1-the combo hits don't go away until some time passes during battle (though they never leave outside of battle), so there're numbers overlapping eachother.
2-A similar thing seems to happen with the bullets, it doesn't seem that big a deal because the bullets stay in the same place, but because the 'empty slots' for the bullets have a lot of alpha/transparency goin on, they get darker and lighter whenever a skill is used. For some reason this issue concerning the bullets is a recent occurence and I don't know why. I can't remeber really messing with that part of the code once I had it perfect.

class Window_BattleStatus < Window_Base
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
def initialize
super(0, 320, 480, 162)
self.opacity = 0
@windows = []
@faces = []
@ubullets = []
@ubullets = []
@combohits = []
viewport = Viewport.new(3, 320, 640, 162)
viewport.z = 101

for i in 0...$game_party.actors.size
y = i * 54 + 1 # (4 - $game_party.actors.size) #- 15 #* 60
@windows = Window_ActorStatus.new(i, i * 54 + 318)
@faces = Sprite.new(viewport)
@faces.bitmap = RPG::Cache.picture("Face" + $game_party.actors.id.to_s + ".png")
@faces.y = y
@faces.opacity = 250
end




@level_up_flags = [false, false, false, false]
refresh
end
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
def update
super
for window in @windows
window.update
end
end
#--------------------------------------------------------------------------
# ● Dispose
#--------------------------------------------------------------------------
def dispose
super
for i in 0...$game_party.actors.size
@windows.dispose
@faces.dispose
end

for i in 0...$game_troop.enemies.size
@combohits.dispose
end

#for i in 0...$data_actors[3].parameters[1,1]
# @ubullets.dispose
#end

#for i in 0...$game_actors[3].sp
# @bullets.dispose
#end
super
end
#--------------------------------------------------------------------------
# ● Refresh
#--------------------------------------------------------------------------
def refresh(number = 0)

for i in 0...$game_troop.enemies.size
@enemy = $game_troop.enemies
viewportz = Viewport.new(0, 0, 600, 600)
viewportz.z = @enemy.screen_z
y = @enemy.screen_y - 26
x = @enemy.screen_x - 60
z = @enemy.screen_z - 100
@combohits = Sprite.new(viewportz)
if @enemy.sp < 10
@combohits.bitmap = RPG::Cache.picture("combohit" + @enemy.sp.to_s + ".png")
@combohits.x = x
@combohits.y = y
@combohits.z = z
@combohits.opacity = 255
end
end


if number == 0
count = 0
for window in @windows
window.refresh(@level_up_flags[count])
count += 1
end
else
@windows[number - 1].refresh(@level_up_flags[number - 1])
end
end
#--------------------------------------------------------------------------
# ● AT Refresh
#--------------------------------------------------------------------------
def at_refresh(number = 0)
if number == 0
for window in @windows
window.at_refresh
end
else
@windows[number - 1].at_refresh
end
end
end

#==============================================================================
# â–  Window_ActorStatus
#==============================================================================

class Window_ActorStatus < Window_Base
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
#def initialize(id, x)
# @id = id
# super(x, 320, 160, 160)
# self.contents = Bitmap.new(width - 32, height - 32)
# self.back_opacity = 255
# actor = $game_party.actors[@id]
# @name = actor.name
# @maxhp = actor.maxhp
# @maxsp = actor.maxsp
# @hp = actor.hp
# @sp = actor.sp
# @state = make_battler_state_text(actor, 120, true)
# @windows = []
# for i in 0...5
# @windows.push(Window_DetailsStatus.new(actor, i, x))
# end
# refresh(false)
#end

def initialize(id, y)
@id = id
super(0, y, 480, 54)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = 255
actor = $game_party.actors[@id]
@name = actor.name
@maxhp = actor.maxhp
@maxsp = actor.maxsp
@hp = actor.hp
@sp = actor.sp
@state = make_battler_state_text(actor, 120, true)
@windows = []
for i in 0...5
@windows.push(Window_DetailsStatus.new(actor, i, x, y))
end
refresh(false)
end



#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
def update
for window in @windows
window.update
end
end
#--------------------------------------------------------------------------
# ● Dispose
#--------------------------------------------------------------------------
def dispose
for window in @windows
window.dispose
end
super
end
#--------------------------------------------------------------------------
# ● Refresh
#--------------------------------------------------------------------------
def refresh(level_up_flags)
self.contents.clear
actor = $game_party.actors[@id]
@windows[0].refresh(actor) if @name != actor.name
@windows[1].refresh(actor) if @maxhp != actor.maxhp or @hp != actor.hp
@windows[2].refresh(actor) if @maxsp != actor.maxsp or @sp != actor.sp
@windows[3].refresh(actor, level_up_flags) if
(@state != make_battler_state_text(actor, 120, true) or level_up_flags)
@name = actor.name
@maxhp = actor.maxhp
@maxsp = actor.maxsp
@hp = actor.hp
@sp = actor.sp
@state = make_battler_state_text(actor, 120, true)
end
#--------------------------------------------------------------------------
# ● AT Refresh
#--------------------------------------------------------------------------
def at_refresh
@windows[4].refresh($game_party.actors[@id])
end
end

#==============================================================================
# â–  Window_DetailsStatus
#==============================================================================

class Window_DetailsStatus < Window_Base
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
#def initialize(actor, id, x)
# @status_id = id
# super(x, 320 + id * 26, 160, 64)
# self.contents = Bitmap.new(width - 32, height - 32)
# #self.contents.font.name = $fontface
# #self.contents.font.size = $fontsize
# self.opacity = 0
# self.back_opacity = 0
# refresh(actor, false)
#end

def initialize(actor, id, x, y)
@status_id = id
super(x - 20, y - 17, 500, 90) #individual window viewport/bitmap (dunno the real name)
self.contents = Bitmap.new(width - 32, height - 32)
#self.contents.font.name = $fontface
#self.contents.font.size = $fontsize
self.opacity = 0
self.back_opacity = 0
refresh(actor, false)
end
#--------------------------------------------------------------------------
# ● Refresh
#--------------------------------------------------------------------------
def refresh(actor, level_up_flags = false)
self.contents.clear



#for i in 0...$game_troop.enemies.size
#@enemy = $game_troop.enemies
#@percent = (@enemy.hp * 100) / @enemy.maxhp
#unless @enemy.hp == 0
#draw_slant_bar(@enemy.screen_x - 55, @enemy.screen_y - 10, @enemy.hp, @enemy.maxhp, width = 75, height = 6, bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
#self.contents.draw_text(@enemy.screen_x - 39, @enemy.screen_y - 22, 100, 32, "#{@percent}" + "%")
#end



case @status_id
when 0
draw_actor_name(actor, 9, -1)
when 1
self.contents.font.size = 34
#self.contents.font.bold = true
draw_actor_hp(actor, 180, 5, 100)
when 2
if actor.id == 1
draw_actor_sp(actor, 320, 19, 145)
end

if actor.id == 2
armorz = $data_actors[actor.id].armor3_id
self.contents.font.color = normal_color
self.contents.font.size = 21
self.contents.draw_text(320, 20, 220, 18, $data_armors[armorz].name)
end

if actor.id == 3
# draw_bullets
#end

@bullets = []
@ubullets = []
viewport = Viewport.new(3, 302, 640, 180)
viewport.z = 101



for i in 0...$data_actors[3].parameters[1,1]
y = actor.index * 54 + 29
@ubullets = Sprite.new(viewport)
@ubullets.bitmap = RPG::Cache.picture("ubullet.png")
@ubullets.x = i * 20 + 325
@ubullets.y = y
@ubullets.z = 9999
@ubullets.opacity = 255
end

for i in 0...$game_actors[3].sp
@bullets = Sprite.new(viewport)
@bullets.bitmap = RPG::Cache.picture("sbullet.png")
@bullets.x = i * 20 + 325
@bullets.y = y
@bullets.z = 10000
@bullets.opacity = 255
end
end

when 3
if level_up_flags
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 120, 32, "LEVEL UP!")
else
#draw_actor_state(actor, 4, 0)
end
when 4
draw_actor_atg(actor, 170, 24, 120)
end
end
end





#==============================================================================
# â–  Window_Base
#==============================================================================

class Window_Base

#--------------------------------------------------------------------------
# ● Draw Actor HP Meter
#--------------------------------------------------------------------------
#alias cbs_draw_actor_hp draw_actor_hp
#def draw_actor_hp(actor, x, y, width = 146, height = 5)
# bg = Color.new( 0, 0, 0, 160)
# c1 = Color.new(175, 0, 0, 160)
# c2 = Color.new(255, 0, 0, 255)
# self.contents.fill_rect(x, y, width, height, bg)
# width2 = width * actor.hp / actor.maxhp
# gradient(x + 1, y + 1, width2 - 2, height - 2, c1, c2)
# cbs_draw_actor_hp(actor, x, y, width)
#end
#--------------------------------------------------------------------------
# ● Draw Actor SP Meter
#--------------------------------------------------------------------------
alias cbs_draw_actor_sp draw_actor_sp
def draw_actor_sp(actor, x, y, width = 146, height = 15)
bg = Color.new( 0, 0, 0, 160)
c1 = Color.new( 0, 174, 225, 255)
c2 = Color.new( 255, 255, 255, 255)
self.contents.fill_rect(x, y, width, height, bg)
width2 = width * actor.sp / actor.maxsp
gradient(x + 1, y + 1, width2 - 2, height - 2, c1, c2)
cbs_draw_actor_sp(actor, x, y, width)
end
#--------------------------------------------------------------------------
# ● Draw Gradient
#--------------------------------------------------------------------------
def gradient(x, y, width, height, c1, c2)
for i in 1..width
x2 = x + i - 1
r = c1.red * (width - i) / width + c2.red * i / width
g = c1.green * (width - i) / width + c2.green * i / width
b = c1.blue * (width - i) / width + c2.blue * i / width
a = c1.alpha * (width - i) / width + c2.alpha * i / width
self.contents.fill_rect(x2, y, 1, height, Color.new(r, g, b, a))
end
end
#--------------------------------------------------------------------------
# ● Make State Text
#--------------------------------------------------------------------------
def make_battler_state_text(battler, width, need_normal)
brackets_width = self.contents.text_size("Status: ").width
text = ""
for i in battler.states
if $data_states.rating >= 1
if text == ""
text = $data_states.name
else
new_text = text + "/" + $data_states.name
text_width = self.contents.text_size(new_text).width
if text_width > width - brackets_width
break
end
text = new_text
end
end
end
if text == ""
if need_normal
text = "Status: Normal"
end
else
#text = "Status: " + text + $game_variables[26 + battler.index].to_s
#text = "Combo: " + battler.sp.to_s
text = " [" + text + "]"
end
return text
end
end


PS
Sorry I don't know the command to put the text in the spoiler into 'code' mode.
 
Just a BUMP!

EDIT

LOL! Ok part of it was obvious... I was creating a new sprite each time instead of a new bitmap. So now the images aren't overlapping anymore and that's awesome, however they still remain after battle. Any help would be appreciated!
Have fun,
-K
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top