Hello!
What I would like to do is to capture the contents of a background, and then use this image as the graphic for an object in a seperate room.
I decided that an effective method of doing this would be to assign a graphic to a frame in a view, and then set the object's view to the same frame as the dynamic sprite.
I have written this piece of code to achieve this:
DynamicSprite* tag = DynamicSprite.CreateFromBackground();
tag.Resize(48, 32);
ViewFrame *frame = Game.GetViewFrame(VSTATION, 4, 0);
frame.Graphic = tag.Graphic;
I get this error, sadly:
---------------------------
Adventure Game Studio
---------------------------
An internal error has occurred. Please note down the following information.
If the problem persists, post the details on the AGS Technical Forum.
(ACI version 3.12.1074)
Error: There was an error drawing object 6. Its current sprite, 335, is invalid.
---------------------------
OK
---------------------------
I have checked that the frame and view correspond, and they do seem to. Is there something I have missed?
You have to move the declaration of the DynamicSprite outside the function, otherwise the pointer gets destroyed as soon as the function finishes. The garbage collection will subsequently delete the sprite, thus the error.
You're using it in another room so you have to make it global.
Btw I don't know the context but you don't need the view, you can set the Object's .Graphic directly.
Did you create the variable tag within a function? Try putting the declaration outside of the function, as it's possible that the sprite is destroyed once the pointer to it is destroyed, after the function ends.
Thank you gentlemen, I've made the function global and created the variable outside of the function and it works splendidly. I shall call this issue solved! Much appreciated.