The z-space problem of displaying sprites
#1
I wanted to make a sprite that follows a character like a visual equipment script without size restrictions, so I made the script below while studying and putting together several scripts for the past few days.
And the results were generally very satisfactory.

But one more problem arose.
If you adjust the z of the sprite created in this way, it will either go above everything on the screen, or below everything, and become invisible.
I honestly don't know what to do.
self.z I thought was the z value of the character's sprite.
It is not simply on top of the character sprite, but on top of the entire screen.
self.viewport.z also doesn't work
I also put it in viewport.z
I tried putting it in @_HEAD_sprite.z as well, but it doesn't work as I want.
What should I do?

current situation              what i want
[Image: sprite-0004-gif.253550]                                [Image: sprite-0003-gif.253551]

Code:
class Game_Character
  attr_accessor :sprite_HEAD
end



class Sprite_Character < Sprite_Character
  def create_HEAD_sprite(text)
   
    $game_variables[195]="Graphics/Characters/197-Support05"

    bitmap = Bitmap.new($game_variables[195])

    viewport = Viewport.new(self.x,self.y,bitmap.width/4,bitmap.height/4)
    viewport.z = self.z
    @_HEAD_sprite = Sprite.new(viewport)
    @_HEAD_sprite.bitmap = bitmap
    @_HEAD_sprite.ox = 0
    @_HEAD_sprite.oy = 0
    @_HEAD_sprite.x = self.x - bitmap.width/8
    @_HEAD_sprite.y = self.y - bitmap.height/8
    @_HEAD_sprite.z = self.z
    @_HEAD_sprite_visible = true

  end



  def dispose_HEAD_sprite
    @_HEAD_sprite.dispose
    @_HEAD_sprite_visible = false
  end

  def update_HEAD_sprite
    if @character.sprite_HEAD != nil

      if not @_HEAD_sprite_visible
        create_HEAD_sprite(@character.sprite_HEAD)
      end
     
      @_HEAD_sprite.viewport.rect.set(
      self.x-@_HEAD_sprite.bitmap.width/8,
      self.y-@_HEAD_sprite.bitmap.height/4,
      @_HEAD_sprite.bitmap.width/4,
      @_HEAD_sprite.bitmap.height/4)
      if @_HEAD_sprite.bitmap != $game_variables[195]
         @_HEAD_sprite.bitmap = Bitmap.new($game_variables[195])
      end

     
      @_HEAD_sprite.x = self.character.pattern * -@_HEAD_sprite.bitmap.width/4
      @_HEAD_sprite.y = (@character.direction - 2) / 2 * -@_HEAD_sprite.bitmap.height/4
      @_HEAD_sprite.viewport.z = self.viewport.z
    else
      if @_HEAD_sprite_visible
        dispose_HEAD_sprite
      end
    end
  end
    
  def update
    super
    update_HEAD_sprite
  end
end
Reply }


Messages In This Thread
The z-space problem of displaying sprites - by icogil - 02-18-2023, 08:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Problem with drain script form the ATOA ACBS Djigit 2 5,544 07-12-2015, 09:17 PM
Last Post: Djigit
   Event collision problem with FPLE script ThePrinceofMars 2 5,768 11-11-2014, 06:30 PM
Last Post: ThePrinceofMars
  Custom meter problem daylights 13 16,137 08-12-2013, 03:34 AM
Last Post: daylights
   [RUBY] Depack Thread Problem Narzew 1 4,386 07-20-2012, 01:16 PM
Last Post: Narzew
   Advantages & Charlie Fleed CTB problem Yin 7 11,972 12-12-2011, 03:45 PM
Last Post: Yin
   Charlie Fleed's CTB - Problem with dual wielding characters MegaPowerNinja 2 5,855 04-25-2011, 09:51 AM
Last Post: Charlie Fleed
   Slight problem with Omega Quest script. Boot 4 8,646 03-08-2011, 02:53 AM
Last Post: BlackDragon 31
   Help on an old problem. Yin 5 9,351 12-07-2010, 02:55 AM
Last Post: Yin
   AMS script problem Thehero 2 6,560 05-18-2010, 07:30 AM
Last Post: Jaberwocky
   Window Visibility Problem computerwizoo7 7 11,293 05-10-2010, 05:53 PM
Last Post: deValdr



Users browsing this thread: 8 Guest(s)