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.

Scripting question XP

Ark

Member

Hi!

I have a short question which I'd like to ask you. Please help if you can!

IS THERE A WAY (A SMALL SNIPET OF SCRIPT) TO CHANGE THE HEIGHT AND WIDTH OF THE SPRITE ON MAP?
I NEED IT FOR MY SYSTEM (FAKE 3D) TO MAKE THE PLAYER THINK THAT SOMEONE IS IN THE BACKGROUND/FOREGROUND!

Thank you in advance!

(RPG Maker XP)
 

Ark

Member

I do need to have a script to do that.

Because I want to shrink the charsets gradually and I'd need hundreds of charsets to do that.

I use Pixelmovement script and I want to tell a paralell script to shrink charset if it goes beyond a certain x or y pixel...

So, please help me!
 

khmp

Sponsor

First let's say you want this to occur for only a few characters on Map.

The way it works is this:

-Spriteset_Map
  -Sprite_Character
    -Game_Characters

The Spriteset_Map is the nice graphical stuff you see when you're on a Map. All the events and the player on the Map are set up within Sprite_Character's. An array of Sprite_Characters are contained within Spriteset_Map. The Game_Character is the class you will need to manipulate in order for the changes to be reflected in the Sprite_Character's which are contained within Spriteset_Map. You would incorporate some things like zoom_x and y into Game_Character and use methods to manipulate them properly.

Example:
Code:
class Game_Character
  alias_method :ark_sizing_game_character_initialize, :initialize
  attr_reader :zoom_x, zoom_y
  def initialize
    ark_sizing_game_character_initialize
    @zoom_x = @zoom_y = 1.0
  end
  def resize(zoom_x, zoom_y)
    @zoom_x, @zoom_y = zoom_x, zoom_y
  end
end

class Sprite_Character < RPG::Sprite
  alias_method :ark_sizing_sprite_character_update, :update
  def update
    ark_sizing_sprite_character_update
    self.zoom_x, self.zoom_y = @character.zoom_x, @character.zoom_y
  end
end

And then you would have something like this in a script call:
Code:
$game_map.events[id].resize(
new_zoom_x, new_zoom_y)
or for just the player:
Code:
$game_player.resize(
new_zoom_x, new_zoom_y)

Alternatively you can have this occur automatically for every Sprite_Character on screen. As in this case we do not need to worry about order we would simply iterate through the Sprite_Character's of the Spriteset_Map. But I'm unsure if you want this to occur automatically which is why I didn't just do this code. Sorry if I wasted your time with the above code. :wink:

Code:
class Spriteset_Map
  alias_method :ark_sizing_spriteset_map_update, :update
  def update
    ark_sizing_spriteset_map_update
    
    @character_sprites.each { |sprite_character|
      next if sprite_character.nil?
    
      pixel_x = sprite_character.character.real_x / 4
      pixel_y = sprite_character.character.real_y / 4
      zoom_x = zoom_y = 1.0

      # Do testing to see if the zoom values should change.
      # 1.0 is normal size, 2.0 is double size, 0.5 is half normal size.
      # You need to figure out the math to properly adjust zoom here.

      sprite_character.zoom_x = zoom_x
      sprite_character.zoom_y = zoom_y
    }
  end
end

Good luck with it Ark! :thumb:
 

Ark

Member

I have another problem.

It works quite well with the normal system. But I want to use it alongside with the Pixel movement script and it gives me an error!

About something of a float.

it was around this line

self.zoom_x, self.zoom_y = @character.zoom_x, @character.zoom_y

so I changed it to:

self.zoom_x = @character.zoom_x
self.zoom_y = @character.zoom_y

so it doesn't give me the error but when I call the size changing script it does nothing!

Can U help me?
 

khmp

Sponsor

Ark":2ofmlsdb said:
I have another problem.

It works quite well with the normal system. But I want to use it alongside with the Pixel movement script and it gives me an error!

About something of a float.

it was around this line

self.zoom_x, self.zoom_y = @character.zoom_x, @character.zoom_y

so I changed it to:

self.zoom_x = @character.zoom_x
self.zoom_y = @character.zoom_y

so it doesn't give me the error but when I call the size changing script it does nothing!

Can U help me?

The best I can do is try, no promises. Just post a link to the script that does the pixel movement movement script.
 

khmp

Sponsor

Well I'm a little confused on the exact reason why it ignores that the parent's additional values. I redefined the values inside Game_Player and it resolved the problem but Game_Player derives from Game_Character and the pixel methods do not override the initialize method of Game_Character, still Game_Player doesn't for some reason know of @zoom_x or @zoom_y. Another error was that because I had typed the code in the post without testing it I left out a ":" in front of zoom_y. If you receive a message about zoom not existing again. Tell me what class comes up. Anyway the fixed code is below:

Code:
class Game_Character
  alias_method :ark_sizing_game_character_initialize, :initialize
  attr_reader :zoom_x, :zoom_y
  def initialize
    ark_sizing_game_character_initialize
    @zoom_x = @zoom_y = 1.0
  end
  def resize(zoom_x, zoom_y)
    @zoom_x, @zoom_y = zoom_x, zoom_y
  end
end

class Game_Player < Game_Character
  alias_method :ark_sizing_game_player_initialize, :initialize
  attr_reader :zoom_x, :zoom_y
  def initialize
    ark_sizing_game_player_initialize
    @zoom_x = @zoom_y = 1.0
  end
  def resize(zoom_x, zoom_y)
    @zoom_x, @zoom_y = zoom_x, zoom_y
  end
end

class Sprite_Character < RPG::Sprite
  alias_method :ark_sizing_sprite_character_update, :update
  def update
    ark_sizing_sprite_character_update
    p '@zoom_x not contained within: ' + @character.type.to_s if @character.zoom_x.nil?
    self.zoom_x, self.zoom_y = @character.zoom_x, @character.zoom_y
  end
end

Good luck with it Ark! :thumb:
 

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