Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Fading pictures question

Nachos

Sponsor

I'm making this " Picture fading" script, which fades in a picture, displays it, and then fades it out.

The point is, how can I:

1º set this picture that will be shown in the event.
2º I made it to display 2 pictures, but now i want it to display one, and i displays the same picture twice.
3º It fades in and out in a shot time, how can i make it longer¿?

Code:
#==============================================================================
#   â–  Pictures fading
#==============================================================================
#   By: Nahchito (rmxp) / [url=http://www.nachosonline.tk]www.nachosonline.tk[/url]
#   Date: 30/12/2008
#   Version: V 0.1
#==============================================================================

class Scene_FadingPic
  
 #--------------------------------------------------------------------------
 # â—
 

EOG

Member

First of all if you want to make a script that will work on every Scene or you need to write it as a module or a class not as a scene.
Second RPG Maker already have a script to show pictures. It is:
Code:
$game_screen.pictures[picNumber].show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
If you want to make picture fade-in and  -out you should change picture opacity by 0.1 not 1

I suggest make a class Scene_FadingPic
Functions:
- initialize(picName)
- update
- fadeing - optional
 
Ok,

You're starting with an opacity of 255. You want to start with 0

@sprite1.opacity = 0

Also, in the transition method, you are not changing the opacity of the sprite.
try replacing @n with @sprite1.opacity

Next, the sprites opacity has legal values of 0..255, and will truncate / round if you assign an invalid value, so you'll need to make the if statements:

if @sprite1.opacity >= 255

and

if @sprite1.opacity <= 0

or just ==

Code:
#==============================================================================
#   â–  Pictures fading
#==============================================================================
#   By: Nahchito (rmxp) / [url=http://www.nachosonline.tk]www.nachosonline.tk[/url]
#   Date: 30/12/2008
#   Version: V 0.1
#==============================================================================

class Scene_FadingPic
  
 #--------------------------------------------------------------------------
 # â—
 

EOG

Member

this is how I'd do that:
Code:
#==============================================================================
#   Ã¢â€“  Pictures fading
#==============================================================================
#   By: EOG (rmxp)
#   No credit need; you can edit and use as you wish.
#==============================================================================

class Game_FadingPics
#==============================================================================
# ** Initialize
#==============================================================================
  def initialize
    @fadeing_in = []
    for picture in $game_screen.pictures
      if picture == nil
        next
      end
      @fadeing_in[picture.number] = false
    end #if
  end #def
#==============================================================================
# ** Fade
#==============================================================================
  def fade(picName , x = 0, y = 0, zoom_x = 100, zoom_y = 100, orgin = 0)
    if $scene.is_a?(Scene_Map)
      for picture in $game_screen.pictures
        if picture == nil
          next
        end
        if picture.erased? #find empty picture
          $game_screen.pictures[picture.number].show(picName, orgin, x, y, zoom_x, zoom_y, 0, 0)
          @fadeing_in[picture.number] = true
          break
        end #if
      end #for
    end #if
  end #def
 #--------------------------------------------------------------------------
 # ** Update
 #-------------------------------------------------------------------------- 
  def update
    #fadeing
    for picture in $game_screen.pictures
      if picture == nil
        next
      end
      if @fadeing_in[picture.number]
        picture.opacity += 1
        if picture.opacity == 255
          @fadeing_in[picture.number] = false
        end #if
      end #if
      if !@fadeing_in[picture.number] and picture.erased? != ""
        picture.opacity -= 1
        if picture.opacity == 0
          picture.erase
        end #if
      end #if
    end #for
  end #def
end #class
  
class Scene_Map
    alias old_main main
    alias old_update update
    def main
      $Game_FadingPics = Game_FadingPics.new
      old_main
    end 
    def update
      old_update
      $Game_FadingPics.update
    end
  end
class Game_Picture
  attr_accessor :opacity
  def erased?
    if @name == ""
      return true
    end
    return false
  end
end

Usage:
In event list commands => Scrpt
Code:
$Game_FadingPics.fade("picName" [, x][, y][, zoom_x][, zoom_y][, orgin])

variables in [] are optional.
 

Nachos

Sponsor

The problem is, you are giving me a script you JUST MADE. I'm not looking for the script, I'm looking for a solution to my problem to improve my scripting skills.
Looking at what you've made, I've edited my script and I got this:

Code:
#==============================================================================
#   â–  Pictures fading
#==============================================================================
#   By: Nahchito (rmxp) / [url=http://www.nachosonline.tk]www.nachosonline.tk[/url]
#   Date: 30/12/2008
#   Version: V 0.1
#==============================================================================

class Scene_FadingPic
  
 #--------------------------------------------------------------------------
 # â—
 

EOG

Member

Oh sorry that is because I forgot to delete one of prints I use for debug. Just remove line
Code:
print $game_screen.pictures.size
from my code. I'll post here soon and guide you in scripting.
 

EOG

Member

Those are basics of Ruby in RGSS if you know the basics you can skip to the second long red line
Lots of help in Ruby and RGSS you can find in Help file of program. Help => Contents

-----------------------------------------------------
Some introduction to Ruby in RPG Maker:
* RPG Maker have a two idea of classes.
  **Normal classes and Scene classes
     -Normal classes are there to do the counting and prepare everything to show in Scene classes they are not available to be shown in game(without changing Main)
     -Scene classes are classes that prints things on screen and only one scene class can be visable at a time.

Ruby is a language where class constructor is calls initialize
A constructor is a function executed at creation of an object.

ex.
Code:
class Add
   def initialize(a, b)
      return a+b
   end
end
This code will create a class Math which constructor needs two variables and adds them together

Code:
print Add.new(2,3)
This code will print a message box which contains '5'. It creates new object from add class and gives it two variables it needs(2 and 3)

In Ruby there are four types of variables:
local: variable that works only inside function
ex.
Code:
class Local
   def localVariable
       this_is_a_local_variable = 4
       print this_is_a_local_variable
   end
end

instance: variable that works only inside class (this variables are started with @)
ex.
Code:
class Instance
    def instanceVariable
       @this_is_an_instance_variable = 4
    end
    def printInstanceVariable
       print @this_is_an_instance_variable
    end
end

global: variable that works inside every class (this variables are started with $)
ex.
Code:
class global
    def GlobalVariable
       $this_is_an_global_variable = 4
    end
end
class ThatUsesGlobalVariable
    def printGlobal
        print $this_is_an_global_variable
    end
end

class: variable that is has the same value for every object of the same type(it is started with @@ ; there are no class variables used in RGSS so I'll write a longer code that will show how it works.
ex.
Code:
class Math
    def initialize
       @@total = 0
    end
    def add(a,b)
      print a+b
      @@total += a+b
      print @@total
    end
end
c = Math.new
d = Math.new
c.add(1,2)
d.add(3,4)
This code will show numbers 3, 3, 7, 10
This means that
a+b = 3
@@total = 0+3
a+b = 7
@@total = 3+10


In RPG Maker in Sprite classes there is a function called main it is a function called from Main
and is threated as pseudo constructor.

-----------------------------------------------------
In your program you use a single Sprite
In your newest version of script you use my function as a bitmap
Code:
@sprite1.bitmap = fade(picName , x = 0, y = 0, zoom_x = 100, zoom_y = 100, orgin = 0)
it will not work 'cause:
1. You do not have fade function in your script
2. Fade is not a bitmap

Your first guess of
Code:
@sprite1.bitmap = RPG::Cache.picture("sce1")
was a hit you need to use RPG::Cache.picture
but instead of ("sce1") you just need a variable here
ex.  (picture)
Instead of main you need to make a constructor(info about this is above) witch gets a name of a picture and it's position on screen.
ex.
Code:
def initialize(picture,x,y)
to set position of Sprite you need code
Code:
 @sprite1.x = x
 @sprite1.y = y


-----------------------------------------------------
Sorry but I must end for today I'll post some new tips in 10h if no1 will help you.
If you do not understand something remember that you have Help(inside RMXP) and ask questions if what I write is to hard to you just ask questions and I'll answer. you can PM me if you wish I'll help.
 

Nachos

Sponsor

Hey thanks for that. I know there was a contents help file, I read it once. I was learning RGSS by editing scripts, but now I've decide to pay attention to the help file.

As for the problem, I've deleted a line and it worked.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top