I've been having some issues where if I attempt to resize a character's current frame as a dynamic sprite it doesn't actually update onscreen. Here's the code I'm using:
void CorrectSize(this Character*)
{
ViewFrame *CharacterFrame=Game.GetViewFrame(this.View, this.Loop, this.Frame);
if(CloudsNew[this.ID].Sprite!=null)
{
CloudsNew[this.ID].Sprite.Delete();
}
CloudsNew[this.ID].Sprite=DynamicSprite.CreateFromExistingSprite(CloudsNew[this.ID].FromGraphic, true);
CloudsNew[this.ID].Sprite.Resize(CloudsNew[this.ID].Width, CloudsNew[this.ID].Height);
CharacterFrame.Graphic=CloudsNew[this.ID].Sprite.Graphic;
}
Hopefully, that's not too confusing - cloudsnew is just a struct where I'm storing all the extra variables relating to my character extender functions. If I add a line setting an object's graphic to CharacterFrame.Graphic the object graphic does change as I'd expect (so the frame itself is being resized correctly), but the character remains unchanged. Strangely, if I use a drawing surface on the dynamic sprite, then the character will update, but not otherwise. Is there some command I should be running in order for the character to update its graphic? I'm using CustomRes build 3.3.0, if that's relevant.
Thanks, and apologies if I'm missing something silly.
Maybe I'm missing something too.
But this should not be the right order ?
DynamicSprite *pv[20]; // outside
int s (int view, int loop, int frame)
{
ViewFrame *vf = Game.GetViewFrame(view, loop, frame);
return vf.Graphic;
}
void CorrectSize(this Character*, int loop, int frame)
{
int a = loop * 4 + frame; // examples
int p = s (this.View, loop, frame);
pv[a] = DynamicSprite.CreateFromExistingSprite(p);
DrawingSurface *ds = pv[a].GetDrawingSurface();
ds.DrawImage(0, 0, s (this.View, loop, frame) );
// resize part
ds.Release();
ViewFrame *vf = Game.GetViewFrame(this.View, loop, frame);
vf.Graphic = pv[a].Graphic; // I finally realized
}
Thanks, I played around with your code a bit but that doesn't actually seem to be the source of the problem - though led to me figuring it out. It seems that my deleting the dynamic sprite is the issue - this leads to the new dynamic sprite being created in the same slot as the old one (i.e. with the same graphic int), which seems to be result in the engine not realising that the new sprite is different. Easy enough to work around - I just created another DynamicSprite pointing to the old sprite and wait to delete it after the new one has been created. Thanks for the help, regardless.
Indeed, the code was not to solve the problem at all, only showing you the proper order to do something alike..
Quote from: Junkface on Sun 09/11/2014 00:59:56
Is there some command I should be running in order for the character to update its graphic?
I'm glad that in one way or another you've solved this.
Salute