• Anmelden

1

Sonntag, 2. September 2012, 11:21

Charakter Schatten - Vriable Frames

Hi zusammen,

ich bin vor einiger Zeit auf dieses umwerfende Script gestoßen, dass sicher viele von euch bereits kennen.
Es wirft einen Charakter-Schatten abhängig von der besimmten Lichtquelle.
Ich habe ein kleines Problem, da ich in meinem Projekt 12-Frame-Chars benutze, der Schatten jedoch nur auf 4-Frames (Standart) eingestellt ist.
Da ich denke das Script hilft wirklich bei atmosphärischer Darstellung wäre ich sehr denkbar, wenn es nicht zu viel Arbeit ist, wenn
sich jemand die Mühe machen würde und mir jemand die Zeilen so umschreibt, dass der Schatten auch auf 12- Frames andwendbar ist.

Hier das Orginal-Script:

Ruby Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#==============================================================================
# ¡ Sprite_Shadow (Sprite_Ombre )
# Based on Genzai Kawakami's shadows, dynamisme&features by Rataime, extra features Boushy
#==============================================================================
 
CATERPILLAR_COMPATIBLE = true
 
class Game_Party
 attr_reader :characters
end
 
class Sprite_Shadow < RPG::Sprite
 
 attr_accessor :character
 
 def initialize(viewport, character = nil,source = nil,anglemin=0,anglemax=0,distancemax=0)
   super(viewport)
   @anglemin=anglemin.to_f
   @anglemax=anglemax.to_f
   @distancemax=distancemax.to_f
   @character = character
   @source = source
   update
 end
 
 def update
   super
 
   if @tile_id != @character.tile_id or
      @character_name != @character.character_name or
      @character_hue != @character.character_hue
     @tile_id = @character.tile_id
     @character_name = @character.character_name
     @character_hue = @character.character_hue
     if @tile_id >= 384
       self.bitmap = RPG::Cache.tile($game_map.tileset_name,
         @tile_id, @character.character_hue)
       self.src_rect.set(0, 0, 32, 32)
       self.ox = 16
       self.oy = 32
     else
       self.bitmap = RPG::Cache.character(@character.character_name,
         @character.character_hue)
       @cw = bitmap.width / 4
       @ch = bitmap.height / 4
       self.ox = @cw / 2
       self.oy = @ch
     end
   end
   self.visible = (not @character.transparent)
   if @tile_id == 0
     sx = @character.pattern * @cw
     sy = (@character.direction - 2) / 2 * @ch
     if self.angle>90 or angle<-90
       if @character.direction== 6
              sy = ( 4- 2) / 2 * @ch
       end
       if @character.direction== 4
              sy = ( 6- 2) / 2 * @ch
       end
       if @character.direction== 2
              sy = ( 8- 2) / 2 * @ch
       end
       if @character.direction== 8
              sy = ( 2- 2) / 2 * @ch
       end
     end
     self.src_rect.set(sx, sy, @cw, @ch)
   end
   self.x = @character.screen_x
   self.y = @character.screen_y-5
   self.z = @character.screen_z(@ch)-1
   self.opacity = @character.opacity
   self.blend_type = @character.blend_type
   self.bush_depth = @character.bush_depth
   if @character.animation_id != 0
     animation = $data_animations[@character.animation_id]
     animation(animation, true)
     @character.animation_id = 0
   end
   @deltax=@source.x-self.x
   @deltay= @source.y-self.y
   self.angle = 57.3*Math.atan2(@deltax, @deltay )
   @angle_trigo=self.angle+90
   if @angle_trigo<0
     @angle_trigo=360+@angle_trigo
   end
   self.color = Color.new(0, 0, 0)
   @distance = ((@deltax ** 2) + (@deltay ** 2))
   if$game_map.shadows==-1
     self.opacity = 0
   else
     self.opacity = 1200000/(@distance+6000)   
   end
   @distance = @distance ** 0.5
   if @distancemax !=0 and @distance>=@distancemax
     self.opacity=0
   end
   if @anglemin !=0 or @anglemax !=0
      if (@angle_trigo<@anglemin or @angle_trigo>@anglemax) and @anglemin<@anglemax
        self.opacity=0
      end
      if (@angle_trigo<@anglemin and @angle_trigo>@anglemax) and @anglemin>@anglemax
        self.opacity=0
      end    
   end
 end
end
 
#===================================================
# ¥ CLASS Sprite_Character edit
#===================================================
 
class Sprite_Character < RPG::Sprite
 alias shadow_initialize initialize
 
 def initialize(viewport, character = nil)
   @character = character
   super(viewport)
   @ombrelist=[]
   if (character.is_a?(Game_Event) and character.list!=nil and character.list[0].code == 108 and character.list[0].parameters == ["s"])
     if (character.list[1]!=nil and character.list[1].code == 108)
       @anglemin=character.list[1].parameters[0]
     end
     if (character.list[2]!=nil and character.list[2].code == 108)
       @anglemax=character.list[2].parameters[0]
     end
     if (character.list[3]!=nil and character.list[3].code == 108)
       @distancemax=character.list[3].parameters[0]
     end 
    for i in $game_map.events.keys.sort
     if ($game_map.events[i].is_a?(Game_Event) and $game_map.events[i].list!=nil and $game_map.events[i].list[0].code == 108 and $game_map.events[i].list[0].parameters == ["o"])
       @ombrelist[i+1] = Sprite_Shadow.new(viewport, $game_map.events[i],self,@anglemin,@anglemax,@distancemax)
     end
    end
    @ombrelist[1] = Sprite_Shadow.new(viewport, $game_player,self,@anglemin,@anglemax,@distancemax)
#===================================================
# œ Compatibility with fukuyama's caterpillar script
#===================================================
if CATERPILLAR_COMPATIBLE and $game_party.characters!=nil
 
 for member in $game_party.characters
   @ombrelist.push(Sprite_Shadow.new(viewport, member,self,@anglemin,@anglemax,@distancemax))
 end
 
end
#===================================================
# œ End of the compatibility
#===================================================
   end
   shadow_initialize(viewport, @character)
 end
 
 alias shadow_update update
 
 def update
   shadow_update
   if @ombrelist!=[]
     for i in 1..@ombrelist.size
       if @ombrelist[i]!=nil
         @ombrelist[i].update
       end
     end
   end
 end 
 
end
 
#===================================================
# ¥ CLASS Scene_Save edit
#===================================================
class Scene_Save < Scene_File
 
 alias shadows_write_save_data write_save_data
 
 def write_save_data(file)
   $game_map.shadows = nil
   shadows_write_save_data(file)
 end
end
 
#===================================================
# ¥ CLASS Game_Map edit
#===================================================
class Game_Map
 attr_accessor :shadows
end


Vielen Dank im Vorraus,

Als Gegenleistung kann ich gerne ein Musikstück komponieren (für denjenigen der geduldig genug ist mich kreativ werkeln zu lassen)
oder als Anreiz eine kleine Demo meiens Projekts hochladen um eine Notwendigkeit bzgl. Unterstützung vorzuweisen ;-)

Grüße Suirat

2

Sonntag, 2. September 2012, 13:54

In Zeile 44:

Ruby Quellcode

1
@cw = bitmap.width / 4


zu

Ruby Quellcode

1
@cw = bitmap.width / 12


Solltest du aber Charaktere verschiedener Frame-Anzahl benutzen, müsstest du schauen ob dein Script in irgendeiner Variable die Framezahl des jeweiligen Chars speichert. Poste das Script am besten hier, dann kann ich das nochmal entsprechend verbessern.
Terranigma 2 - Episode I - Open Beta out now!

RPC - Rpg-Maker Community Platform - Spielübergreifende Erfolge und mehr!

3

Sonntag, 2. September 2012, 14:27

Vielen Dank für die schnelle Antwort, ich hatte gehofft, dass es so einfach sein würde.Was natürlich immer noch ein kleines Problem ist sind die verschiedenen Frames versch. Charas, da hast du recht, dass wäre natürlich top, wenn das auch realtiv einfach zu ändern wäre...

Hier das Variable Frame Script:

Ruby Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#============================================================================
# ** Variable Character Frames Script (v1.0)
#============================================================================
# Idee und Ausführung: Der Drake, KD, Phantom, Ascare, RAMart.
# Niemand verlangt ein extra Credit dafür, ihr könnt es einfach benutzen.
#
# Benutzung: Einfach zum Dateinamen des Charakters ein f[x] einfügen. 
# Wobei x für die Anzahl der Frames steht (inkl. Standpose).
#
# Beispiele: Hero_f[8].png, Wachef[12]ani2.png, f[6]frau.png
# Standard ist 4 und brauch nicht extra genannt zu werden (z.B. für RTP-Charas).
#============================================================================
 
class Game_Character
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  alias_method :init, :initialize
  def initialize
    init
    getCharFrame
  end
  #--------------------------------------------------------------------------
  # * Get Character Frame
  #--------------------------------------------------------------------------
 def getCharFrame
  @CharFrame = 4
  self.character_name.sub(/f\[(\d+)\]/) { @CharFrame = $1.to_i }
  return @CharFrame
 end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Branch with jumping, moving, and stopping
    if jumping?
      update_jump
    elsif moving?
      update_move
    else
      update_stop
    end
    # If animation count exceeds maximum value
    # * Maximum value is move speed * 1 taken from basic value 18
    if @anime_count > 18 - @move_speed * 2
      # If stop animation is OFF when stopping
      if not @step_anime and @stop_count > 0
        # Return to original pattern
        @pattern = @original_pattern
        # If stop animation is ON when moving
      else
        # Update pattern
       if @CharFrame == 4
         @pattern = (@pattern + 1) % 4
        else
         @pattern = [((@pattern + 1) % @CharFrame), 1].max
       end
      end
      # Clear animation count
      @anime_count = 0
    end
    # If waiting
    if @wait_count > 0
      # Reduce wait count
      @wait_count -= 1
      return
    end
    # If move route is forced
    if @move_route_forcing
      # Custom move
      move_type_custom
      return
    end
    # When waiting for event execution or locked
    if @starting or lock?
      # Not moving by self
      return
    end
    # If stop count exceeds a certain value (computed from move frequency)
    if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
      # Branch by move type
      case @move_type
      when 1  # Random
        move_type_random
      when 2  # Approach
        move_type_toward_player
      when 3  # Custom
        move_type_custom
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Update frame (move)
  #--------------------------------------------------------------------------
  def update_move
    # Convert map coordinates from map move speed into move distance
    distance = 2 ** @move_speed
    # If logical coordinates are further down than real coordinates
    if @y * 128 > @real_y
      # Move down
      @real_y = [@real_y + distance, @y * 128].min
    end
    # If logical coordinates are more to the left than real coordinates
    if @x * 128 < @real_x
      # Move left
      @real_x = [@real_x - distance, @x * 128].max
    end
    # If logical coordinates are more to the right than real coordinates
    if @x * 128 > @real_x
      # Move right
      @real_x = [@real_x + distance, @x * 128].min
    end
    # If logical coordinates are further up than real coordinates
    if @y * 128 < @real_y
      # Move up
      @real_y = [@real_y - distance, @y * 128].max
    end
    # If move animation is ON
    if @walk_anime
      # Increase animation count by 1.5
      @anime_count += 1.5*(@CharFrame/4)
    # If move animation is OFF, and stop animation is ON
    elsif @step_anime
      # Increase animation count by 1
      @anime_count += 1*(@CharFrame/4)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (stop)
  #--------------------------------------------------------------------------
  def update_stop
    # If stop animation is ON
    if @step_anime
      # Increase animation count by 1
      @anime_count += 1*(@CharFrame/4)
    # If stop animation is OFF, but current pattern is different from original
    elsif @pattern != @original_pattern
      # Increase animation count by 1.5 /
      # by Mikko: Ich habs auf 1 gesetzt dadurch wird die Anitmation flüssig
      @anime_count += 1*(@CharFrame/4)
    end
    # When waiting for event execution, or not locked
    # * If lock deals with event execution coming to a halt
    unless @starting or lock?
      # Increase stop count by 1
      @stop_count += 1
    end
  end
end
 
class Sprite_Character < RPG::Sprite
 
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If tile ID, file name, or hue are different from current ones
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue
      # Remember tile ID, file name, and hue
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      # If tile ID value is valid
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue)
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      # If tile ID value is invalid
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @CharFrame = @character.getCharFrame
        @cw = bitmap.width / @CharFrame
        @ch = bitmap.height / 4
        self.ox = @cw / 2
        self.oy = @ch
      end
    end
    # Set visible situation
    self.visible = (not @character.transparent)
    # If graphic is character
    if @tile_id == 0
      # Set rectangular transfer
      sx = @character.pattern * @cw
      sy = (@character.direction - 2) / 2 * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    # Set sprite coordinates
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    # Set opacity level, blend method, and bush depth
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    # Animation
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end
# Zusatz von RedLink um FehlAnzeigen in Menüs etc. zu vermeiden
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================
 
class Window_Base < Window
   def getCharFrame(actor)
  actor.character_name.sub(/f\[(\d+)\]/) { @CharFrame = $1.to_i }
  return @CharFrame
 end
  def draw_actor_graphic(actor, x, y)
  if @CharFrame == nil
    @CharFrame = 4
  end  
    getCharFrame(actor)
    bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
    cw = bitmap.width / @CharFrame
    ch = bitmap.height / 4
    src_rect = Rect.new(0, 0, cw, ch)
    self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
 
  end
end

4

Sonntag, 2. September 2012, 14:39

Probiers mal mit:

Ruby Quellcode

1
2
@CharFrame = @character.getCharFrame
        @cw = bitmap.width / @CharFrame
Terranigma 2 - Episode I - Open Beta out now!

RPC - Rpg-Maker Community Platform - Spielübergreifende Erfolge und mehr!

5

Sonntag, 2. September 2012, 20:42

Klappt hervorragend, Vielen Dank!
Wenn du mal in irgendiner Richtung Hilfe benötigst und ich dessen mächtig bin, melde dich.

Gruss Suirat