(http://dl.dropbox.com/u/56282677/rmxp/zoom.jpg)
i'm using that function to fade objects out (like a diminishing flame) however i want it to shrink towards the middle of the sprite instead of to the bottom (see picture^).
the first thing i tried was something like
sprite.oy -= (original_height - new_height) / 2, then i discovered it's not the sprite but the pixels in it that get increased/decreased.
so then i tried it like this (added to sprite_character):
# subtract the old
self.oy -= @zoom_center
# calc the new
@zoom_center = (self.bitmap.height - (self.bitmap.height * @character.zoom)) / 2 unless self.bitmap == nil
# add the new
self.oy += @zoom_center
self.zoom_x = @character.zoom
self.zoom_y = @character.zoom
but now it drops down to the bottom of the sprite rect, slowly goes up to the middle and drops down again to where zoom_x originally made it end up.O_O
this is the most logical way i could think of, and all other attempts have slowed the dropping down but still ended up at the bottom.
Have you tried just changing the sprites y instead of the the origin y?
yep, still drops. no matter what i do, the added number always seems to either be too high or too low, respectively making it rise or drop over time. it also seems to drop/rise faster as it gets smaller. which makes no sense to me unless there's some element i don't know about in the zoom function (haven't found any info on it anywhere either).
Shouldn't you just set the ox and oy to the center of the sprite? Why are you trying to subtract from it? It'd make more sense to set the origins to the center and then decrease the zoom_x and zoom_y.
i thought so too, but it doesn't work. as the sprite shrinks, it drops for whatever reason. the subtraction/addition is an attempt to compensate for that, but i can't find anything steady to base this compensation on, so it overcompensates and faulters.
Create a viewport only for for this sprite, settings is size to the size of the bitmap (largest frame of the oom), and its location where the sprite needs to be. Set the sprite x and y to 0. Set sprite ox and oy to center of viewport. Shrink away.
how do i set the new viewport to the current sprite?:/ sorry i'm not terribly familiar with viewports yet.
@sprite = Sprite.new(viewport)
from outside of Sprite_Character then?
Does @sprite.viewport = viewport not work? Sorry, I haven't worked with RMXP in so long.
i think .viewport is read only and the sprite gets generated in spriteset_map, so @sprite won't work inside sprite_character. self works instead, but i still don't know how to set a different viewport to it.:p
(self = Sprite.new(viewport) doesn't work either)
The character is initialized with a viewport.
sorry i really don't know what you mean. generate a new sprite to be zoomed inside Sprite_Character and set all its properties to self and erase the former sprite? or change the viewport set in Spriteset_Map? (but then i wouldn't know its width/height)
In Spriteset_Map the character is being initialized with the viewport passed as an argument.
how can you know the size of the bitmap before the sprite is initialized?O_O (short of making all bitmaps a standard size, but that's not very dynamic)
anyway i found a formula that works more or less well enough for what i need it for. it's not "clean" but ohwell. thanks for the trouble guys.