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.

Showing pictures with RGSS?

Status
Not open for further replies.
Hey all,

I was hoping for a little help.
How would I go about scripting this, with the script command within an event:

Show Picture "globe" wih a picture id of [@event_id]

show the picture at coordinates ($game_variables[@event_id], $game_variables[@event_id + 50])

move picture[@event_id] to ($game_variables[@event_id], $game_variables[@event_id + 50]) over 20 frames.

Zoom picture[@event_id].x 80%

Zoom picture[@event_id].y 80%

thanks!!
 

khmp

Sponsor

Ok let's start with the first part. Creating the picture and showing it at specified coordinates.

Code:
event_id = 0
# Create a sprite object to draw our picture.
@globe = Sprite.new
# Initialize the bitmap.
@globe.bitmap = RPG::Cache.load_picture(event_id)
# Move it to the specified location. 
@globe.x, globe.y = $game_variables[event_id], $game_variables[event_id + 50]

To move it while decreasing it's size now that is a bit more involved. You'll need to make use of a method called once a frame. Luckily every scene or screen in RMXP has a method that is called once a frame called "update". To get the following code to be applicable I'll need to know the scene that you want this to occur in whether it be Scene_Title, Scene_Menu, Scene_Map etc.

Code:
alias_method :acej_picturefun_main, :main
alias_method :acej_picturefun_update, :update
def main
  event_id = 0
  # Create a sprite object to draw our picture.
  @globe = Sprite.new
  # Initialize the bitmap.
  @globe.bitmap = RPG::Cache.load_picture(event_id)
  # Move it to the specified location. 
  @globe.x, globe.y = $game_variables[event_id], $game_variables[event_id+ 50]
  # Sets it's z value closer so it doesn't hide behind anything.
  @globe.z = 2

  # Where do we want the globe to go on the screen?
  @go_to_x = 50
  @go_to_y = 100
  
  # How many frames will it take to reach those coordinates.
  frames_to_dest = 20

  # Figure out the velocity vector scaled down by the amount of frames.
  # destination - source
  @x_vel = (@go_to_x - @globe.x) / frames_to_dest
  @y_vel = (@go_to_y - @globe.y) / frames_to_dest
  
  # How much leeway is there?
  @x_tol = (@go_to_x - @globe.x) % frames_to_dest
  @y_tol = (@go_to_y - @globe.y) % frames_to_dest

  # Change of zoom equals final zoom - normal zoom scaled down by the amount of frames.
  @delta_zoom = (0.8 - 1.0) / frames_to_dest
  acej_picturefun_main
  @globe.bitmap.dispose
  @globe.dispose
end

def update
  # If we are greater than the tolerance keep moving and zooming.
  if ((@globe.x - @go_to_x).abs > @x_tol) || ((@globe.y - @go_to_y).abs > @y_tol)
    @globe.x += @x_vel
    @globe.y += @y_vel
    @globe.zoom_x += @delta_zoom
    @globe.zoom_y += @delta_zoom
  end
  acej_picturefun_update
end

The comments are all there but if you're confused about any part of the code let me know and I'll try to be more specific about it. Like I said above though to complete the code I'll need to know the scene you want this code to appear in.

Good luck with it AceJP! :thumb:
 
I have questions. Sorry if this post is considered necropost

@globe.bitmap = RPG::Cache.load_picture(event_id)
this line defines what picture i want to show, right?
What should i do if i want to show my own picture? Should I import it first? Then what should I write there?
I don't understand this 'RPG::Cache.load_picture(event_id)'

what does alias_method mean?

khmp: Please don't necropost. If you have questions about an older topic, create a new thread with a link to this one. Thanks.
 
Status
Not open for further replies.

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