Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Picture-based window cursor update issue...
munkis
post Nov 7 2011, 03:22 PM
Post #1


Woah, dude...
Group Icon

Group: Revolutionary
Posts: 197
Type: Writer
RM Skill: Intermediate




What I'm trying to do is allow the user to have an animated picture for the window cursor. Each cell in the animation will be its own pic. I actually have it mostly worked out, but the script doesn't wait long enough between cells.

Script update WIP
CODE
#------------------------------------------------------------------------------
#  * Munkis' Picture-based window cursor V 1.1
#  * Made by munkis
#  •”•••••••••••—
#  •‘ FEATURES •‘
#  •š•••••••••••
#  * Replaces the default window cursor with a picture you create.  Also centers
#    the text in the command windows (thanks to TheLawG14)
#  * ALIASES create_command_window, terminate, and update methods of Scene_Menu,
#    Scene_End, and Scene_Title.
#    OVERWRITES draw_item method of Window_Command.
#  * V 1.0: Initial release
#  * V 1.1: You can now use multiple cursor pics as individual animation cells
#------------------------------------------------------------------------------

class Command_Window_Pic_Test < Window_Base
  def initialize(x,y,width,height)
    super(x,y,width,height)
    self.z = 0
    self.opacity = 0
    @anim_start = 0
#   [config]
    @cursor_cells = ["MenuSelectCell01","MenuSelectCell02","MenuSelectCell03"]
#   @window_properties = [pic_name, window_x, window_y, window_width,
#                         window_height, opacity in Scene_Menu,
#                         opacity in Scene_end, opacity in Scene_Title]
    @window_properties = [187,125,175,235,0,0,255]
#   [/config]
  end
  def refresh(window_contents)
    self.contents.clear
    if @anim_start !=60
      @anim_start +=1
      @pick_cell = rand(2)
    elsif @anim_start == 60
      @anim_start = 0
    end
    bitmap = Cache.picture(@cursor_cells[@pick_cell])
    if $scene.is_a?(Scene_Menu)
      self.opacity = @window_properties[4]
      rect = Rect.new(0, -(window_contents*WLH), @window_properties[2], @window_properties[3])
      self.contents.blt(x-@window_properties[0], y-@window_properties[1], bitmap, rect)
    elsif $scene.is_a?(Scene_End)
      self.opacity = @window_properties[5]
      rect = Rect.new(0, -(window_contents*WLH), @window_properties[2], @window_properties[3])
      self.contents.blt(x-@window_properties[0], y-@window_properties[1], bitmap, rect)
    elsif $scene.is_a?(Scene_Title)
      self.opacity = @window_properties[6]
      rect = Rect.new(0, -(window_contents*WLH), @window_properties[2], @window_properties[3])
      self.contents.blt(x-@window_properties[0], y-@window_properties[1], bitmap, rect)
    end
      bitmap.dispose
  end
end
class Window_Command < Window_Selectable
  def draw_item(index, enabled = true)
    rect = item_rect(index)
    rect.x += 4
    rect.width -= 8
    self.contents.clear_rect(rect)
    self.contents.font.color = normal_color
    self.contents.font.color.alpha = enabled ? 255 : 128
    if $scene.is_a?(Scene_Menu) or $scene.is_a?(Scene_End) or $scene.is_a?(Scene_Title)
      self.contents.draw_text(rect, @commands[index],1)
    else
      self.contents.draw_text(rect, @commands[index])
    end
  end
end
class Window_Selectable < Window_Base
  alias update_picture_cursor update_cursor
  def update_cursor
    update_picture_cursor
    self.cursor_rect.empty if $scene.is_a?(Scene_Menu) or $scene.is_a?(Scene_End) or $scene.is_a?(Scene_Title)
  end
end
class Scene_Menu < Scene_Base
  alias picture_create_command_window_menu create_command_window
  alias picture_terminate_menu terminate
  alias picture_update_menu update
  def create_command_window
    picture_create_command_window_menu
    @command_window.opacity = 0
    @pic_test = Command_Window_Pic_Test.new(@command_window.x-16,@command_window.y-17,@command_window.width+32,@command_window.height+6)
  end
  def terminate
    picture_terminate_menu
    @pic_test.dispose
  end
  def update
    picture_update_menu
    if @window_contents != @command_window.index
      @window_contents = @command_window.index
    end
      @pic_test.refresh(@window_contents)
  end
end
class Scene_End < Scene_Base
  alias picture_create_command_window_end create_command_window
  alias picture_terminate_end terminate
  alias picture_update_end update
  def create_command_window
    picture_create_command_window_end
    @command_window.opacity = 0
    @pic_test = Command_Window_Pic_Test.new(@command_window.x-16,@command_window.y-34,@command_window.width+32,@command_window.height+6)
  end
  def terminate
    picture_terminate_end
    @pic_test.dispose
  end
  def update
    picture_update_end
    if @window_contents != @command_window.index
      @window_contents = @command_window.index
    end
      @pic_test.refresh(@window_contents)
  end
end
class Scene_Title < Scene_Base
  alias picture_create_command_window_title create_command_window
  alias picture_terminate_title terminate
  alias picture_update_title update
  def create_command_window
    picture_create_command_window_title
    @command_window.opacity = 0
    @pic_test = Command_Window_Pic_Test.new(@command_window.x,@command_window.y,@command_window.width,@command_window.he
ight)
  end
  def terminate
    picture_terminate_title
    @pic_test.dispose unless @command_window.nil?
  end
  def update
    picture_update_title
    unless @command_window.nil?
      if @window_contents != @command_window.index
        @window_contents = @command_window.index
      end
        @pic_test.refresh(@window_contents)
    end
  end
end


EDIT: It changes cells once per frame; I want it to wait 30 frames (although the user will be able to change this value).

This post has been edited by munkis: Nov 10 2011, 09:54 AM


__________________________
Go to the top of the page
 
+Quote Post
   
munkis
post Nov 15 2011, 03:26 PM
Post #2


Woah, dude...
Group Icon

Group: Revolutionary
Posts: 197
Type: Writer
RM Skill: Intermediate




bump


__________________________
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Nov 15 2011, 04:01 PM
Post #3


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




Can only give you some theoretical code; I'm not at my computer at the moment.
You can combine the 3 images into one 'spritesheet' just use a sprite instead of a bitmap to display it; and then use src_rect to specify what's being displayed
CODE
@myImg = Sprite.new("some bitmap")
@myImg.src_rect = Rect.new(x,y,w,h)


Then during update merely shift the rect:
CODE
@myImg.src_rect = Rect.new(@index * w, y, w,h)

@index would be obtained based on the speed and frame count:
CODE
@index = (((graphics.frame_count / delay) % ((number_of_frames - 1) * 2) - (number_of_frames - 1)).abs


What this does is itterate through the number of frames with any delay specified, so in terms of frame delay.. If you use 1 as the delay, and had 5 frames, Itd display like so:
0, 1, 2, 3, 4, 3... Down to 0 and back. 2 delay would be like:
0, 0, 1, 1.......

If I haven't lost you, hope that helps.


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
munkis
post Nov 15 2011, 06:29 PM
Post #4


Woah, dude...
Group Icon

Group: Revolutionary
Posts: 197
Type: Writer
RM Skill: Intermediate




Now all I get are incredibly useless error messages that I apparently can't fix. The line the message indicates only has an end command, but adding or subtracting ends doesn't work, and I don't even understand why I'm getting the error in the first place.


__________________________
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Nov 16 2011, 07:55 PM
Post #5


Level 50
Group Icon

Group: +Gold Member
Posts: 1,520
Type: Scripter
RM Skill: Undisclosed




Wow.... very theoretical smile.gif
Although that's a really cool algorithm for the index happy.gifhappy.gif


I may have tinkered with the code slightly....
CODE
#------------------------------------------------------------------------------
#  * Munkis' Picture-based window cursor V 1.1
#  * Made by munkis
#  �•”�•��•��•��•��•��•��•��•��•��•��•—
#  �•‘ FEATURES �•‘
#  �•š�•��•��•��•��•��•��•��•��•��•��•�
#  * Replaces the default window cursor with a picture you create.  Also centers
#    the text in the command windows (thanks to TheLawG14)
#  * ALIASES create_command_window, terminate, and update methods of Scene_Menu,
#    Scene_End, and Scene_Title.
#    OVERWRITES draw_item method of Window_Command.
#  * V 1.0: Initial release
#  * V 1.1: You can now use multiple cursor pics as individual animation cells
#------------------------------------------------------------------------------



class Game_System
  attr_accessor :cursor_speed
  alias initialize_picture  initialize  unless $@
  def initialize(*args)
    @cursor_speed = 30
    return initialize_picture(*args)
  end
end



class Window_Selectable < Window_Base
  alias initialize_picture       initialize       unless $@
  alias create_picture_contents  create_contents  unless $@
  alias open_picture             open             unless $@
  alias update_picture           update           unless $@
  alias update_picture_cursor    update_cursor    unless $@
  alias dispose_picture          dispose          unless $@
  def initialize(*args)
    @active_time_count = 0
    initialize_picture(*args)
    @cursor_sprite = Sprite.new(self.viewport)
    @cursor_sprite.bitmap = Bitmap.new(32, 32)
  end
  def create_contents(*args)
    @is_picture_scene = false
    if $scene.is_a?(Scene_Menu) or $scene.is_a?(Scene_End) or
       $scene.is_a?(Scene_Title)
      @is_picture_scene = true
    end
    text_offset = 16
    if @is_picture_scene
      self.width -= text_offset * 2
    end
    create_picture_contents(*args)
    if @is_picture_scene
      self.ox -= text_offset
      self.width += text_offset * 2
    end
  end
  def open(*args)
    @cursor_sprite.opacity = 0
    return open_picture(*args)
  end
  def update
    @cursor_sprite.opacity = self.openness == 255 ? self.opacity : 0
    update_picture
  end
  def update_cursor
    if @is_picture_scene
      self.cursor_rect.empty
      @cursor_sprite.x = self.x + 16
      @cursor_sprite.y = self.y + 14
      @cursor_sprite.z = self.z + 1
      ir = item_rect(@index)
      @cursor_sprite.oy = -(ir.y + (ir.height - @cursor_sprite.bitmap.height)/2)
      if @active_time_count == 0
        @cursor_sprite.bitmap.dispose
        picture_name = "MenuSelectCell%02d" % (rand(3) + 1)
        @cursor_sprite.bitmap = Cache.picture(picture_name)
      end
      @active_time_count += 1
      @active_time_count = 0 if @active_time_count == $game_system.cursor_speed
    else
      update_picture_cursor
    end
  end
  def dispose
    @cursor_sprite.bitmap.dispose
    @cursor_sprite.dispose
    dispose_picture
  end
end


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
munkis
post Nov 18 2011, 02:05 PM
Post #6


Woah, dude...
Group Icon

Group: Revolutionary
Posts: 197
Type: Writer
RM Skill: Intermediate




@night_runner: Your code just displays the cursor for a frame or two, then it disappears. Unless I'm missing something...?


__________________________
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Nov 22 2011, 03:26 PM
Post #7


Level 50
Group Icon

Group: +Gold Member
Posts: 1,520
Type: Scripter
RM Skill: Undisclosed




I see what the problem is, sorry, I had it following the windows opacity, which you have as 0 in your scripts custom.
I've updated the code in my last post so it now follows the opacity of the text's bitmap, which fixes it for me smile.gif


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
munkis
post Nov 26 2011, 06:11 AM
Post #8


Woah, dude...
Group Icon

Group: Revolutionary
Posts: 197
Type: Writer
RM Skill: Intermediate




It still does the same thing to me. If you could help me get Night5h4d3's code to work, that'd be great.


__________________________
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th May 2013 - 02:43 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker