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.

[Resolved] Sprite coordinates not visually updating

Is there any common known reason to why new coordinates given to sprites don't update on the screen? Naturally, I've checked that my coordinates update exactly as intended, but I don't see my sprites changing their positions visually on the screen at all.

I'm keeping a solid 40 FPS, so Graphics.update is definitely being called properly. I've checked that the methods in question are definitely being run at a constant rate by printing the details.

Below are the methods currently in question.
Code:
  def render

    # Update necessary modules

    Graphics.update

    Input.update

    # Update player

    @player.update

    # Update all sprites

    @spriteset.tiles.each {|tile| tile.update}

  end
The "@player" variable here refers to my Player class, which is the main sprite object that inherits RPG::Sprite, but as its coordinates dynamically changes, and I've proven so by outputting the coordinates into a console repeatedly, the sprite's position visually on the screen stays the same. Here's the player class (note it's completely unfinished, and I'm no master in coding. I tend to fix things as I go, right now I only wish to fix the graphic coordinate issue):
Code:
#============================================================================

# ** Player

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

#  This class contains the player sprite and its functions.

#============================================================================

 

class Player < RPG::Sprite

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

  # * Constants

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

  Left = 0 ; Right = 1

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

  # * Public Instance Variables

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

  attr_accessor :dir

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

  # * Object Initialization

  #      graphic : string name of the character graphic

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

  def initialize(graphic)

    super()

    # Set bitmap

    self.bitmap = RPG::Cache.character(graphic,0)

    # Set coordinates

    self.x = 96

    self.y = 288

    self.z = (Game::PlayerLayer * 500) + 250

    width   = self.bitmap.width / 4

    height  = self.bitmap.height / 4

    self.src_rect.set(0,0,width,height)

    # Set variables

    @dir    = Right

    @step   = 0

    @moving = false

    @jumping= false

    @falling= false

    @tiles  = 0

    @route  = nil

    # Set destination coordinates

    @destination = nil

    # Set source rectangle

    set_graphic

  end

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

  # * Update

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

  def update

    return unless self.visible

    super

    # Set graphic

    set_graphic

    # If moving: update movement

    update_movement if moving?

    # Return if processing

    return if Game.processing?

    # If there's no tile under the player

    if Engine.scene.passable?(self.tile_x,self.tile_y+1) and !@jumping

      @falling = true

      @moving = true

      return

    elsif !Engine.scene.passable?(self.tile_x,self.tile_y+1) and @falling

      @falling = false

      @moving = false

      return

    end

    # If jump key and not jumping

    if Input.trigger?(Game::JumpKey) and !@jumping

      jump

    end

    # Check for movement keys

    if Input.press?(Input::LEFT)

      move_left

      return

    elsif Input.press?(Input::RIGHT)

      move_right

      return

    end

  end

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

  # * Update Movement

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

  def update_movement

    # If destination isn't nil

    unless @destination.nil?

      # If destination has been reached

      if [self.tile_x,self.tile_y] == @destination

        @destination = nil

        @route = nil

        @step = 0

      else

        case @dir

        when Left

          self.x -= 4

        when Right

          self.x += 4

        end

        unless (@jumping or @falling)

          @step += 1

          @step %= 4

        end

      end

      return

    end

    # When jumping

    if @jumping

      if Engine.scene.passable?(self.tile_x,self.tile_y-1) and

        ![self.tile_x,self.tile_y] == @tiles

        self.y -= 8

      else

        @falling = true

        @jumping = false

      end

    end

    # When falling

    if @falling

      if Engine.scene.passable?(self.tile_x,self.tile_y+1)

        self.y += 8

      else

        @falling = false

      end

    end

    # If route isn't empty

    unless @route.nil?

      if @route == "move_left"

        if Engine.scene.passable?(self.tile_x-1,self.tile_y)

          @destination = [self.tile_x-1,self.tile_y]

          @dir = Left

        else

          @route = nil

        end

      elsif @route == "move_right"

        if Engine.scene.passable?(self.tile_x+1,self.tile_y)

          @destination = [self.tile_x+1,self.tile_y]

          @dir = Right

        else

          @route = nil

        end

      end

      return

    end

    # If not falling or jumping: set moving off

    unless (@falling and @jumping)

      @moving = false

    end

  end

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

  # * Move Left

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

  def move_left

    return unless @route.nil?

    @route = 'move_left'

    @moving = true

  end

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

  # * Move Right

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

  def move_right

    return unless @route.nil?

    @route = 'move_right'

    @moving = true

  end

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

  # * Jump

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

  def jump

    @tiles   = [self.tile_x,self.tile_y-3]

    @moving  = true

    @jumping = true

  end

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

  # * Moving?

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

  def moving?

    @moving

  end

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

  # * Tile X

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

  def tile_x

    self.x / 32

  end

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

  # * Tile Y

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

  def tile_y

    self.y / 32

  end

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

  # * Set Graphic

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

  def set_graphic

    return unless self.visible

    # Obtain width and height of frames

    width   = self.bitmap.width / 4

    height  = self.bitmap.height / 4

    self.ox = width / 2

    self.oy = height - 32

    # Set ch

    ch = (@jumping or @falling) ? height * 2 : 0

    # Direction case

    case @dir

    when Left

      self.src_rect.set(@step * width,ch,width,height)

    when Right

      self.src_rect.set(@step * width,height+ch,width,height)

    end

  end

end
The methods that refer to the "Engine" module returns the boolean values I intend them to return, so that isn't very important to include here.

Anyone got any ideas on what I am doing wrong?

Thanks!
 
The sprites, including the player's sprite, are in the spriteset's @character_sprites. There shouldn't be a problem If you're calling spriteset.update somewhere.
I'm just guessing here, but an events' moving? method should return true if it's currently moving from one tile to the next one. Yours returns true only when jumping and falling.
 
This doesn't base itself upon any of the default scripts. There is no such thing as a Spriteset_Map, only my sprites drawn on the screen.

But I fixed it. Thanks for the reply. Was an issue with the Graphics module that I had to change.
 
For general enlightment, might want to share your fix for this?

Also, setting RPG::Sprite as the superclass for a playable instance is, while functional, pretty cluttery and could or should cause you problems sooner or later that you probably wouldn't have going the normal way (class Game_Player; def initialize('graphic'); @graphic = RPG::Sprite.new; @graphic.bitmap = RPG::Cache.characters(graphic); end; end - very roughly and probably containing a thousand syntax errors, but you get me)...
However, everything could just as well work out fine, so yeah... whatever floats your boat ^^ Just saying having a visual class as superclass for a functional class seems odd.
 
Well, the whole project that I am working on has none of the default RMXP scripts, only classes and modules present in the DLL. This caused some strange issues with the Graphics module in the way I set up the rendering process of the whole system. For an unknown reason, Graphics.transition did not execute as intended, so the Graphics kept being frozen from Graphics.freeze. Naturally this doesn't make any sense, and I'm sure that it's entirely due to my bad way of scripting the system, so I'm not entirely sure how to get around this ignoring of the transition method, but I'll look into it. Currently I'm only commenting out my Graphics.freeze method until I need to meddle with it. I only wish to make sure that my game handling of sprites works as intended first.

And yes, I do actually agree there, and decided to change it into what you suggested. It works as I intended it to, but it sounds much more ideal to assign the sprite to a seperate variable indeed. Thanks for that input.
 
Hm... as for Graphics.transition, that shouldn't cause you any problems as long as it's properly called. Zeriab's Community Evolutionary Script Project is a pretty good example on how you can make it work... I hope that'll give you an idea on what's going on with your script.

On a side note, that topic somehow made me further look into developing outside RPG Maker tools, getting my hands on Ruby/Gosu. You seem to get tired of RMXP's default system as well, so yeah... maybe you'll have les headaches trying Gosu out, which is completely transparent and way less resource-expensive (and therefore has a better performance). Just a suggestion ;)
 

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