*Updated* Object Manipulation (DynamicSprite)

Started by magintz, Wed 04/02/2009 20:32:13

Previous topic - Next topic

magintz

This is a new post, but wanted to save space, SSH's reply was to my old issue which is now fixed.
Original issue had DynamicSprite* sprite within the function rather than being global so was being lost immediately after calling.

I am trying to improve my game by replacing the RawDrawLine I have with an object as the line needs to be intractable.  I'm trying to use a DynamicSprite to stretch and skew the image and assign that new sprite to the object of my choosing.

I'm messing around in a test ags document using the default template at the moment and this is what I have.

Code: ags

DynamicSprite* sprite;

while(count < 359)
  {
    Wait(8);
    sprite = DynamicSprite.CreateFromExistingSprite(6);
    sprite.Resize(2, 350); // This makes the single red dot a thin line
    sprite.Rotate(1+count); // Incrementally rotate
    object[0].Graphic = sprite.Graphic;
    count+=2;
  }


The problem I'm having is getting the line to rotate properly through the angles like a clock hand going clockwise. I want the starting point (which is in the top right hand of the screen) to remain the same and the hand to rotate around that central point. It manages fine for the first 90 degrees but then starts bugging out. I'm pretty sure it's to do with the objects co-ordinates being the bottom left most pixel of the object which doesn't change, but the objects size is changing as the image rotates.

I could really use some further help here.

Cheers guys n gals,
Maggi
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

SSH

You need to keep the sprite pointer as a global variable, or when the function finishes, the sprite gets deallocated...
12

magintz

Quote from: SSH on Wed 04/02/2009 20:56:51
You need to keep the sprite pointer as a global variable, or when the function finishes, the sprite gets deallocated...

Thanks, new problem though: updated in first post.

Any help is appreciated, please re-read first post.

Magintz
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

Pumaman

Quote from: magintz on Wed 04/02/2009 20:32:13
The problem I'm having is getting the line to rotate properly through the angles like a clock hand going clockwise. I want the starting point (which is in the top right hand of the screen) to remain the same and the hand to rotate around that central point. It manages fine for the first 90 degrees but then starts bugging out. I'm pretty sure it's to do with the objects co-ordinates being the bottom left most pixel of the object which doesn't change, but the objects size is changing as the image rotates.

Why not have the sprite contain a half transparent section and half line section so that you can rotate it about a central point easily?

magintz

#4
I'm slightly confused about what you mean. I've had a look further and I can't tell where the object is positioned. It doesn't seem to rotate around any kind of point or centre. How does the DynamicSprite.Rotate function work exactly?

Edit: I've run a quick test with a test image showing you how it's rotating. As you can see nothing is staying where I expect it to.


Code: ags

while(count < 359)
  {
    Wait(8);
    sprite = DynamicSprite.CreateFromExistingSprite(8);
    sprite.Rotate(1+count);
    object[0].Graphic = sprite.Graphic;
    count+=2;
  }
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

strazer

Hey, just a quick note: Please don't completely rewrite your original posts. It makes it hard to follow the thread and there won't be a record of the original problem as reference for other people looking for a solution to the same problem.

Cheers

magintz

Ok, I've made a note in the first thread. Sorry bout that.

I assume what is happening with my prblem is the way it gets resized: here's an example.



The black border shows the complete outline of the sprite boundaries. With the bottom left pixel remaining in the same place the image does not rotate as desired.

I still don't understand what Pumaman suggested, but if someone can clarify or make some suggestions it would be greatly appreciated.
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

Pumaman

Ok, it seems like I didn't properly understand your initial post.

The problem with rotation is that the sprite width and height will change each time depending on the angle, so it's hard to position it.

What you could do is pass the Width and Height into the Rotate command, to get a fixed output size which would then be easier to keep in a fixed position.

SSH

What I did for this problem in the walkcylce generator was to calculate where I wanted the CENTRE on the unrotated sprite to be, rotate it and then make sure the CENTRE on the rotated sprite was the same point.
12

magintz

Fantastic, I think that should work.

Regards, Magintz
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

SMF spam blocked by CleanTalk