Say I want to make my sprite.zoom_x = 80, and sprite.zoom_y = 80,
but I'm trying to trigger this effect during the time that battle is loading, or anywhere else, such as a "shrink" spell or something. What do I have to replace "sprite" with what would normally be "self" in Game_Actor and Game_Enemy classes? There appears to be no bitmap/sprite access in Game_Actor and Game_Enemy.
edit: updated for specificity.
It is because RMXP is poorly stuctured in this way. It is my biggest bitch about the scripts that it is so hard to access the sprites in relation to the proper character instance that they represent.
All character sprites are found in ther @character_sprites array in Spriteset_Map, or with Spriteset_Battle, whatever your case (I think its @battler_sprites in Spriteset_Battle). Spriteset_Map is initialized through Scene_Map. It reads all the character instances from Game_Map, and uses the string name of their graphic to load the bitmap.
Probably easiest down and dirty way to get at them is to add a "attr_accessor :spriteset" to Scene_Map, and a "attr_accessor :character_sprites" to Spriteset_Map. From there you can get at them and change them with $scene.spriteset.character_sprites[INDEX].ZOOM or whatever method you want. This is not the ideal way to do this, but it works. You can create an abbreviated call for it if you want, as well.
Quote from: ForeverZero on June 18, 2011, 04:08:59 AM
It is because RMXP is poorly stuctured in this way. It is my biggest bitch about the scripts that it is so hard to access the sprites in relation to the proper character instance that they represent.
All character sprites are found in ther @character_sprites array in Spriteset_Map, or with Spriteset_Battle, whatever your case (I think its @battler_sprites in Spriteset_Battle). Spriteset_Map is initialized through Scene_Map. It reads all the character instances from Game_Map, and uses the string name of their graphic to load the bitmap.
Probably easiest down and dirty way to get at them is to add a "attr_accessor :spriteset" to Scene_Map, and a "attr_accessor :character_sprites" to Spriteset_Map. From there you can get at them and change them with $scene.spriteset.character_sprites[INDEX].ZOOM or whatever method you want. This is not the ideal way to do this, but it works. You can create an abbreviated call for it if you want, as well.
This is definitely being used for Spriteset_Battle
Which I think is pulling from Sprite_Battler
I am considering your idea of using an attr_accessor :spriteset to something, but I'm going to guess it belongs in Spriteset_Battler, and possibly in Scene_Battle1-4, but that seems like actually more work than should be necessary to make it all happen?
Ok, so as soon as I attempted to import this stuff into game enemy
@battler_name = @battler.battler_name
@battler_hue = @battler.battler_hue
self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
it immediately pointed out it didn't recognize 'bitmap'. If I could figure out where the enemy's stat sheet is married to the enemy's sprite, then I could do something, but I'm at a loss. I don't see any correlation. I guess I will have to go back to my dummy events that spit out all the data on a print request and hope something makes sense soon.
You have to access stuff like zoom_x and zoom_y through Sprite_Battler (or enemy or whatever it is in RPG Maker XP), and change it by changing the values in Game_Enemy.
Quote from: cozziekuns on June 18, 2011, 04:48:35 PM
You have to access stuff like zoom_x and zoom_y through Sprite_Battler (or enemy or whatever it is in RPG Maker XP), and change it by changing the values in Game_Enemy.
could you get an example of the syntax used? I keep getting errors.
I've tried things like making attr accessors in Sprite_Battler and then using @zoom_x = 50 in Game_Enemy, but I must have done something wrong, because it didn't work.
Do the opposite. Make attr_accessors in Game_Enemy for zoom_x and then in the update method of Sprite_Battler check if @battler is a Game_Enemy, then write self.zoom_x = @battler.zoom_x.
So first I put in the self.zoom in the update of sprite_battler (see bottom of code):
def update
super
# If battler is nil
if @battler == nil
self.bitmap = nil
loop_animation(nil)
return
end
# If file name or hue are different than current ones
if @battler.battler_name != @battler_name or
@battler.battler_hue != @battler_hue
# Get and set bitmap
@battler_name = @battler.battler_name
@battler_hue = @battler.battler_hue
self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
@width = bitmap.width
@height = bitmap.height
self.ox = @width / 2
self.oy = @height
if @battler.is_a?(Game_Enemy)
self.zoom_x = @battler.zoom_x
end
then I've got the attr_accessor and @zoom_x = zoom_x in Game Enemy:
class Game_Enemy < Game_Battler
attr_accessor :coz_moving_x # x coordinate
attr_accessor :coz_moving_y # y coordinate
attr_accessor :zoom_x # x zoom
#--------------------------------------------------------------------------
# * Object Initialization
# troop_id : troop ID
# member_index : troop member index
#--------------------------------------------------------------------------
def initialize(troop_id, member_index)
super()
@troop_id = troop_id
@member_index = member_index
troop = $data_troops[@troop_id]
@enemy_id = troop.members[@member_index].enemy_id
enemy = $data_enemies[@enemy_id]
@battler_name = enemy.battler_name
@battler_hue = enemy.battler_hue
@hp = maxhp
@sp = maxsp
@hidden = troop.members[@member_index].hidden
@immortal = troop.members[@member_index].immortal
@coz_moving_x = 0
@coz_moving_y = 0
@zoom_x = zoom_x
end
and finally I'm trying to call it as simple as possible here in def screen_x of Game_Enemy:
def screen_x
@zoom_x = 20
Nothing happens. Clearly I'm doing something wrong.
Updating screen_x doesn't update zoom_x as far I as know. You'll have to access it through the $game_troop array. Try changing the initial value of zoom_x, and see if that works first.
Quote from: cozziekuns on June 18, 2011, 07:57:19 PM
Updating screen_x doesn't update zoom_x as far I as know. You'll have to access it through the $game_troop array. Try changing the initial value of zoom_x, and see if that works first.
ok, i figured out two things:
1. My data is being read from SDK II: Sprite Battler
so I added it here:
def redraw_battler
if @battler.battler_name != @battler_name or
@battler.battler_hue != @battler_hue
# Get and set bitmap
@battler_name = @battler.battler_name
@battler_hue = @battler.battler_hue
self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
@width = bitmap.width
@height = bitmap.height
self.ox = @width / 2
self.oy = @height
if @battler.is_a?(Game_Enemy) #added by shintashi
self.zoom_x = @battler.zoom_x
#self.mirror = true
end
That's when I ran into a problem:
Whatever @zoom_x is set to in Game_Enemy during initialization, is what it stays. Right now I've got it set for @zoom_x = 1, if I set to @zoom_x = 2, my icon gets fat and @zoom_x = 0.8 makes my icon skinny. That's what I want to be able to do, but I need to be able to do it outside of initialization. Is this "doesn't update" thing what you meant by $game_troop array?
def update
super
# If battler is nil
if @battler == nil
self.bitmap = nil
loop_animation(nil)
return
end
# If file name or hue are different than current ones
if @battler.battler_name != @battler_name or
@battler.battler_hue != @battler_hue
# Get and set bitmap
@battler_name = @battler.battler_name
@battler_hue = @battler.battler_hue
self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
@width = bitmap.width
@height = bitmap.height
self.ox = @width / 2
self.oy = @height
end
if @battler.is_a?(Game_Enemy)
self.zoom_x = @battler.zoom_x
end
end
You misplaced the if @battler.is_a?(Game_Enemy); self.zoom_x = @battler.zoom_x; end part. This means it will only refresh if the characters hue or name is changed because of the if statement.
so I figured out one way of doing it, without using an attr accessor:
case @battler.index
when 0
self.zoom_x = 0.85
self.zoom_y = 0.85
when 1
self.zoom_x = 0.9
self.zoom_y = 0.9
when 2
self.zoom_x = 0.95
self.zoom_y = 0.95
when 3
self.zoom_x = 1
self.zoom_y = 1
when 4
self.zoom_x = 0.85
self.zoom_y = 0.85
when 5
self.zoom_x = 0.9
self.zoom_y = 0.9
when 6
self.zoom_x = 0.95
self.zoom_y = 0.95
when 7
self.zoom_x = 1
self.zoom_y = 1
end
This causes the sprites to shrink as they get further away from the bottom of the screen (i.e. perspective). I plan on using the mirror effect for creating an "if surprised" effect, then I can give characters different levels of surprise resistance. 'm thinking surprised characters would probably be at an agility penalty for purposes of initiative -our family was watching Matrix last night (rerun) and it occurred to me a very fast person would be at a penalty, but not completely unable to react.
This of course doesn't mean I've figured out how to change it under the influence of a spell or future action, however.