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
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
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