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.

Character Sprite Correction

arev

Sponsor

This script allows you to manipulate the sprite of any event (using characterset), by setting its horizontal/vertical position.
When is it usefull?
1 - When some of the objects in the map are characters, and you don't want them to look like they're placed on a gridlines.
2 - When you're using characters that require some space in the bottom (i.e. for steps animation). In that situation the graphic is ussually moved up, and it may cause some weird situations when calculatin passability or coordinates.
3 - When you want to place graphics from several events in one place, without moving them. This is helpful in making lanterns, torches, etc.
Screenshot:
http://www.eimg.org/images/745026corr.jpg[/IMG]

Script:
Code:
#==============================================================================
# ** Game_Character
#==============================================================================

class Game_Character

  attr_accessor :correction_x
  attr_accessor :correction_y
  #--------------------------------------------------------------------------
  alias normal_initialize initialize
  
  def initialize
    @correction_x = 0
    @correction_y = 0
    normal_initialize
  end

end
#==============================================================================
# ** Sprite_Character
#==============================================================================

class Sprite_Character < RPG::Sprite

  def update
    super
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue)
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @cw = bitmap.width / 4
        @ch = bitmap.height / 4
        self.ox = @cw / 2 - @character.correction_x
        self.oy = @ch - @character.correction_y
      end
    end
    self.visible = (not @character.transparent)
    if @tile_id == 0
      sx = @character.pattern * @cw
      sy = (@character.direction - 2) / 2 * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end

Usage:
Paste the script above "Main". Set the first page of an event to parallel or autostart. Put a "Call Script" command with:
Code:
get_character(0).correction_x = 0
get_character(0).correction_y = 0
Turn on any local switch, and make another page with the sam graphic.
Adjust the numbers (but not the ones in the brackets) to move the sprite left/right and up/down.
For example: the characters on the right side of the screenshot have a "Call script" command like this:
Code:
x = -8 + rand(16)
y = -8 + rand(16)
get_character(0).correction_x = x
get_character(0).correction_y = y
This way the correction is different for each character, and you can still copy/paste ;)

Now, I know a lot of people are using scripts that already alter Game_Character and Sprite_Character, and I can't alias the Sprite_Character's def update to work properly so here's what you need to do if you want to add this method to, for example, pixelmovement:
Find the Sprite_Character class. In its 'def update' find:
Code:
self.ox = @cw / 2
self.oy = @ch
and replace it with:
Code:
self.ox = @cw / 2 - @character.correction_x
self.oy = @ch - @character.correction_y
The Game_Character class is aliased so there's no need to do anything with it.

Enjoy the script :)
 
So this is basically proving to show that we can do the step animation in half squares.. essentially making the grid from 4x4 on a box, to a 8x8 box, in the same space as a 4x4. Making more of a smooth movement. Its a great idea, but some people will have to base their passability scripts around this formula.
 
He already has, the girl in the top right is normal, then check out the other girl who is halfway down and notice Arshes is halfway above the bottom grid line.
 

arev

Sponsor

Sorry to bump like this, but recently I saw a few projects, where there were quite large groups of characters (most likely armies), and I thought that it's a great place to use my script. I'm adding a screenshot of this situation:
http://www.eimg.org/images/745026corr.jpg[/img]
The chars on the right side have a "Call script" command:
Code:
x = -8 + rand(16)
y = -8 + rand(16)
get_character(0).correction_x = x
get_character(0).correction_y = y
 

arev

Sponsor

Yes, it can be used to affect the player. From any event, call a script:
Code:
get_character(-1).correction_x = blabla
"-1" in the bracket stands for the player, "0" stands for "this event", and numbers > 0 stand for the IDs of the events on the map.
 
Very nice, I had already implemented vertical correction in my own script before I knew this one existed :P I already intended to add horizontal as well, so congrats for beating me to the punch.

As an aside, I remember another script topic which offered the same functionality - it might have been yours or it might not have been (or you might just have edited this one), either way it is indeed useful :)
 

WiZ`

Member

great :D i was searching for it :D
Just a question XD it's possible to change the position of the player? or of all the character in a map whitout set it in all the event in the map?
 

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