Blackyu

Professional Procrastinator
Veteran
Joined
Jul 10, 2016
Messages
114
Reaction score
337
First Language
French
Primarily Uses
RMVXA
Hi! I'm looking to do pretty much what the title says on RPG Maker VX Ace.

I have a big sprite, much larger than 32x32, and I had a problem with it being anchored wrong, which didn't look good at all.
Thanks to this previous post, I learned that I could fiddle with the .oy value of the Sprite object in order to anchor it properly, but I'm having an issue with selecting the correct sprite index.

In order to retrieve the sprite and center it correctly, I'm using this script snippet:
Code:
spriteset_map = SceneManager.scene.instance_variable_get(:@spriteset)
sprites = spriteset_map.instance_variable_get(:@character_sprites)
spider_sprite = sprites[SPRITE_INDEX]
spider_sprite.oy -= 26

The issue is, due to the sprite not being there on map load (the event in question is activated later), that I have no way to predict which index the sprite will have in the character spriteset. In other words, I don't know what SPRITE_INDEX should be.

I guess I could bruteforce all sprites indices until I find the right one, but I'm not so sure that it'll remain the same at all times, and that solution seems shaky to me. If I add another event on the map, it could offset the correct sprite's index in the spriteset and I'd have to guess again!

So I'm wondering if there could be a better way to find the sprite I'm looking for.
Let's say that I know the event's ID whose sprite I want to edit. Are there any script calls that would allow me to reach the Sprite object from the Event so I can change the .oy value?

Any help much appreciated!
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
3,132
Reaction score
2,257
First Language
Spanish
Primarily Uses
RMVXA
due to the sprite not being there on map load (the event in question is activated later)
why not go to that routine and change the sprite before it's even loaded? 0o
if you know where it comes from, where it is, and where it should be, then you know where it's defined for the first time.
 

Blackyu

Professional Procrastinator
Veteran
Joined
Jul 10, 2016
Messages
114
Reaction score
337
First Language
French
Primarily Uses
RMVXA
why not go to that routine and change the sprite before it's even loaded? 0o
if you know where it comes from, where it is, and where it should be, then you know where it's defined for the first time.
Yes, I know exactly which event it is and when it is activated, but it still doesn't tell me which index the sprite is going to have in the spriteset when the event's relevant page is activated.
The solution I'm currently using to change the sprite's anchor requires me to know the index of the Sprite object I need to edit in the character spriteset, which I don't.

That's why I'm asking if there's a way to directly reach the Sprite object from an Event object via scripting, because that would bypass the sprite index thing entirely.

And I'm afraid I cannot edit the sprite file at all, because the problem isn't so much with the sprite itself, but just the fact that RM anchors sprites at the bottom by default, which is what the .oy business intends to fix.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
3,132
Reaction score
2,257
First Language
Spanish
Primarily Uses
RMVXA
it still doesn't tell me which index the sprite is going to have in the spriteset
what for?
the sprite here is the same sprite there.
it is, literally, the same sprite.
once you let go of it from the creation process, THEN it becomes "that sprite over there from that process"
change the origin at creation time and then pass it up to the next process.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
1,133
Reaction score
538
First Language
English
Primarily Uses
RMXP
First get the event's character_name. Then go to the spriteset's @character_sprites and use select to find all events that match that name. In theory you should only find one inside the [array] it returns. Find it by selecting the first position using array [0] or array.first
 

Blackyu

Professional Procrastinator
Veteran
Joined
Jul 10, 2016
Messages
114
Reaction score
337
First Language
French
Primarily Uses
RMVXA
First get the event's character_name. Then go to the spriteset's @character_sprites and use select to find all events that match that name. In theory you should only find one inside the [array] it returns. Find it by selecting the first position using array [0] or array.first

I tried to put it all together and eventually made it work!

For any future readers, the script snippet I used was the following:

Code:
ev_id = 48

spider_char_name = $game_map.events[ev_id].instance_variable_get(:@character_name)

spriteset_map = SceneManager.scene.instance_variable_get(:@spriteset)
sprites = spriteset_map.instance_variable_get(:@character_sprites)
spider_sprites = sprites.select{|spr| spider_char_name ==
  spr.instance_variable_get(:@character_name)}

spider = spider_sprites[0]
spider.oy -= 26

Thanks a ton for the help!
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
1,133
Reaction score
538
First Language
English
Primarily Uses
RMXP
I think the maker will allow you to use this call to the select method like this.

Ruby:
 spider_sprites = sprites.select{|spr| spider_char_name ==
  spr.character_name }
 

Blackyu

Professional Procrastinator
Veteran
Joined
Jul 10, 2016
Messages
114
Reaction score
337
First Language
French
Primarily Uses
RMVXA
I think the maker will allow you to use this call to the select method like this.

Ruby:
 spider_sprites = sprites.select{|spr| spider_char_name ==
  spr.character_name }

Hmmm, doesn't look like it. It doesn't recognize the character_name field and thinks it's a method.
In any case, the previous solution worked just fine, so thanks a lot for your help!

1659040945072.png
 

Latest Threads

Latest Profile Posts

oneOfUs.jpg
Streaming more Poppet Quest game even in about 12 minutes.
Some dog owners really impress me. I'm pushing 2-3 metric tons of garbage containers that destroy everything they hit. What do you think is going to happen to your tiny dog when I run it over? And why are you crossing my path to argue with me? Have you never been hit by 200kgs of garbage?

Lesson for you folks. Never mess with an angry garbage container. Or its driver.
I didn't dispose of a file properly and now my whole game won't start: I get a script error in the Scene Manager stage of game launch. What to do? Transfer it all to a new project? That's going to be tedious. Fortunately I am only nine workdays into it.
Makin' stuff on a broken laptop yay

Forum statistics

Threads
131,680
Messages
1,222,165
Members
173,424
Latest member
filfes
Top