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.

[SOLVED] Adding an Arrow Graphic to choices!

Hey everyone, I have a possible eventing issue that I am hoping someone may be able to help me out with . . .

Basically, within my project I have a difficulty selection screen that pops out when you start a new game:
Difficulty%20Screen0.png


Now this is all fine and dandy and it actually works because I am using a script that utilizes these in game events:

events.png


What I would love however is to be able to attach this graphic:
arrow.png


to the left of the choices in the difficulty selection screen so that it looks something like this:
Difficulty%20Screen.png


and is able to move up and down alongside the choices. How would I do this? I am confused and would love some assistance! Thank you in advance for any help . . .
 

Injury

Awesome Bro

Hey there

If you are using an event system, I can help. Displaying the images via script or eventing is at your discretion.

The concept is to have x,y values set up for each choice:

difficulty1X=x (the x plane position of the image)
difficulty1Y=y (the y plane " " " ")

You would do this for each difficulty. Now the cursor would rely on it's own set of coordinates:

arrowX
arrowY

and you need a variable to retain the position of the cursor

arrowPos

So we have some variables to work with. We set up our "static" (not going to change) variables to hold the X,Y coordinates for each choice. Now the fun part! Initially, we need to show the cursor like you showed the background.

show picture arrow.fileFormat

but we need it to be at the first cursor position, so we can set the variables prior to showing the picture.

Code:
set arrowPos=1

If(arrowPos=1){

arrowX=difficulty1X

arrowY=difficulty1Y

}

//We can throw in the other difficulties in between here as well

show arrow.fileFormat @ arrowX arrowY

Now we have to wait for input from the user to see if they want to move the arrow and choose a different difficulty...This requires the Enter Password or whatever XP VX uses for User Input. We want to look for a directional push. This might be more easily accomplished with scripts, but either way, we just want to find out if they move it:

Code:
if(input=[Up]){

If(arrowPos=1){ //the first difficulty choice!

play a noise, don't move the arrow

 }

If(arrowPos > 1){ //if its 2,3 or 4

set arrowPos -1

 }

}

if(input=[Down]){

if(arrowPos=4){ //the last difficulty

play a noise, dont move the arrow

}

if(arrowPos < 4){ //If its 1,2 or 3

set arrowPos +1

}

 
So essentially we are looking to see if the arrow is at 1, if up is pressed deny a change of position for the arrow. If the arrow is at 4 and down is pressed, deny that. If up is pressed at 4, we subtract 1 from the arrow position, and the image updates with difficulty3's X,Y to the arrowX,Y variables. Now once the player makes their choice, you probably want to look for them to press a button to confirm their choice, so use the user input function in whatever version maker your using to set the difficulty, erase the images and begin your game.
Hope that makes sense! I'm not the best a pseudo code but the concept it there! You are going to want to put all these controls in a different event that will handle the images and the controls. I'd suggest moving your "showPicture background" or w/e to the event that is going to manage the arrow and whatnot.
PS Gubid knows better probably, but look at this for the concept!
 
Posted this over at CA as well.

This should do the trick. Just put the arrow in the pictures folder as 'arrow.png'.

Code:
class Window_Selectable < Window_Base

  Show_Cursor_Switch = 1

  Animated_Arrow = true

  #--------------------------------------------------------------------------

  # * Cursor Rectangle Update

  #--------------------------------------------------------------------------

  alias update_cursor_rect_arrow_add update_cursor_rect

  def update_cursor_rect

    update_cursor_rect_arrow_add 

    update_arrow

  end

  def update_arrow

    empty_rect = Rect.new(0,0,0,0)

    if self.cursor_rect != empty_rect and @arrow == nil

      @arrow = Sprite.new

      @arrow.bitmap = RPG::Cache.picture("arrow")

      @arrow.x = self.x + self.cursor_rect.x

      @arrow.y = self.y + self.cursor_rect.y + 16

      @arrow.z = self.z + 1

      @arrow_anim = 0

    elsif self.cursor_rect != empty_rect and @arrow != nil

      @arrow.x = self.x + self.cursor_rect.x

      if Animated_Arrow == true

        @arrow.x += @arrow_anim

        if Graphics.frame_count % 5 == 0

          @arrow_anim += 1

          @arrow_anim %=4

        end

      end

      @arrow.y = self.y + self.cursor_rect.y + 16

    elsif self.cursor_rect == empty_rect and @arrow != nil

      dispose_arrow

    end  

 

    if defined?($game_switches) == nil

      dispose_arrow

      return

    end

    if $game_switches[Show_Cursor_Switch] == false and @arrow != nil

      dispose_arrow

    end

  end

  def dispose_arrow

    @arrow.dispose

    @arrow = nil

  end

  alias dispose_win_sel_arrow dispose

  def dispose

    dispose_win_sel_arrow 

    if @arrow != nil

      dispose_arrow

    end

  end

end

class Window_Message < Window_Selectable

  alias update_cursor_rect_arrow_add_msg update_cursor_rect

  def update_cursor_rect

    update_cursor_rect_arrow_add_msg

    update_arrow

  end

end

This actually will apply to all windows so long as the switch is ON. Your choice. I even animated it for you.
 
Hey GudiD! thank you so much for doing this for me (you too Injury) I entered the script, but here's the issue that happens now. When I turn switch 1 on, I get a blank black screen if I turn the switch on in the same event page as my difficulty settings. If I do an all new event and turn the switch 1 on, nothing changes, I get my normal difficulty settings screen with choices and everything without the arrow.

I'm also not sure if I'm doing this correctly as I am highly unfamiliar with scripting and switches . . .

The script you created above; is it meant to put in as an all new script or to replace Window_Selectable? Once I enter the script, what specifically do I need to do to turn the switch on? Am I correct in assuming i create a new event with the switch 001 on? Sorry for the naivety on my part, but thank you so much for helping me!
 
Its all good. It should be placed in as a new script section below all the others, but above main, just like you were adding any other new script. You then ensure that the 'arrow.png' file exist in your 'Graphics\Pictures' folder. Then set the SWITCH ID that you want to control the showing of the cursor, then turn it on in game. (by event or whatever)

Works fine in a clean project that I created it in.

I tested this by editing the variable using the debug console F9 when you launch your game. When you enable the switch, it then shows it (the cursor) in the debug menu and all others, until the switch is disabled.

Let me know if you need any more direction.
 

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