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/animation placement (pixelmovement)

Using Fotz!etc's 'pixel movement' script I'm trying to properly implement hand-drawn maps.  My only problem is positioning characters and animated elements precisely where I need them.

For example, I have a cat on a table playfully twitching his tail:
http://i4.photobucket.com/albums/y141/T ... tled-3.jpg[/img]
On the left is where the cat event (character set/180 degree turn) appears in the map when I place it.  The right is where it's supposed to be.  I can only move the event within the grid so there is no way to directly match the correct position.  Is there a way to offset the event graphic within the engine or is this a script request I'll have to make? 
 
I'm not familiar with the pixel movement script, however.....

If this image is not used in a bunch of places, you could just edit the character set.
Add 14 blank pixels to the bottom of each row. (making the whole image 56 pixels taller)

Be Well
 
It really doesn't have much to do with the pixel movement script, I just added that bit in case it came up.  I considered adding pixels, which would be fine for just the one thing.  Ideally, however, I'd like to have multiple animated elements on a map.  Adding pixels is more time-consuming as I would have to load each file back into an image editor.  If possible I'd much prefer simply typing "shift down 13 by 8 pixels" as a command or something within the event.  As I said, I'm guessing this isn't going to be doable without a script.
 
Ok, here's the thing...

It would be much easier for me, if you edited your character sets, rather than me trying to figure out how to script it! :)

That doesn't mean I won't try. (in fact, I think I'm getting close)

I'll update this in a bit

Be Well

[ edit ]

Ok, here's what I did, and it seems to work...

At the top of Game_Character 1, right below "attr_accessor :transparent, add
Code:
  attr_accessor :ox                       # bitmap origin X offset
  attr_accessor :oy                       # bitmap origin Y offset

Then, replace Sprite_Character with
Code:
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
#  This sprite is used to display the character.It observes the Game_Character
#  class and automatically changes sprite conditions.
#==============================================================================

class Sprite_Character < RPG::Sprite
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :character                # character
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     viewport  : viewport
  #     character : character (Game_Character)
  #--------------------------------------------------------------------------
  def initialize(viewport, character = nil)
    super(viewport)
    @character = character
    update
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If tile ID, file name, or hue are different from current ones
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue or
       @ox_offset != @character.ox or
       @oy_offset != @character.oy
      # Remember tile ID, file name, and hue  (and ox & oy)
      @ox_offset = @character.ox
      @oy_offset = @character.oy
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      # If tile ID value is valid
      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
      # If tile ID value is invalid
      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.ox
        self.oy = @ch + @character.oy
      end
    end
    # Set visible situation
    self.visible = (not @character.transparent)
    # If graphic is character
    if @tile_id == 0
      # Set rectangular transfer
      sx = @character.pattern * @cw
      sy = (@character.direction - 2) / 2 * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    # Set sprite coordinates
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    # Set opacity level, blend method, and bush depth
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    # Animation
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end

Now, on any map you can use an event command (script):

$game_map.events[5].oy += 64

This will offset event[5] by 64 pixels.

I'll work on compartmentalizing this, so it's more portable in case someone else wants to use it as well.

give it a shot.

Be Well


[ Squid Note ] It took me a lot of head scratching to figure out how $game_map ties to @spriteset  [ /Squid Note ]
 
Oh, man, I'm sorry.  I wasn't saying I wanted YOU to script it.  I'm not that presumptuous.  I was hoping someone would have a non-scripting solution before I made an official request in the script section.  Still, I'll give this a try.  Thanks for your help, you went way farther than you had any reason to.  I guess I need to be clearer next time.
 
Okay, I've tried the script but I get an error message each time I enter a map where the script activates.  'No Method Error' 'undefined method'.  The event I'm trying to apply it to is 002:ev002.  I've tried inputting the script exactly as you've indicated.  I've tried '$game_map.events[2].oy += 64' '[002]', '[ev002]', I continue to get the error.  I'm sure this is just stupidity on my end, but as I'm not at all clear on ruby syntax I'm pretty lost.  Sorry for being such a bother.
 
I was being a bit sarcastic. (or is it 'sardonic'?)  :)  <- see the smiley!
I didn't mind doing the script. I needed to learn how the Sprites were connected
with the Events anyways.

I left something out....  (brain fart) :D

In Game_Character, right after "def initialize",  put
Code:
    @ox = 0
    @oy = 0

It doesn't like those properties not having a value to start out with.

How are you executing "$game_map.events[2].oy += 64"?

I did it with an "autorun" event in an inconspicuous place on the map.
Make sure you use a self-switch to turn off the autorun event.
Also make sure that you have an event 002 on the map.

Let me know how it goes.

I also noticed that if you put the command in the same event that your moving,
you can get it to move multiple times. (this could come in handy.)

Be Well
 
I must be doing something wrong.  I did as you said to, autorun, self-switch, event 2 is there, but it doesn't move at all.  I tried changing '64' to something higher, no movement. 
Page 1:  the script, set self-switch A to 'On', autorun
Page 2:  self-switch A 'On'
 
The next time you can ask me directly.. ^^

Shift Event Script (optional!):

The event graphics can be shifted via a comment.

$pixelmovement.player_shift_x  / $pixelmovement.player_shift_y: The shift of the player in x/y direction

To change the shifting of an event graphic, just add a comment to this event:
Shift X: 16
Shift Y: 32

Pixel Event Setting (optional!):

Via a comment at the beginning of the first event's page you can change the event's starting position on single pixels The comment has to look like this:
Teleport: x,y


Two things which could help you.. and you would have seen it yourself, if you would have taken a look into the ReadMe file.. :P
 

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