Fórum iBlue
Uso de Animações no Mapa(Animations 2.0) Buddy_Group

Bem Vindos ao iBlue GAMES!

Registre-se para obter acesso especial em todo conteúdo presente no Fórum!
Tenha um bom uso do nosso fórum, e seja ativo!





Fórum iBlue
Uso de Animações no Mapa(Animations 2.0) Buddy_Group

Bem Vindos ao iBlue GAMES!

Registre-se para obter acesso especial em todo conteúdo presente no Fórum!
Tenha um bom uso do nosso fórum, e seja ativo!





Somos ÚNICOS, somos o SEU fórum


Você não está conectado. Conecte-se ou registre-se

Ver o tópico anterior Ver o tópico seguinte Ir para baixo  Mensagem [Página 1 de 1]

T-Lord

1Uso de Animações no Mapa(Animations 2.0) Empty Uso de Animações no Mapa(Animations 2.0) Seg 31 Dez 2012 - 18:26

T-Lord
Administrador
Uso de Animações no Mapa(Animations 2.0)
Autor: Trickster

Tópico Original

Tradução: Gabriel Winchester
Altamente recomendado que você analise a Demo. Lá, exemplos de usos são claros e objetivos.

►Introdução

Este script permite mostrar uma animação em qualquer ponto da tela(x,y) ou
qualquer tile para evitar o uso de eventos em branco apenas para
servir de marcas para animação.

►Instruções
Adicione acima do main

Chamando
$animations.push(Animation.new(type,x,y,id[,loop,sound,viewport]))
qualquer coisa entre as chaves é opcional
#as chaves nao devem ser escritas, são apenas para demonstrar o que é opicional.
type é o tipo de permanencia na tela:
1 ou 'screen' segue o jogador na tela
2 ou 'tile' fica em um tile definido(x,y)
3 ou 'map' fica em um (x,y) definido no mapa
4 ou 'player' segue o jogador (x,y) define a centralizaçao
5 ou 'event' segue um evento (use parametro x para id e [x,y] para centralizar)
id é a id da animaçao

Opcional
loop é o numero de vezes que a anim é executada
mude para nil => animaçao infinita
valor padrão é 1
sound => true fará com que o som da animaçao seja executado
false fara com que nenhum som seja executado
valor padrão é true
viewport é o viewport das animaçoes. o padrão é a tela

► Scripts(cole na ordem postada)


Spoiler :


Código: [Tens de ter uma conta e sessão iniciada para poderes visualizar este link]=begin
┌──────────────────────────────────────┐
│● Display Animations 2.0 │
│ │
│ Created By │
│ │
│ Trickster (tricksterguy@hotmail.com)│
│ │
│ │
└──────────────────────────────────────┘

Tradução : Gabriel Winchester

►Introdução

Este script permite mostrar uma animação em qualquer ponto da tela(x,y) ou
qualquer tile para evitar o uso de eventos em branco apenas para
servir de marcas para animação.

►Instruções
Adicione acima do main

Chamando
$animations.push(Animation.new(type,x,y,id[,loop,sound,viewport]))
qualquer coisa entre as chaves é opcional
type é o tipo de permanencia na tela:
1 ou 'screen' segue o jogador na tela
2 ou 'tile' fica em um tile definido(x,y)
3 ou 'map' fica em um (x,y) definido no mapa
4 ou 'player' segue o jogador (x,y) define a centralizaçao
5 ou 'event' segue um evento (use parametro x para id e [x,y] para centralizar)
id é a id da animaçao

Opcional
loop é o numero de vezes que a anim é executada
mude para nil => animaçao infinita
valor padrão é 1
sound => true fará com que o som da animaçao seja executado
false fara com que nenhum som seja executado
valor padrão é true
viewport é o viewport das animaçoes. o padrão é a tela
=end


#==============================================================================
# ** Animação
#------------------------------------------------------------------------------
# This class displays an animation, it can be displayed at any (x,y) rather than
# using the show animation event command and being restricted to displaying it
# on an event.
#==============================================================================
class Animation
#--------------------------------------------------------------------------
# * Static (Class) Variables
#--------------------------------------------------------------------------
@@animations = []
@@reference_count = {}
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor Mad
attr_accessor :y
attr_accessor :z
attr_accessor :ox
attr_accessor :oy
attr_accessor :loop
attr_accessor :sound
attr_accessor :flash
attr_accessor :hit
attr_accessor :viewport
attr_accessor :visible
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(type, x, y, id, loop = 1, sound = true, flash = true, hit = true,
viewport = nil)
# Setup Type of Animation Display
@type = type
# Initialize Offset X and Offset Y and Z
@ox, @oy, @z = 0,0,2000
# Set Visiblility to true
@visible = true
# Branch Out According to Type
case type
when 'screen','map',1,3
# When Screen or Map or 1 or 3 Set X and Y to given coordinates
@x, @y = x, y
when 'tile',2
# When Tile or 2 Set X and Y to real coordinates
# Convert Tile coordinates to Screen coordinates
@x, @y = (x % $game_map.width) * 128, (y % $game_map.height) * 128
when 'player',4
# When Player or 4 Set Offset X and Y to Coordinates Given
@battler = $game_player
@ox, @oy = x, y
when 'event',5
# When Event or 5 Set Offset X and Y to The Y Given (An Array)
@battler = $game_map.events[x]
@ox, @oy = *y
end
# Get Animation
@animation = $data_animations[id]
# If animation is nil then return
return if @animation.nil?
# Initialize looping sound and viewport
@loop, @sound, @viewport = loop, sound, viewport
# If there is no battler then hit is false
@hit = @battler == nil ? false : hit
# Initialize Animation
animation
end
#--------------------------------------------------------------------------
# * Animation Initialize
#--------------------------------------------------------------------------
def animation
# Dispose any old Animation
dispose_animation
# Setup Duration
@animation_duration = @animation.frame_max
# Get Animation Name and Hue
animation_name = @animation.animation_name
animation_hue = @animation.animation_hue
# Get Animation Bitmap
bitmap = RPG::Cache.animation(animation_name, animation_hue)
# Increase or Setup Reference Count for Bitmap
if @@reference_count.include?(bitmap)
@@reference_count[bitmap] += 1
else
@@reference_count[bitmap] = 1
end
# Setup Animation Sprites
@animation_sprites = []
# Prevent Duplicate Screen Animations from being played
if @animation.position != 3 or not @@animations.include?(@animation)
16.times do |i|
sprite = ::Sprite.new(self.viewport)
sprite.bitmap = bitmap
sprite.visible = false
@animation_sprites[i] = sprite
end
@@animations << @animation unless @@animations.include?(@animation)
end
# Update Animation
update_animation
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
# If Animation is not equal to nil and 2 frames has passed
if @animation != nil and (Graphics.frame_count % 2 == 0)
# Decrease Duration
@animation_duration -= 1
# Update animation
update_animation
end
# Clear Animations
@@animations.clear
end
#--------------------------------------------------------------------------
# * Update Animation
#--------------------------------------------------------------------------
def update_animation
# If Duration is Greater than zero or Indefinite Loop Or Looping
if @animation_duration > 0 or @loop.nil? or @loop > 1
# If Duration is Zero (For Looping)
if @animation_duration == 0
# Reset Animation Duration and Decrease Loops if not an Indefinite Loop
@animation_duration = @animation.frame_max
@loop -= 1 if !@loop.nil?
end
# Get Frame Index cell_data and position
frame_index = @animation.frame_max - @animation_duration
cell_data = @animation.frames[frame_index].cell_data
position = @animation.position
# Set Sprites for animation
animation_set_sprites(@animation_sprites, cell_data, position)
# Check Each Timing If at that frame then there is something that needs to
# Be done (Flash, Sound, etc..)
@animation.timings.each do |timing|
animation_process_timing(timing) if timing.frame == frame_index
end
else
# Dispose Animation
dispose_animation
end
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
dispose_animation
end
#--------------------------------------------------------------------------
# * Dispose Animation
#--------------------------------------------------------------------------
def dispose_animation
# Skip unless animations sprites is not nil (Array) and its not empty
return unless @animation_sprites != nil and not @animation_sprites.empty?
# Get a Sprite, Reduce Reference count, Dispose the bitmap if references
# are zero
sprite = @animation_sprites[0]
@@reference_count[sprite.bitmap] -= 1
sprite.bitmap.dispose if @@reference_count[sprite.bitmap] == 0
# Dispose Each Sprite
@animation_sprites.each {|sprite| sprite.dispose}
@animation_sprites.clear
@animation = nil
@disposed = true
end
#--------------------------------------------------------------------------
# * Disposed?
#--------------------------------------------------------------------------
def disposed?
return @disposed.nil? ? false : true
end
#--------------------------------------------------------------------------
# * Animation Set Sprites
#--------------------------------------------------------------------------
def animation_set_sprites(sprites, cell_data, position)
16.times do |i|
# Get Sprite and Pattern
sprite = sprites[i]
pattern = cell_data[i, 0]
# If Sprite is nil or Pattern is nil or -1
if sprite == nil or pattern == nil or pattern == -1
# Set Visibility to false unless sprite is nil
sprite.visible = false if sprite != nil
# Continue to Next Iteration
next
end
# Set Visibility
sprite.visible = self.visible
# Setup Source Rectangle
sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
# Branch According to Type
case @type
when 'tile','map',2,3
sprite.x = (self.x - $game_map.display_x + 3) / 4 + 16
sprite.y = (self.y - $game_map.display_y + 3) / 4 + 32
when 'screen',1
sprite.x = self.x
sprite.y = self.y
when 'player','event',4,5
sprite.x = @battler.screen_x + self.ox
sprite.y = @battler.screen_y + self.oy
end
# Increase X and Y depending on position placed
sprite.x += cell_data[i, 1]
sprite.y += cell_data[i, 2]
# Setup Z to Z of the animation (Def. 2000)
sprite.z = self.z
# Setup Sprite's Offset X and Y
sprite.ox = 96
sprite.oy = 96
# Setup Other Properties
sprite.zoom_x = cell_data[i, 3] / 100.0
sprite.zoom_y = cell_data[i, 3] / 100.0
sprite.angle = cell_data[i, 4]
sprite.mirror = (cell_data[i, 5] == 1)
sprite.opacity = cell_data[i, 6]
sprite.blend_type = cell_data[i, 7]
end
end
#--------------------------------------------------------------------------
# * Animation Process Timing
#--------------------------------------------------------------------------
def animation_process_timing(timing)
# If Sound Enabled and Timing Sound Effect name is not an empty string
if timing.se.name != "" and self.sound
se = timing.se
Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
end
return if not hit
# IF Current Scene is Scene_Map and Battler is not nil
if $scene.is_a?(Scene_Map) and @battler != nil
# Find the character
character = $scene.spriteset.find_character(@battler)
end
return if character == nil
# Branch our according to Flash Scope
case timing.flash_scope
when 1
# Flash the Character
character.flash(timing.flash_color, timing.flash_duration * 2)
when 2
# Flash the Characters Viewport
if character.viewport != nil
character.viewport.flash(timing.flash_color, timing.flash_duration * 2)
end
when 3
# Make the Character Invisible
character.flash(nil, timing.flash_duration * 2)
end
end
#--------------------------------------------------------------------------
# * Set X Coordinate
#--------------------------------------------------------------------------
def x=(x)
sx = @battler == nil ? x : x - @battler.screen_x
if sx != 0 and @animation_sprites != nil
@animation_sprites.each {|sprite| sprite.x += sx}
end
@x = sx
end
#--------------------------------------------------------------------------
# * Set Y Coordinate
#--------------------------------------------------------------------------
def y=(y)
sy = @battler == nil ? y : y - @battler.screen_y
if sy != 0 and @animation_sprites != nil
@animation_sprites.each {|sprite| sprite.y += sy}
end
@y = sy
end
end

class Scene_Map
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :spriteset
end

class Spriteset_Map
#--------------------------------------------------------------------------
# * Find Character
#--------------------------------------------------------------------------
def find_character(char)
@character_sprites.each do |character|
return character if character.character == char
end
end
end
Spoiler :
Código: [Tens de ter uma conta e sessão iniciada para poderes visualizar este link]$animations = []

class Scene_Map
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
alias animation_main main
def main
@animations = []
animation_main
($animations + @animations).each {|anim| anim.dispose}
$animations.clear
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias animation_update update
def update
$animations.each do |anim|
anim.update

http://www.zonetoony.net/
juan™

2Uso de Animações no Mapa(Animations 2.0) Empty Re: Uso de Animações no Mapa(Animations 2.0) Sáb 5 Jan 2013 - 10:04

juan™
Administrador
Obrigado por Compartilhar esse tutorial
coloce quote no codigo para ficar mais informado

http://www.zonetoony.net/
T-Lord
Administrador
É que eu fiquei sem tempo para postar!

http://www.zonetoony.net/

Ver o tópico anterior Ver o tópico seguinte Ir para o topo  Mensagem [Página 1 de 1]

Permissões neste sub-fórum
Não podes responder a tópicos