DynamicSprite.Copy()? (SOLVED)

Started by Rui 'Trovatore' Pires, Wed 01/02/2006 15:12:43

Previous topic - Next topic

Rui 'Trovatore' Pires

So, I'm using DynamicSprites. And at one point, I want to allow the user to dynamically resize one of them. At first I just tried

        roompic.Resize(butImage.Width, butImage.Height);
        butImage.NormalGraphic=roompic.Graphic;

...but I saw the problem at once. Once resized, the image stays resized, and everytime I resize it further it becomes less and less detailed until it ends up as a big blocky thing.

No problem, I thought. I'll just create another global DynamicSprite and keep the original, unresized image in that one. So I did

        roompic=roompicresize;
        roompic.Resize(butImage.Width, butImage.Height);
        butImage.NormalGraphic=roompic.Graphic;

...which, to my surprise did not work. Logically, it should... roompic should become the stored DynamicSprite roompicresize, with no changes at all being made to roompicresize, and should then resize that original, detailed picture (now stored in roompic) and "output" it.

Then I tried the following code, to get to the bottom of it:

        roompic=roompicresize;
        roompic.Resize(butImage.Width, butImage.Height);
        roompic.SaveToFile("test.bmp");
        roompicresize.SaveToFile("test2.bmp");
        butImage.NormalGraphic=roompic.Graphic;

It then became clear (especially after commenting out and back in the "roompic=roompicresize" line) - when I do "roompic=roompicresize;", BOTH dynamic sprites get changed. Both will get resized. I also tried adding

       Display("%d,%d", roompic.Graphic, roompicresize.Graphic);

after "roompic=roompicresize;", which, surprisingly, returned the same digit, when I would expect to find two different ones: the original capture, stored in roompicresize, and the one I'm about to resize, roompic.

If I'm doing something wrong, I'd really like to know what it is. If it isn't, then I'd like to suggest, at least, a DynamicSprite.Copy(); function, to act similarly to String.Copy();.


EDIT - Ain't it fun when you find the solution just after you post.

roompic=DynamicSprite.CreateFromExistingSprite(roompicresize.Graphic);

This did the trick. But I'd still like to suggest DynamicSprite.Copy();, as it's much more intuitive and will save the forum's bandwitdh from slower people like me in the future.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

As you discovered, CreateFromExisitngSprite will do the job nicely ... while a Copy() function could be added, it's so easy to do already that I'm not sure it's worth the hassle.

Rui 'Trovatore' Pires

Then I'd like to suggeste a brief mention in the manual, maybe under "CreateFromExistingSprite", maybe even as an example? Or at least say that "sprite1=sprite2" won't do what one thinks it should do... incidently, what *does* it do?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gilbert

Hmmm just another copy of the pointer I guess?

Scorpiorus

#4
Yep, and hence 'sprite1' would point to the very same sprite.

And it's a good point that it won't do a content copy which is a common case for all AGS pointers. <--- [badly stated]

[edit]
And it's a good point that it won't do a content copy. All AGS pointers work that way.

Rui 'Trovatore' Pires

Hmm, so it gets two pointers pointing at the same sprite... confusing. Scorpiorus put it well just now - it doesn't do something which is common for all other pointers. Heck, that's what caused my confusion in the first place. :)
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Scorpiorus

Oops, it's actually me made it even more confusing -- what I meant is that all pointers behave in the same manner, ie. they all do NOT do a content copy. :)

Rui 'Trovatore' Pires

Hmmm... I think I see my confusion now.

Is the way pointers work distinct from the way integers work? Because that was my reference; I kept thinking, "If I can "int_a=int_b" and still keep int_b the same as it was, why doesn't it happen here?".

Also, I'd like someone to point out to me where this is specified in the manual, so I can feel like a total n00b who didn't rtfm. :)
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SSH

Imagine a guy pointing at something remarkable. Say, the eiffel tower. Then another guy comes along and points at the eiffel tower too. This is like having two pointers and assigning one to the other. Then, a terrorist comes and blows up the eiffel tower. This affects both pointers. To do what you want, you need to creat a new copy of the eiffel tower and just blow one of them up...
12

Rui 'Trovatore' Pires

Right-o, thanks. You see, I thought that using "sprite1=sprite2" I was doing just that - creating a copy of sprite2 in sprite1. I see the difference now. Quite a good example, that one. :)
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

In the old days, with dynamic sprites you just had the sprite number in an int.

So you might have had

int sprite1, sprite2;

If you then did:

sprite1 = sprite2;

it wouldn't make a copy of the sprite, it would just mean that sprite1 was now referring to the same sprite number as sprite2. That's the same behaviour as you get with the new system.

Rui 'Trovatore' Pires

So it is. How silly of daft ol' me.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SMF spam blocked by CleanTalk