Sujet n°11363
Posté par Zohran le 19 Avr - 00:15 (2012)
Titre : Problème utilisation GIF
Bonsoir, voilà en fait, d'après la méthode de Brendan, j'ai essayé d'utiliser les gifs pour les battlers mais sans succès, comment faut il faire? SVP


PS: Autre soucis que je n'arrive pas à résoudre, losque j'ouvre le menu statut des pokémons tout va bien mais lorsque je regarde le statut du pkmn suivant, c'est toujours le gif du premier qui reste, de l'aide svp?

Posté par Brendan75 le 20 Avr - 23:40 (2012)
Je ne peux pas t'aider pour l'intant car je n'ai pas mon ordinateur, le problème semble pourtant assez simple à réglé si tu t'intéresse un peu au fonctionnement de ce menu. Il faut que tu utilises "@sprite.setup("nom_fichier.gif")" pour mettre à jour l'image à afficher.

Posté par Zohran le 21 Avr - 16:10 (2012)
Ce qui me pose problème, c'est le viewport dans battle core 1, je le gère comment? (Merci de ta réponse)
Je suis content que tu m'aides, cela me permettra d'améliorer PSP DS et PSP 5G, je bosse sur le h mode 7 en ce moment, je crée des textures !

Posté par Brendan75 le 21 Avr - 22:26 (2012)
A priori, le script gère les viewport, quel est ton problème exactement ?

(mode 7, c'est le mal...)

Posté par Zohran le 21 Avr - 22:58 (2012)
Hi hi le mode 7 oui, mais bizarrement je me suis pris d'affection pour le hmode 7.


Sinon, bah à la ligne où il y a (de mémoire...) @enemy_sprite = RPG::Sprite.new(viewport)
j'ai remplacé par @enemy_sprite = GifSprite.new(viewport)


Ah moins qu'il faille mettre @enemy_sprite.setup ?


PS: Mis à part ton avis sur le H mode 7, malgré tout que pense tu des textures que j'ai commencé à faire? Le rendu?

Posté par Brendan75 le 22 Avr - 01:00 (2012)
La méthode, c'est new(fichier, viewport), si tu mets directement le viewport c'est normal que ça bugge.

Posté par Zohran le 22 Avr - 18:04 (2012)
J'ai un autre problème maintenant que j'ai oublier de mentionner, voici le log, c'est en confrontation avec une autre méthode, pourquoi?


LOG:
---------- Erreur de script : Pokemon_Battle_Wild* ----------
----- Version du logiciel : PSP DS v0.4
----- Type
NoMethodError


----- Message
- ARGS - []
undefined method `effect?' for #<GifSprite:0x99f09a0>


----- Position dans Pokemon_Battle_Wild*
Ligne 196


----- Backtrace
Script : Pokemon_Battle_Wild* | Ligne : 196 | Méthode : in `pre_battle_animation'
Script : Pokemon_Battle_Wild* | Ligne : 190 | Méthode : in `loop'
Script : Pokemon_Battle_Wild* | Ligne : 203 | Méthode : in `pre_battle_animation'
Script : Pokemon_Battle_Core 1* | Ligne : 229 | Méthode : in `main'
Script : Main | Ligne : 58





Posté par Nuri Yuri le 22 Avr - 18:07 (2012)
Fallait s'y attendre. Remplacer un objet d'une classe à un objet d'un autre classe provoque ce genre de problèmes.
RPG::Sprite est un enfant de Sprite et contient plus de méthodes comme celle qui fait planter ton projet. Tu dois faire en sorte à ce que ce soit compatible, t'as plusieurs choix pour.

Posté par Zohran le 22 Avr - 18:12 (2012)
Si j'ai bien compris, effect est une sous méthode appartenant à la méthode RPG::Sprite, donc je dois utiliser une autre méthode avec les gifs, qui sera semblable à effect mais propre aux gifs, c'est cela?


Lol, je crois que j'ai commencé à vraiment comprendre comment fonctionne les scripts ! Je crois que j'ai réussi à définir la méthode effect parce que j'ai plus le bug ! You ouh ! Et j'ai compris pourquoi brendan ma dit pour les viewports que c'est .new(file, viewport) car cette méthode est définie dans le script !

Posté par Brendan75 le 22 Avr - 21:35 (2012)
Eh bien, si mes scripts forment de nouveaux svripteurs, c'est génial. En effet ta méthode peut être viable, je ne te conseillerai que de tester et de voir.

Posté par Zohran le 22 Avr - 22:29 (2012)
Merci beaucoup, j'ai à nouveau un problème mais pas d'erreur script, en fait lors du combat, le gif est là, il s'anime, ça ok pas de pb, j'attaque le pkmn adverse et lors du lancement de l'animation de l'attaque, celle ci ne se finit pas et le jeu reste bloqué sans couper mais reste avec l'affichage bloqué de l'animation et de la phrase : Roucool lance Ouragan (comme si l'animation ne se finissait pas et qu'une boucle serait infini, pas de sortie de boucle, j'ai donc du oublier de définir quelque chose) HELP !!!!

Posté par Pαlвσlѕку le 22 Avr - 22:52 (2012)
Je pense aussi à une boucle infinie.

Par hasard, est-ce que lors de l'attaque tu as pensé à mettre le gif en pause ?
Si lors de l'attaque, ton Pokémon bouge et qu'en même temps tu as l'animation d'attaque, je peux comprendre qu'à un moment donné le jeu ne sait plus trop où il en est et se bloque.
Par chance, peut-on dire, ta boucle doit contenir un Graphics.update, ce qui expliquerait pourquoi ton écran se fige sans faire planter le jeu.

Je ne sais pas à quoi ressemble le code pour afficher des gifs et les modifications que tu as apporté, je ne peux donc pas t'aider d'avantage.

Posté par Zohran le 22 Avr - 22:53 (2012)
Ah, merci de ta réponse, je vais examiner cela et essayer de palier au problème ! Merci encore !


Je n'arrive pas à résoudre le problème malheureusement, peut-être que mes définitions ne sont pas totalement bonne... Voici ce que j'ai rajouté:


#==============================================================================  
# ■ GIF  
# D'après un script de Pokémon Essentials, adapté par Brendan75  
#-----------------------------------------------------------------------------  
#   Lecture de Fichier .GIF et animations.  
#==============================================================================  
class GifSprite < Sprite  
    
  #---------------------------------------------------------------------------  
  # ● Fonctions DLL  
  #---------------------------------------------------------------------------  
  GTPF   = Win32API.new("gif.dll", "GifToPngFiles", 'pp', 'l')  
  GTPFIM = Win32API.new("gif.dll", "GifToPngFilesInMemory", 'plp', 'l')  
  CDS    = Win32API.new("gif.dll", "CopyDataString", 'lpl', 'l')  
  FDS    = Win32API.new("gif.dll", "FreeDataString", 'l', '')  
    
  #---------------------------------------------------------------------------  
  # ● Variables Publiques  
  #---------------------------------------------------------------------------  
  attr_accessor :gifbitmaps  
  attr_accessor :gifdelays  
  
  #---------------------------------------------------------------------------  
  # ● Get Data From Result  
  #---------------------------------------------------------------------------  
  def getDataFromResult(result)  
    datasize = CDS.call(result, "", 0)  
    ret = nil  
    if datasize != 0  
      data = "0" * datasize  
      CDS.call(result, data, datasize)  
      ret = data.unpack("V*")  
    end  
    FDS.call(result)  
    return ret  
  end  
    
  #---------------------------------------------------------------------------  
  # ● Initialize  
  #---------------------------------------------------------------------------
  @@_animations = []
  @@_reference_count = {}
  def initialize(file, viewport = nil)  
    super(viewport)
    #
    @_whiten_duration = 0
    @_appear_duration = 0
    @_escape_duration = 0
    @_collapse_duration = 0
    @_damage_duration = 0
    @_animation_duration = 0
    @_blink = false
    @_reverse = false
    @_option = 0
    @_registered_x = 0
    @_registered_y = 0
    @_registered_ox = 0
    @_registered_oy = 0
    #
    @gifbitmaps   = []  
    @gifdelays    = []  
    @totalframes  = 0  
    @framecount   = 0  
    @currentIndex = 0  
    setup(file)  
    self.bitmap = Bitmap.new(@gifbitmaps[0].width, @gifbitmaps[0].height)  
    update  
  end  
    
  #---------------------------------------------------------------------------  
  # ● Setup  
  #---------------------------------------------------------------------------  
  def setup(file)  
    file = canonicalize(file)  
    if (filestring = File.open(file, "rb"){|f| f.read(1)})  
      filestrName = file  
    elsif (filestring =File.open(file + ".gif", "rb"){|f| f.read(1)})  
      filestrName = file + ".gif"  
    end  
    tmpBase = File.basename(file) + "_tmp_"  
    filestring = File.open(filestrName, "rb"){|f| f.read } if filestring  
    Dir.chdir(ENV["TEMP"]) do  
      result = GTPFIM.call(filestring, filestring.length, tmpBase)  
      @gifdelays = getDataFromResult(result)  
      @totalframes = @gifdelays.pop  
      for i in 0.. @gifdelays.length  
        @gifdelays = [@gifdelays[i][/i], 1].max  
        bmfile = sprintf("%s%d.png", tmpBase, i)  
        if FileTest.exist?(bmfile)  
          gifbitmap = Bitmap.new(bmfile)  
          @gifbitmaps.push(gifbitmap)  
          File.delete(bmfile)  
        else  
          @gifdelays.delete_at(i)  
        end  
      end  
    end  
  end  
    
  #---------------------------------------------------------------------------  
  # ● Update  
  #---------------------------------------------------------------------------  
  def update  
    super  
    if @gifbitmaps.length > 0  
      @framecount += 2  
      for i in 0.. @gifdelays.size-1  
        @currentIndex = i if @gifdelays <= @framecount % @totalframes  
      end  
    end  
    self.bitmap.clear  
    bitmap = @gifbitmaps[@currentIndex]  
    rect = Rect.new(0, 0, bitmap.width, bitmap.height)  
    self.bitmap.blt(0, 0, bitmap, rect)  
  end  
  #
  def effect?
      @_whiten_duration > 0 or
      @_appear_duration > 0 or
      @_escape_duration > 0 or
      @_collapse_duration > 0 or
      @_damage_duration > 0 or
      @_animation_duration > 0
  end
    
  def register_position
      @_registered_x = self.x
      @_registered_ox = self.ox
      @_registered_y = self.y
      @_registered_oy = self.oy
  end
    
  def animation(animation, hit, reverse = false)
      dispose_animation
      @_animation = animation
      return if @_animation == nil
      @_animation_hit = hit
      @_animation_duration = @_animation.frame_max
      animation_name = @_animation.animation_name
      animation_hue = @_animation.animation_hue
      bitmap = RPG::Cache.animation(animation_name, animation_hue)
      if @@_reference_count.include?(bitmap)
        @@_reference_count[bitmap] += 1
      else
        @@_reference_count[bitmap] = 1
      end
      @_animation_sprites = []
      if @_animation.position != 3 or not @@_animations.include?(animation)
        for i in 0..15
          sprite = ::Sprite.new(self.viewport)
          sprite.bitmap = bitmap
          sprite.visible = false          
          @_animation_sprites.push(sprite)
        end
        unless @@_animations.include?(animation)
          @@_animations.push(animation)
        end
      end
      @_reverse = reverse
      if animation.name.include?('/')
        split_list = animation.name.split('/')
        if split_list.length == 2
          if split_list[0].include?("R")
            @_option = 1
          end
          if split_list[0].include?("N")
            @_reverse = false
          end
          if split_list[0].include?("M")
            @_option = 2
          end
        end
      end
      update_animation
  end
    
  def dispose_animation
      if @_animation_sprites != nil
        sprite = @_animation_sprites[0]
        if sprite != nil
          @@_reference_count[sprite.bitmap] -= 1
          if @@_reference_count[sprite.bitmap] == 0
            sprite.bitmap.dispose
          end
        end
        for sprite in @_animation_sprites
          sprite.dispose
        end
        @_animation_sprites = nil
        @_animation = nil
      end
  end


  def update_animation
      if @_animation_duration > 0
        frame_index = @_animation.frame_max - @_animation_duration
        cell_data = @_animation.frames[frame_index].cell_data
        position = @_animation.position
        animation_set_sprites(@_animation_sprites, cell_data, position)
        for timing in @_animation.timings
          if timing.frame == frame_index
            animation_process_timing(timing, @_animation_hit)
          end
        end
      else
        dispose_animation
      end
  end
  
  def animation_set_sprites(sprites, cell_data, position)
      for i in 0..15
        sprite = sprites
        pattern = cell_data
        if sprite == nil or pattern == nil or pattern == -1
          sprite.visible = false if sprite != nil
          next
        end
        sprite.visible = true
        sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
        if position == 3
          if self.viewport != nil
            sprite.x = self.viewport.rect.width / 2
            sprite.y = self.viewport.rect.height - 160
          else
            sprite.x = 320
            sprite.y = 240
          end
        else
          sprite.x = self.x - self.ox + self.src_rect.width / 2
          sprite.y = self.y - self.oy + self.src_rect.height / 2
          sprite.y -= self.src_rect.height / 4 if position == 0
          sprite.y += self.src_rect.height / 4 if position == 2
        end
        sprite.x += cell_data
        sprite.y += cell_data
        sprite.z = 2000
        sprite.ox = 96
        sprite.oy = 96
        sprite.zoom_x = cell_data / 100.0
        sprite.zoom_y = cell_data / 100.0
        sprite.angle = cell_data
        sprite.mirror = (cell_data == 1)
        sprite.opacity = cell_data * self.opacity / 255.0
        sprite.blend_type = cell_data
      end
  end


  def animation_process_timing(timing, hit)
      if (timing.condition == 0) or
         (timing.condition == 1 and hit == true) or
         (timing.condition == 2 and hit == false)
        if timing.se.name != ""
          se = timing.se
          Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
        end
        case timing.flash_scope
        when 1
          self.flash(timing.flash_color, timing.flash_duration * 2)
        when 2
          if self.viewport != nil
            self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
          end
        when 3
          self.flash(nil, timing.flash_duration * 2)
        end
      end
  end
    
    def register_position
      @_registered_x = self.x
      @_registered_ox = self.ox
      @_registered_y = self.y
      @_registered_oy = self.oy
    end
    
    def reset_position
      self.x = @_registered_x
      self.ox = @_registered_ox
      self.y = @_registered_y
      self.oy = @_registered_oy
    end
    
    def animation(animation, hit, reverse = false)
      dispose_animation
      @_animation = animation
      return if @_animation == nil
      @_animation_hit = hit
      @_animation_duration = @_animation.frame_max
      animation_name = @_animation.animation_name
      animation_hue = @_animation.animation_hue
      bitmap = RPG::Cache.animation(animation_name, animation_hue)
      if @@_reference_count.include?(bitmap)
        @@_reference_count[bitmap] += 1
      else
        @@_reference_count[bitmap] = 1
      end
      @_animation_sprites = []
      if @_animation.position != 3 or not @@_animations.include?(animation)
        for i in 0..15
          sprite = ::Sprite.new(self.viewport)
          sprite.bitmap = bitmap
          sprite.visible = false          
          @_animation_sprites.push(sprite)
        end
        unless @@_animations.include?(animation)
          @@_animations.push(animation)
        end
      end
      @_reverse = reverse
      if animation.name.include?('/')
        split_list = animation.name.split('/')
        if split_list.length == 2
          if split_list[0].include?("R")
            @_option = 1
          end
          if split_list[0].include?("N")
            @_reverse = false
          end
          if split_list[0].include?("M")
            @_option = 2
          end
        end
      end
      update_animation
    end
        
    def animation_set_sprites(sprites, cell_data, position)
      # Cas Spécial : le sprite de mouvement du Pokémon
      sprite = sprites[15]
      pattern = cell_data[15, 0]
      jump = false
      if sprite == nil or pattern == nil or pattern == -1
        sprite.visible = false if sprite != nil
        jump = true
      end
      
      x_compensate = 0
      y_compensate = 0
      
      if not jump
        if position == 3
          if self.viewport != nil
            self.x = self.viewport.rect.width / 2
            self.y = self.viewport.rect.height - 160
          else
            self.x = 320
            self.y = 240
          end
        else
          self.x = @_registered_x
          self.y = @_registered_y
        end
        
        if @_reverse and position == 3
          self.x = 620 - self.x
          self.y = 440 - self.y #328 - self.y
          #self.ox = self.src_rect.width / 2
          #self.oy = self.src_rect.height / 2
        end
    
        if not @_reverse
          self.x += cell_data[15, 1]
          self.y += cell_data[15, 2]
          x_compensate -= cell_data[15, 1] if position != 3
          y_compensate -= cell_data[15, 2] if position != 3
        else
          self.x -= cell_data[15, 1]
          self.y -= cell_data[15, 2]
          x_compensate += cell_data[15, 1] if position != 3
          y_compensate += cell_data[15, 2] if position != 3
        end
        
      end
        
      for i in 0..14
        sprite = sprites
        pattern = cell_data
        if sprite == nil or pattern == nil or pattern == -1
          sprite.visible = false if sprite != nil
          next
        end
        
        sprite.visible = true
        sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
          
        if position == 3
          if self.viewport != nil
            sprite.x = self.viewport.rect.width / 2
            sprite.y = self.viewport.rect.height - 160
          else
            sprite.x = 320
            sprite.y = 240
          end
        else
          sprite.x = self.x - self.ox + self.src_rect.width / 2
          sprite.y = self.y - self.oy + self.src_rect.height / 2
          sprite.y -= self.src_rect.height / 4 if position == 0
          sprite.y += self.src_rect.height / 4 if position == 2
        end
        
        if @_reverse and position == 3
          sprite.x = 620 - sprite.x
          sprite.y = 328 - sprite.y
        end
        
        if not @_reverse
          sprite.x += cell_data + x_compensate
          sprite.y += cell_data + y_compensate
        else
          sprite.x -= cell_data - x_compensate
          sprite.y -= cell_data - y_compensate
        end
        
        sprite.z = 2000
        sprite.ox = 102
        sprite.oy = 58
        sprite.zoom_x = cell_data / 200.0
        sprite.zoom_y = cell_data / 200.0
        sprite.angle = cell_data
        if @_option == 1 and @_reverse
          sprite.angle += 180
        end
        sprite.mirror = (cell_data == 1)
        if @_option == 2 and @_reverse
          sprite.mirror = (sprite.mirror == false)
        end
        sprite.opacity = cell_data * self.opacity / 255.0
        sprite.blend_type = cell_data
      end
  end
  #
  #---------------------------------------------------------------------------  
  # ● Each  
  #---------------------------------------------------------------------------  
  def each  
    @gifbitmaps.each {|item| yield item }  
  end  
end  
    
#==============================================================================  
# ■ Fonctions Complémentaires  
#==============================================================================  
def strsplit(str, re)  
  ret = []  
  tstr = str  
  while re =~tstr  
  ret[ret.length] = $~.pre_match  
  tstr = $~.post_match  
  end  
  ret[ret.length] = tstr if ret.length  
  return ret  
end  
  
def canonicalize(c)  
  csplit = strsplit(c, /[\/\\]/)  
  pos = -1  
  ret = []  
  retstr = ""  
  for x in csplit  
    if x == "."  
        
    elsif x == ".."  
      ret.delete_at(pos) if pos >= 0  
      pos -= 1  
    else  
      ret.push(x)  
      pos += 1  
    end  
  end  
  for i in 0...ret.length  
    retstr += "/" if i > 0  
    retstr += ret  
  end  
  return retstr  
end


Up s'il vous plait !