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.

How to change a sprite character's z variable

you still aren't explaining properly. If you mean changing the priority of something in the tileset, its in the database.

EDIT: and this is the wrong forum. You should have put it in general support.
 
kaBOOM, I don't know if anything like this is possible, because what you are describing is in a 3d context (X coordinate, Y coordinate, and Z coordinate) , and RMXP is based around 2d, and not 3d. what i think you would have to do is create a characterset where the picture under the character is drawn as you would want it to be. Hope this helps.

WarriorAngel
 
What I mean with "Z variable" is the priority the picture has to the viewer. Nothing to do with 3D. For example: the priority of a 'sprite picture' is higher than that of a 'sprite character'. That's why a pictures is always on top of the characters. What I want to do i precisely break that pattern and make the 'sprite picture' go under (lower z value) a 'sprite character'...

Why? Well, its a secret...
 
You can change the z-value of any sprite with the following code:
Code:
# Change the z-value to 100
sprite_object.z = 100
Of course, the difficult part is to actually get the sprite-object.

Add the following code in a new script:
Code:
class Spriteset_Map
attr_reader :character_sprites, :picture_sprites
end
class Scene_Map
attr_reader :spriteset
end
This enables you to gain outside access to the character-sprites (event- and playersprites)
After that you should be able gain access to the sprite via:
Code:
$scene.spriteset.character_sprites[id].z = 100
# Picture
$scene.spriteset.picture_sprites[id].z = 100
Note that this only works during the map, should be done via the Script-command. The id should be the event-ID on the current map (so 1 will get you the sprite of the event with the ID 1). The player-sprite is the last object in that array and can be easily accesed using -1 as the id.

Higher Z-Values means "nearer" to the player. The map-tiles start at value 0, i'm not enterily sure how the priority and layer is handled, this is a bit more complex. Beware, that if you change the z-value the handling of priority with the tilemap can become obsolet or a problem.

Hope this helps.
 
Thanks a lot. The code you gave me(with some modifications I made, like changing 'reader' to 'accesor') work pretty good to change the characters z variable in respect to themselves ('sprite characters'), but for some reason the 'sprite pictures' seem to STILL be ON TOP of the 'sprite characters'. Why is that?
 
I think it is because they are on different viewports.(Spriteset_Map)

Code:
    @viewport1 = Viewport.new(0, 0, 640, 480)
    @viewport2 = Viewport.new(0, 0, 640, 480)
    @viewport3 = Viewport.new(0, 0, 640, 480)
    @viewport2.z = 200
    @viewport3.z = 5000

Pictures are in Viewport 2 while the characters are in 1.

You can always display pictures by code, I don't suggest messing with the viewport settings.
 

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