Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Problem with SetSpriteShapeBox

Author
Message
Max Tillberg
18
Years of Service
User Offline
Joined: 16th Jul 2005
Location:
Posted: 3rd Sep 2013 15:28 Edited at: 3rd Sep 2013 15:30
I wonder if someone could help me with the SetSpriteShapeBox command? For some reason it is centered at the middle of sprites and I wonder if it should. The problem is that it gets quite hard to calculate the angle.

If I tries the following, the box is offset from the sprite


This works better but the angle is off since the instert point differs.


I use the latest beta and Tier 1.

Sincerely,
Max Tillberg
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Sep 2013 15:43
i think the shape is set for non rotated sprites because it rotates with the sprite. the angle is a optional shift if the image is rotated.

the shape its centered by default.
there exists also a simple box shape command.
SetSpriteShape( iSpriteIndex, shape )
0=no shape, 1=circle, 2=box, 3=polygon
Max Tillberg
18
Years of Service
User Offline
Joined: 16th Jul 2005
Location:
Posted: 3rd Sep 2013 15:55
According to the help file "The box is defined by specifying its top left and bottom right coordinates in sprite space, relative to the top left corner of the sprite." Does not this indicate the the insert point is top left and not center of the sprite? The reason I can't use SetSpriteShape is that I want the physics box to be smaller than the sprite. I guess I could recalculate the angle myself but it is not that easy.

Sincerely,
Max Tillberg
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Sep 2013 16:04
I actually reported this issue to Paul quite some time ago and he fixed it. My guess is that somehow the bug has crept back in. I will send him an email.

"Everything should be made as simple as possible, but not simpler."
Max Tillberg
18
Years of Service
User Offline
Joined: 16th Jul 2005
Location:
Posted: 3rd Sep 2013 16:11
Thanks a lot. I guess AppGameKit still have some issues but hopefully it will get out of beta soon.

Sincerely,
Max Tillberg
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Sep 2013 16:12
Might be easier specifying lines instead of the box, like the box sides in turn - then you can offset them however you like, even have an irregular box if you need it, or specify a more ideal shape for the sprite.

I am the one who knocks...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Sep 2013 16:36
In the above case you could just use:


The only time you need the other version is if you are using a none bounding box shape...

"Everything should be made as simple as possible, but not simpler."
Max Tillberg
18
Years of Service
User Offline
Joined: 16th Jul 2005
Location:
Posted: 3rd Sep 2013 16:36 Edited at: 3rd Sep 2013 16:37
Van B, When you say "specifying lines", are you thinking of addSpriteShapePolygon or is there some other method?

Sincerely,
Max Tillberg
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Sep 2013 16:43
I think that's what VanB means. This got me thinking though, have you tried using AddSpriteShapeBox rather than SetSpriteShapeBox? (You might have to SetSpriteShape(spriteID, 0) first)

I wonder if it was the Add command Paul fixed rather than the Set command (which deletes existing shapes on a sprite before creating a new one).

"Everything should be made as simple as possible, but not simpler."
Max Tillberg
18
Years of Service
User Offline
Joined: 16th Jul 2005
Location:
Posted: 3rd Sep 2013 16:58
I have the same problem with AddSpriteShapeBox (centered) plus I end up with two boxes even if I don't use SetSpriteShape. I tried to ClearSpriteShapes but only the manually added sprite is removed.

Sincerely,
Max Tillberg
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Sep 2013 17:18
Max Tillberg, can you post some example code?

"Everything should be made as simple as possible, but not simpler."
Max Tillberg
18
Years of Service
User Offline
Joined: 16th Jul 2005
Location:
Posted: 3rd Sep 2013 17:54
Sure thing, here is the complete code



Sincerely,
Max Tillberg
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Sep 2013 18:07
This needs changing: GetSpriteAngleRad(1)
To this: GetSpriteAngle(1)

Can you post a screenshot, I haven't got AppGameKit at work and freedom engine seems to not display debug...

"Everything should be made as simple as possible, but not simpler."
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 3rd Sep 2013 18:27 Edited at: 3rd Sep 2013 18:29
The help files are incorrect in this case, the box is now relative to the offset point rather than the top left corner. However the angle parameter is handled by Box2D which always rotates the box around its center.

This only matters if you want the box to be at a different angle than the sprite since it will still rotate with the sprite. It seems in this case you want the box to line up with the sprite by using GetSpriteAngle, this is not necessary and an angle of 0 should line it up.
Max Tillberg
18
Years of Service
User Offline
Joined: 16th Jul 2005
Location:
Posted: 3rd Sep 2013 18:32 Edited at: 3rd Sep 2013 18:33
I changed to GetSpriteAngle in a third example but I am rather sure the angle should be in degrees. Anyway, the angle is still wrong.




Sincerely,
Max Tillberg
Max Tillberg
18
Years of Service
User Offline
Joined: 16th Jul 2005
Location:
Posted: 3rd Sep 2013 18:41
Thanks Paul,
There is still two things that I do not understand. I have not changed the offset, should it not 0,0 be in the upper left corner of the sprites. I am rather sure that in my example it is in the middle of the first sprite. My second question is how I set the angle in SetSpriteShapeBox so it is alligned to the sprite?

Sincerely,
Max Tillberg
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Sep 2013 19:01
Quote: "There is still two things that I do not understand. I have not changed the offset, should it not 0,0 be in the upper left corner of the sprites. I am rather sure that in my example it is in the middle of the first sprite."

No, the offset is in the centre of the sprite by default.

Quote: "My second question is how I set the angle in SetSpriteShapeBox so it is alligned to the sprite?"

The angle should be zero as it is relative to the sprite not the world.

"Everything should be made as simple as possible, but not simpler."
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Sep 2013 19:12
Max Tillberg
18
Years of Service
User Offline
Joined: 16th Jul 2005
Location:
Posted: 3rd Sep 2013 19:15
Thanks a lot everybody, now it works.

Sincerely,
Max Tillberg

Login to post a reply

Server time is: 2024-05-03 10:39:39
Your offset time is: 2024-05-03 10:39:39