Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Csk_Parallax
- def self.parallax_sprite
- spr = Parallax_sprite.new
- $game_map.parallax_sprites << spr
- return spr
- end
- end
- class Parallax_Sprite
- attr_accessor :active, :visible, :filename, :opacity,
- :x, :y, :ox, :oy, :parallax_x, :parallax_y
- def initialize
- clear
- end
- def clear
- @active = false
- @visible = true
- @filename = ""
- @opacity = 255
- @x = 0
- @y = 0
- @z = -100000
- @ox = 0
- @oy = 0
- @parallax_x = 1.0
- @parallax_y = 1.0
- @sprite = nil
- @remove_x = 0
- @remove_y = 0
- end
- def setup(filename)
- @active = true
- @filename = filename
- @sprite ||= Sprite.new(@viewport)
- @sprite.bitmap = Cache.picture(@filename)
- @sprite.visible = @visible
- w = @sprite.bitmap.width
- h = @sprite.bitmap.height
- @sprite.x = @x - $game_map.display_x * @parallax_x * 32
- @sprite.y = @y - $game_map.display_y * @parallax_y * 32
- @sprite.z = @z
- @sprite.ox = @ox * w
- @sprite.oy = @oy * h
- @sprite.opacity = @opacity
- end
- def set_pos(x, y)
- @x = x
- @y = y
- end
- def set_origin(ox, oy)
- @ox = ox
- @oy = oy
- end
- def set_parallax(x, y)
- @parallax_x = x
- @parallax_y = y
- end
- def set_opacity(opacity)
- @opacity = opacity
- end
- def set_z(z)
- @z = z
- @sprite.z = @z unless @sprite == nil
- end
- def set_remove_pos(x, y)
- @remove_x = x
- @remove_y = y
- end
- def update
- if @sprite != nil
- @sprite.x = @x - $game_map.display_x * @parallax_x * 32
- @sprite.y = @y - $game_map.display_y * @parallax_y * 32
- @sprite.update unless @sprite
- @active = false if (@remove_x != 0 and @sprite.x < @remove_x)
- @active = false if (@remove_y != 0 and @sprite.y < @remove_y)
- end
- end
- end
- class Game_Map
- attr_reader :parallax_sprites
- alias csk_parallax_setup setup
- def setup(map_id)
- csk_parallax_setup(map_id)
- @parallax_sprites ||= []
- end
- alias csk_parallax_update update
- def update(*args)
- csk_parallax_update(*args)
- @parallax_sprites.each {|data|
- data.update
- @parallax_sprites.delete(data) unless data.active
- }
- end
- def parallax_sprite
- spr = Parallax_Sprite.new
- @parallax_sprites << spr
- return spr
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment