Animation Clipping Engineversion: 1.0
release date: 11
th January, 2013
system: RGSS // RPG Maker XP
IntroductionThis script allows you to decide whether an animation is confined inside enemies' battlers or not.
A picture can explain much better than words, though:
ScriptCODE
#==============================================================================
# ** Jens of Zanicuud's animation clipping script
#=============================================================================
# -version 1.0
# -free use, just credit
# -you can find me at www.rpgrevolution.com
# -snapshot script made by Keroro at www.rpg2s.net
#==============================================================================
#--------------------------------------------------------------------------
# * Customization
#--------------------------------------------------------------------------
MASK_ANIME = [1,2,101] #list of animation which have to be clipped
#--------------------------------------------------------------------------
# ** Graphics
#--------------------------------------------------------------------------
module Graphics
#--------------------------------------------------------------------------
# * Call Win32APIs
#--------------------------------------------------------------------------
RtlMoveMemory = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
BitBlt = Win32API.new('gdi32', 'BitBlt', 'iiiiiiiii', 'i')
CreateCompatibleBitmap = Win32API.new('gdi32', 'CreateCompatibleBitmap', 'iii', 'i')
CreateCompatibleDC = Win32API.new('gdi32', 'CreateCompatibleDC', 'i', 'i')
DeleteObject = Win32API.new('gdi32', 'DeleteObject', 'i', 'i')
GetDIBits = Win32API.new('gdi32', 'GetDIBits', 'iiiiipi', 'i')
SelectObject = Win32API.new('gdi32', 'SelectObject', 'ii', 'i')
SetDIBits = Win32API.new('gdi32', 'SetDIBits', 'iiiiipi', 'i')
hWnd = Win32API.new('user32', 'FindWindow', 'pp', 'i').call('RGSS Player', 0)
DC = Win32API.new('user32', 'GetDC', 'i', 'i').call(hWnd)
#--------------------------------------------------------------------------
# * snap_to_bitmap
#--------------------------------------------------------------------------
def Graphics.snap_to_bitmap(width=640, height=480)
bitmap = Bitmap.new(width, height)
RtlMoveMemory.call(address="\0"*4, bitmap.__id__*2+16, 4)
RtlMoveMemory.call(address, address.unpack('L')[0]+8, 4)
RtlMoveMemory.call(address, address.unpack('L')[0]+16, 4)
address = address.unpack('L')[0]
info = [40,width,height,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')
hDC = CreateCompatibleDC.call(DC)
hBM = CreateCompatibleBitmap.call(DC, width, height)
DeleteObject.call(SelectObject.call(hDC, hBM))
SetDIBits.call(hDC, hBM, 0, height, address, info, 0)
BitBlt.call(hDC, 0, 0, width, height, DC, 0, 0, 0xCC0020)
GetDIBits.call(hDC, hBM, 0, height, address, info, 0)
DeleteObject.call(hBM)
DeleteObject.call(hDC)
bitmap
end
end
#--------------------------------------------------------------------------
# ** Sprite
#--------------------------------------------------------------------------
class Sprite
#--------------------------------------------------------------------------
# ** Subtract_bitmap
#--------------------------------------------------------------------------
def subtract_bitmap(bmp, x, y)
for i in 0...bmp.width
for j in 0...bmp.height
color = bmp.get_pixel(i,j)
if color.alpha != 0
self.bitmap.set_pixel(x+i,y+j,Color.new(0,0,0,0))
end
end
end
return true
end
#--------------------------------------------------------------------------
# ** Create Background Mask
#--------------------------------------------------------------------------
def create_background_mask(battlers)
self.bitmap.dispose if self.bitmap != nil
self.bitmap = Graphics.snap_to_bitmap(640,320)
for battler in battlers
battler_bitmap = RPG::Cache.battler(battler.battler_name,0)
x = battler.screen_x - battler_bitmap.width/2
y = battler.screen_y - battler_bitmap.height
self.subtract_bitmap(battler_bitmap, x, y)
end
end
end
#==============================================================================
# ** Spriteset_Battle
#==============================================================================
class Spriteset_Battle
#--------------------------------------------------------------------------
# * Aliases
#--------------------------------------------------------------------------
alias cutin_anime_aliased_update update
alias cutin_anime_aliased_initialize initialize
alias cutin_anime_aliased_dispose dispose
#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------
def initialize
cutin_anime_aliased_initialize
@mask_sprite = RPG::Sprite.new(@viewport1)
@mask_sprite.z = 9999
@mask_sprite.visible = false
end
#--------------------------------------------------------------------------
# * dispose
#--------------------------------------------------------------------------
def dispose
cutin_anime_aliased_dispose
@mask_sprite.bitmap.dispose
@mask_sprite.dispose
end
#--------------------------------------------------------------------------
# * update
#--------------------------------------------------------------------------
def update
#check if mask sprite has been initialized yet
if !@mask_sprite.nil?
anim_actors = []
for actor in $game_troop.enemies
if actor.animation_id != 0 and MASK_ANIME.include?(actor.animation_id)
anim_actors.push(actor)
end
end
if !anim_actors.empty?
@mask_sprite.create_background_mask(anim_actors)
@mask_sprite.visible = true
else
if not self.effect?
@mask_sprite.visible = false
end
end
end
#do default update
cutin_anime_aliased_update
end
end
Terms of usefree use, just credit me for the script and Keroro for the
snap_to_bitmap function.
InstructionsPlace it in a blank above Main and it will work.
You can decide what animations have to be clipped and what not just filling the array named MASK_ANIME.
e.g. MASK_ANIME = [1,2,101]
means that animations 1, 2 and 101 will be clipped when applied to an enemy.
NotesThis script works only on enemies. In practice, it takes a snapshot of the battle background before the animation, cut the enemy picture from the snapshot and then put the cropped picture over the actual layer, "masking" the animation. That's the one way I succeeded in doing this, sorry

For large enemies or multiple targets, this could cause some lag.
Creditssnap_to_bitmap script by:
Keroro@http://www.rpg2s.net
Known IssuesThere shouldn't be any compatibility issues with Standard BS. For custom BS there's a high chance this won't work properly.
You're free to ask for a compatibility patch anytime.
Ask for troubleshooting anytime.
Jens of Zanicuud