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 / [SOLVED] What am I doing wrong to create a circular solid sprite?

Author
Message
Dale Schultz
2
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 3rd Nov 2021 23:48
I wish to create a simple solid circle using a sprite.



Instead of circles I get squares.

They do look nice, but I really want circles.

https://www.appgamekit.com/documentation/Reference/Sprite/SetSpriteShape.htm does state:
Quote: "This function will not work on dummy sprites as there is no image to use when calculating a shape, in these cases shapes must be specified manually using SetSpriteShapeBox, SetSpriteShapeCircle, or SetSpriteShapePolygon."


This is why the second attempt in the sample code tries that approach.

I am aware of DrawEllipse() but I want to change colors and set position and visibility later.

Attachments

Login to view attachments

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 4th Nov 2021 00:43 Edited at: 4th Nov 2021 02:03
This post has been marked by the post author as the answer.
The shape there is referring to the collision shape not the visual image of the sprite so, if using native commands only, u'll need to (also) draw a (white) ellipse/circle, GetImage(), then assign that image to the sprite via SetSpriteImage(). u can later SetSpriteColor(), Position() or alter it in any way that u want.

Ur code is using image 0 (basically a 10x10 px (white) image scaled to whatever u SetSpriteSize() to) while setting the collision shape to a circle. If u keep ur code as-is and SetPhysicsDebugOn(), u'll see the circle (collision) shape.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 4th Nov 2021 02:31

Found this by searching



Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Nov 2021 19:28
Technically there's little limit on how many octants (i guess the name would change) you can turn a circle into since it's such a uniform shape. 8 seemed efficient. The 3 pixels it writes at each octant is to take anti-aliasing into consideration.

When the memblock space is allocated, there's no guarantee what value each byte will have. So unlike DBP which would initialize each byte with 0 in the allocation, AppGameKit does not and therefore a 0 needs to be written all unused pixels.

Since the function writes 0s to the entire block before drawing the circle, a lot of bytes are written twice so there is room to improve efficiency. If anyone couldn't guess, I wrote that snippet :p
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 4th Nov 2021 21:08
Quote: "If anyone couldn't guess, I wrote that snippet"


I was not sure if you wanted me to say anything lol.

It would be better and faster just to create a circle sprite out side of the program then clone sprite and change its size.
Dale Schultz
2
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 5th Nov 2021 01:19
Quote: "The shape there is referring to the collision shape not the visual image of the sprite"

ah yes thanks, that makes sense.
I noticed that adding shapes were for collision shapes but glossed over that detail when I read the SetShape stuff.

Some interesting solutions to explore and in doing so I ran into the fact that the AppGameKit color definitions space is what what I thought it was. I was surprised that MakeColor() returns negative values!

I may revert back to DrawEllipse() in the main loop, I can simply keep the color needed in a global, and change that as needed and let it draw in every iteration of the sync() loop.

Thanks all.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Nov 2021 17:33
Quote: "I was surprised that MakeColor() returns negative values!"


That's weird, it shouldn't. But you're right, I just tested it. It must store in a signed integer. All white (255,255,255) gives me -1 and they numbers only decrease from there. Black gives me -16777216
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 5th Nov 2021 19:11
Tier 1 doesn't have unsigned integers. MakeColor returns negative due to the alpha value, which defaults to 255. The value is AARRGGBB in hex. so white = 0xFFFFFFFF and black = 0xFF000000.

I would think that creating a transparent image from a memblock and rendering a circle to it with DrawEllipse would be pretty quick.
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 5th Nov 2021 19:19
@Phaelax: Looks like AppGameKit *does* zero out a memblock during CreateMemblock, despite what the docs say.

https://raw.githubusercontent.com/TheGameCreators/AGKTier2/master/common/Source/Wrapper.cpp

Dale Schultz
2
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 5th Nov 2021 21:29
Quote: "That's weird, it shouldn't."


Does it say somewhere that they should be positive?

Quote: "Tier 1 doesn't have unsigned integers. MakeColor returns negative due to the alpha value, which defaults to 255. The value is AARRGGBB in hex. so white = 0xFFFFFFFF and black = 0xFF000000."

Intersting! So If Alpha is < 255 are they positive?

Quote: "I would think that creating a transparent image from a memblock and rendering a circle to it with DrawEllipse would be pretty quick."


But why would one need to do that? DrawEllipse() does work (with colors etc.) all by itself with a single call.

adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 5th Nov 2021 22:59
Quote: "Intersting! So If Alpha is < 255 are they positive?"

No, the alpha would have to be 0x7f or less. 0x80 and higher has the sign bit set for negative integers.

Quote: "But why would one need to do that? DrawEllipse() does work (with colors etc.) all by itself with a single call."

If one only wants to draw the circle, yes. I had assumed that it was to be used with a sprite, perhaps for physics or something. Just to render, yeah, the image isn't needed.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Nov 2021 15:46
Quote: "@Phaelax: Looks like AppGameKit *does* zero out a memblock during CreateMemblock, despite what the docs say."


AGK was still fairly new when I wrote that, it's possible it could have changed in an update. Or maybe I just did it to be safe, I can't remember that far back.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-04-19 19:56:53
Your offset time is: 2024-04-19 19:56:53