RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Show Animated Pictures

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Best RPG Maker User - Engine2014 Most Unsung Member2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best Member2012 Best RPG Maker User (Scripting)Secret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Best Use of Avatar and Signature Space2011 Favourite Staff Member2011 Best RPG Maker User (Scripting)2011 Most Mature Member2010 Favourite Staff Member2010 Best Use Of Avatar And Signature Space
Show Animated Pictures
Version: 1.0
Author: modern algebra
Date: February 20, 2010

Version History


  • <Version 1.0> 02.20.2010 - Original Release

Description


This will allow you to show animated pictures through the regular event commands.

Features

  • Allows you to show an animated picture in battle or the map through the regular event commands
  • You can customize the speed of the animation and the size of each frame for each picture
  • All frames are contained in the same file, for simplicity
  • Can perform other picture operations on it, such as rotation, without interfering with the animation

Instructions

Place this script in its own slot in the Script Editor (F11) above Main and below all the other default scripts.
For instructions on how to format your pictures and name them to utilize this script, see the instructions in the header, starting at line 12.

Attached at the bottom of this post is a very simple sample picture (using facesets generated with MOROMAGA), with the naming required. The first uses the default timing, while the second specifies a frame alteration every 1/15 second. Both are the same image and so both have a frame width of 96.

Script


Code: [Select]
#==============================================================================
#    Show Animated Picture
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: February 20, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#    
#    This will allow you to show animated pictures through the regular event
#   commands.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Place this script in its own slot in the Script Editor (F11) above Main
#   and below all the other default scripts.
#
#    The format for the animated picture is that each frame of the animation
#   should be placed in the image to the right of the previous frame. Each
#   frame must be equal width. The easiest example is any direction of a
#   character sprite. Once you have created your picture in the correct format,
#   you must identify how you want it to animate in its name. You can name the
#   file whatever you want, but you need to include this code somewhere in the
#   name:
#        %[frame_width, time_interval]
#   where:
#     frame_width : the width of each frame, so this should be an integer of
#       however many pixels wide each frame of the animation is
#     time_interval : this determines how much time each frame is shown for
#       before switching to the next frame. It is also an integer, where
#       60 = 1 second. So, if you want each frame to be shown for only 1/10 of
#       a second, then you should put 6 here. If you do not specify a time
#       interval and leave it as %[frame_width] then it will take the value
#       specified in SAP_DEFAULT_TIME at line 56.
#
#    The animation will go from the first through to the last frame and then
#   repeat until the picture is erased. It will switch between frames at the
#   speed you define by setting time_interval.
#
#    If you do not include this code in the name, then the game will treat it
#   as a normal picture and show the whole thing.
#==============================================================================

#==============================================================================
# ** Sprite_Picture
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new constant - SAP_DEFAULT_FRAMES
#    aliased method - update
#    new method - update_src_rect
#==============================================================================

class Sprite_Picture
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * CONSTANTS
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  SAP_DEFAULT_TIME = 12
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Frame Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malbr_anmtepictr_upte_6ys1 update
  def update (*args)
    # Check if picture has changed and, if so, whether it is animated
    if @picture_name != @picture.name
      @sap_animated = @picture.name[/%\[(\d+),?\s*?(\d*?)\]/] != nil
      if @sap_animated
        @sap_frame_width = $1.to_i
        @sap_time_interval = $2.to_i != 0 ? $2.to_i : SAP_DEFAULT_TIME
      end
      @sap_current_frame = -1
      @sap_frame_count = 0
    end
    malbr_anmtepictr_upte_6ys1 (*args) # Run Original Method
    # If picture is animated
    update_src_rect if @sap_animated
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Transfer Origin Rectangle
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def update_src_rect
    @sap_frame_count %= @sap_time_interval
    if @sap_frame_count == 0
      @sap_current_frame += 1
      @sap_current_frame = 0 if self.bitmap.width < (@sap_current_frame + 1)*@sap_frame_width
      sx = @sap_current_frame*@sap_frame_width
      self.src_rect.set(sx, 0, @sap_frame_width, self.bitmap.height)
    end
    @sap_frame_count += 1
  end
end

Credit


  • modern algebra

Support


Please post in this topic in RMRK for support, no matter how long it's been since the topic was posted in last. Do not PM me, as if you have an issue it is likely someone else will, and I want them to benefit from the ensuing discussion also.

Known Compatibility Issues

No currently known compatibility issues. It would likely interfere with other scripts that alter how much of a picture is shown, however. I know of no such scripts, however.


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
« Last Edit: February 20, 2010, 07:23:40 PM by Modern Algebra »

pokeball joyOfflineFemale
*
Rep:
Level 85
I heard the voice of the salt in the desert
2012 Best RPG Maker User (Mapping)Project of the Month winner for June 20092010 Best RPG Maker User (Creativity)2011 Best RPG Maker User (Creativity)2011 Best RPG Maker User (Mapping)Winner - 2011 Winter Project of the Season2010 Best RPG Maker User (Graphical)2010 Best Artist2010 Best RPG Maker User (Mapping)2014 Best RPG Maker User - Mapping2014 Best Artist2014 Best RPG Maker User - Graphics2013 Best RPG Maker User (Graphical)2013 Best RPG Maker User (Mapping)2010 Most Unsung Member2010 Most Attractive Female Member
Now this looks bloody helpful...great work!!

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
oh snap, this is cool (we could so use this in our game) =o

*
Rep:
Level 97
2014 Best RPG Maker User - Engine2014 Most Unsung Member2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best Member2012 Best RPG Maker User (Scripting)Secret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Best Use of Avatar and Signature Space2011 Favourite Staff Member2011 Best RPG Maker User (Scripting)2011 Most Mature Member2010 Favourite Staff Member2010 Best Use Of Avatar And Signature Space
Well, I'm glad you guys like it. I was kind of thinking halfway through making it that it wasn't all that useful, as the effect could easily be replicated by an event like:

Loop
Show Picture 1 [frame 1]
Wait: x frames
Show Picture 1 [frame 2]
Wait: x frames
etc..
End Loop

Though, it does have the benefit of being able to perform other picture operations on each at the same time.

So I'm happy that you guys like it, as otherwise I'd be convinced it was boring and useless :P

**
Rep: +0/-0Level 83
Woah, this is great!  Thanks for another great script, modern algebra!  I'd hate to ask, but would a demo be possible?  I think it would really help show how it works.

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for August 2008Project of the Month winner for December 20092011 Best Game Creator (Non RM)Gold - GIAW Halloween
that'd be in an event.
and those are the exact event commands you'd need to call, more or less.

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

*
Rep:
Level 85
I am the wood of my broom
2010 Project of the YearProject of the Month winner for January 2009Project of the Month winner for January 2010Project of the Month winner for April 2010
I find it pretty amazing that this also works in VXAce!
Just wanted to add that there is a bug tho.

At line 70, after this: @sap_frame_count = 0
Add this: @picture_name = @picture.name
And it works, at least in VXAce ;w;)/