irpg Community
ช่วยหน่อยครับเรื่องแถบ exp (Script HUD ของ mog hunter) - Printable Version

+- irpg Community (https://irpg.in.th)
+-- Forum: irpg Fabella RPG Maker Academia (https://irpg.in.th/forum-4.html)
+--- Forum: RPG Maker Engine School (https://irpg.in.th/forum-7.html)
+--- Thread: ช่วยหน่อยครับเรื่องแถบ exp (Script HUD ของ mog hunter) (/thread-637.html)



ช่วยหน่อยครับเรื่องแถบ exp (Script HUD ของ mog hunter) - XthemeCore - 10-13-2012

ต้องขอโทษทุกท่านด้วยครับที่มาขาดๆหายๆ
วันนี้มีคำถามอยากขอความช่วยเหลือหน่อยครับ
คือจากภาพด้านล่างนี้

[Image: asdasdd_zpsdd6afabd.png]

ผมกำลังทำแถบ exp สำหรับเกมครับโดย mo จาก HUD ของ mog hunter
ทีนี้ผมทำแถบ exp 2 แถบ โดยแถบซ้ายเป็น exp ของเรา ส่วนแถบขวาเป็น exp ของนคร
ผมอยากให้แถบขวาเพิ่มจากขวาไปซ้ายครับ จากที่เห็นในภาพจะเพิ่มจากซ้ายไปขวาทั้งสองแถบครับ
ไม่รู้ทำไงดีเลยแนบ script บางส่วนมาให้ครับ (ตัดมาเฉพาะส่วนของ exp ของนครนะครับ)

[shcode=rails]
#==============================================================================
# Game_Actor
#==============================================================================
class Game_Actor < Game_Battler

#--------------------------------------------------------------------------
# * Now Exp
#--------------------------------------------------------------------------
def now_exp
return @exp - @exp_list[@level]
end

#--------------------------------------------------------------------------
# * Next Exp
#--------------------------------------------------------------------------
def next_exp
return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
end
end

class HUD < Sprite
#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
@civil = $game_party.actors[1]
return if @civil == nil
@civil_level = @civil.level
@civil_exp = @civil.exp


# CIVILIZATION LEVEL METER
@civil_level_image = RPG::Cache.windowskin("C_Exp_Meter")
@civil_level_bitmap = Bitmap.new(@civil_level_image.width,@civil_level_image.height)
@civil_level_sprite = Sprite.new
civil_rate = @civil.now_exp.to_f / @civil.next_exp
civil_rate = 1 if @civil.next_exp == 0
@civil_level_cw = @civil_level_image.width * civil_rate
@civil_level_cw = @civil_level_image.width if @civil.level == 99
@civil_level_src_rect_back = Rect.new(0, 0,@civil_level_cw, @civil_level_image.height)
@civil_level_bitmap.blt(0,0, @civil_level_image, @civil_level_src_rect_back)
@civil_level_sprite.bitmap = @civil_level_bitmap
@civil_level_sprite.z = 5001
@civil_level_sprite.x = CIVIL_LEVEL_METER[0] + HUD_X
@civil_level_sprite.y = CIVIL_LEVEL_METER[1] + HUD_Y
end

def update
civil_exp_update if @civil_exp != @civil.exp
end
end

#--------------------------------------------------------------------------
# * Civilization_exp_update
#--------------------------------------------------------------------------
def civil_exp_update
@civil_level_sprite.bitmap.clear
civil_rate = @civil.now_exp.to_f / @civil.next_exp
civil_rate = 1 if @civil.next_exp == 0
@civil_level_cw = @civil_level_image.width * civil_rate
@civil_level_cw = @civil_level_image.width if @civil.level == 99

@civil_level_src_rect_back = Rect.new(0, 0,@civil_level_cw, @civil_level_image.height)
@civil_level_bitmap.blt(0,0, @civil_level_image, @civil_level_src_rect_back)
@civil_exp = @civil.exp
end
[/shcode]

ช่วยหน่อยนะครับ


RE: ช่วยหน่อยครับเรื่องแถบ exp (Script HUD ของ mog hunter) - Muge9thD - 10-13-2012

ลองเอาไปเทสดูฮะ บอกผลด้วยเน้อว์ >w<//
[shcode=rails]#==============================================================================?
# Game_Actor
#====================================================================?==========
class Game_Actor < Game_Battler

#--------------------------------------------------------------------------
# * Now Exp
#--------------------------------------------------------------------------
def now_exp
return @exp - @exp_list[@level]
end

#--------------------------------------------------------------------------
# * Next Exp
#--------------------------------------------------------------------------
def next_exp
return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
end
end

class HUD < Sprite
#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
@civil = $game_party.actors[1]
return if @civil == nil
@civil_level = @civil.level
@civil_exp = @civil.exp


# CIVILIZATION LEVEL METER
@civil_level_image = RPG::Cache.windowskin("C_Exp_Meter")
@civil_level_bitmap = Bitmap.new(@civil_level_image.width,@civil_level_image.height)
@civil_level_sprite = Sprite.new
civil_rate = @civil.now_exp.to_f / @civil.next_exp
civil_rate = 1 if @civil.next_exp == 0
@civil_level_cw = @civil_level_image.width * civil_rate
@civil_level_cw = @civil_level_image.width if @civil.level == 99
@civil_level_src_rect_back = Rect.new(0, 0,@civil_level_cw, @civil_level_image.height)
@civil_level_bitmap.blt(@civil_level_image.width - @civil_level_cw ,0, @civil_level_image, @civil_level_src_rect_back)
@civil_level_sprite.bitmap = @civil_level_bitmap
@civil_level_sprite.z = 5001
@civil_level_sprite.x = CIVIL_LEVEL_METER[0] + HUD_X
@civil_level_sprite.y = CIVIL_LEVEL_METER[1] + HUD_Y
end

def update
civil_exp_update if @civil_exp != @civil.exp
end
end

#--------------------------------------------------------------------------
# * Civilization_exp_update
#--------------------------------------------------------------------------
def civil_exp_update
@civil_level_sprite.bitmap.clear
civil_rate = @civil.now_exp.to_f / @civil.next_exp
civil_rate = 1 if @civil.next_exp == 0
@civil_level_cw = @civil_level_image.width * civil_rate
@civil_level_cw = @civil_level_image.width if @civil.level == 99

@civil_level_src_rect_back = Rect.new(0, 0,@civil_level_cw, @civil_level_image.height)
@civil_level_bitmap.blt(@civil_level_image.width - @civil_level_cw,0, @civil_level_image, @civil_level_src_rect_back)
@civil_exp = @civil.exp
end [/shcode]
น่าจะไม่มีปัญหาPoker Face


RE: ช่วยหน่อยครับเรื่องแถบ exp (Script HUD ของ mog hunter) - XthemeCore - 10-13-2012

ขอบคุณครับ คุณ Muge9thD

ตรง @civil_level_src_rect_back = Rect.new(0, 0,@civil_level_cw, @civil_level_image.height)

ผมแก้ x = 0 เป็น @civil_level_image.width - @civil_level_cw ด้วยครับ
มันจะเริ่มจากปลายพอดี

[Image: qweqwe_zpsdab090fc.png]

ขอบคุณครับ