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.

Help with animated Title

this gets Placed in Class Scene_Title in the update definition

loop do
if @sprite.bitmap == RPG::Cache.title("001-title001")
@sprite.bitmap = RPG::Cache.title("001-title002")
break
end
if @sprite.bitmap == RPG::Cache.title("001-title002")
@sprite.bitmap = RPG::Cache.title("001-title003")
break
end
if @sprite.bitmap == RPG::Cache.title("001-title003")
@sprite.bitmap = RPG::Cache.title("001-title001")
break
end
end

However I get an error "undefined bitmap for nil:NilClass".
Anybody know why this error pops up, thanks.
 
I think your Def Main should look a bit like this, at least if you're using the SDK (the loop do and the spriteset.new bit before that all I changed) but replace the filenames appropriately.

I don't know what I'm doing though, so this is a case of the blind leading the blind. Hopefully it'll help though. I don't know how to create a delay between pictures. I'm checking on that... had the command a moment ago but seem to have lost it. Eh.

Code:
  def main
    return if main_battle_test?
    main_database
    main_background
    main_menu
    main_test_continue
    main_audio
    # Execute transition
    Graphics.transition
    # Main loop
    @sprite = Sprite.new #added
    loop do
      main_loop
      break if main_scenechange?
      
if @sprite.bitmap == RPG::Cache.title("001-Title01")
@sprite.bitmap = RPG::Cache.title("title1")
break
end
if @sprite.bitmap == RPG::Cache.title("title1")
@sprite.bitmap = RPG::Cache.title("001-Title01")
break
end

    end
    # Prepare for transition
    Graphics.freeze
    main_dispose
  end
 
Let me say that it will consider one bitmap equal to another only if it is INDEED the same. It could work, since Cache only loads one bitmap for each path and filename you call until you dispose it (that´s bad because if you change the bitmap somehow it becomes changed in all the other objects that uses it). I advice you to store the name of the title to make that work better.

And avoid making those checks inside the main loop, it can give you lag and/or problems during the presentation. I´ll try to lead you to a better way but i just can´t remember well how the main method is written (i´m not with the codes now ^^), but you should test this:

Code:
# Supposing you´re making that inside some Scene and
# that you want to make it check on each frame
class Scene_Title

# Aliases
alias old_main main
alias old_update update

def main
# Raise the number here to make it animate slower, the inverse
# for quicker.
@frame_rate = 2
@frame_count = 0
@title_name = "001-title01"
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title(@title_name)
old_main
@sprite.dispose if !@sprite.disposed?
end

def update
# Here it changes the title
if @frame_count >= @frame_rate
@frame_count = 0
case @title_name
when "001-title01"
@title_name = "002-title02"
when "002-title02"
@title_name = "003-title03"
when "003-title03"
@title_name = "001-title01"
end
@sprite.bitmap = RPG::Cache.title(@title_name)
else
@frame_count += 1
end
@sprite.update
old_update
end

end #of the code

# Just copy and paste it below Scene_Title

It could be made easier with sprintf, but i´m not with my RMXP right now, that´s all i can do ^^

Hope it helped.
 
I really like how as I've been exposed more to scripting, when I look at the lines they begin to make more sense to me. :)

I don't quite understand what alias with old_main does. Tells it "at this point, go to the older main script and run everything else in it"? That it?

Thank you very much for your help, Linkin. Going to try it out now.

Oh wait. I don't think I should be using the SDK, maybe? There's no def update in the scene_title area... Somehow it puts that definition somewhere else entirely, and I can't work out where - merged with other things or something. So I don't know if I'll be screwing things up entirely by fiddling with that. Maybe I should just take the SDK out and abandon what things require it. *scratches head* Blerrrgh.

Edit: I removed the SDK. I can implement it back in perhaps once I have full understanding of everything I'm doing and how to use it properly. I tried your script above, implementing it into my scene_title because I wanted to see if I could do it right and all, and it works perfectly. So thank you very much, again. :)
 
I don´t advice you to use any other´s scripts unless you make sure they wont conflict with others (japanese scripts are the most suspicious....). But i simply dislike SDK xD Use it if you want, but i would not use it...

BTW alias just renames a method. In the moment i called that...
Code:
alias old_main main
I was telling the script to rename the method main to old_main. That way i can create a new method called main that doesn´t rewrite the "old" main (that now is called old_main, and indeed all the real main code is there). Complicated just at the first sight ^^
 
So rather than rewriting it, by typing in alias old_main main, you can for any later scripts that need to call something from the original main, tell them to look for old_main instead, and that's why alias is useful?
 
It´s useful for you in some situations that you need to add some code in a method that have been previously written. That way you don´t need exactly to go inside that code and rewrite it. But note that we just can add new stuff BEFORE and AFTER the method code, if you want to add code in the middle of the method you´ll need to make it inside this method or else rewrite it all adding the new code.

And yes, by calling it the very first method written will be called old_main, followed by the newest called main (that includes the old btw). And if it´s that your question, *i think* yes you can call old_main in any place of the script (redefinitions or not) as long as this method call is made after the alias command.
 

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