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 / SetSpriteShape - Polygon

Author
Message
Red5
12
Years of Service
User Offline
Joined: 26th Aug 2011
Location:
Posted: 15th Sep 2011 01:18
Hi,

I am using the SetSpriteShape command to setup the collision shape for my sprite to be a polygon, i.e.

SetSpriteShape(l_sprite_id,3)

However, the collision shape is always a box (I checked this by switching on Physics debug mode); when using mode 3 with the above command it is supposed to create a close fitting convex polygon around just the visible pixels but it does not seem to work like that or else I am doing something wrong.

The sprite I am using is a triangle with the transparency set correctly.

Any ideas?

Thanks,

Red.
Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 15th Sep 2011 01:48
It works fine for me. I would guess that the sprite ID you're supplying is perhaps not the one you think it is.
Red5
12
Years of Service
User Offline
Joined: 26th Aug 2011
Location:
Posted: 15th Sep 2011 11:27
I am using the correct sprite ID.

See the attached PDF document for more info on this issue.

Thanks,

Red.

Attachments

Login to view attachments
Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 15th Sep 2011 12:41
Looking at that, the polgon collision box looks like a square collision box but it has angled corners. Are there maybe some not completely transparent pixels in that area of the sprite?

If you start a brand new project and just use one frame of your sprite instead of an atlas texture, do you get the correct polygon show up, or does it look the same?
Red5
12
Years of Service
User Offline
Joined: 26th Aug 2011
Location:
Posted: 15th Sep 2011 14:15 Edited at: 15th Sep 2011 14:32
The sprite I am using is part of an image atlas containing around 100 different sprites. The very first sprite I created was a rounded box. In this example I am displaying sprite number 41 which is a triangle and for some reason all sprite extracted from this image atlas are taking on the shape of the rounded box.

I did what you suggested and created a new project and simply copied the triangle sprite into it and then exported as a transparent PNG and it works fine.

So this kind of suggests that if you are using an image atlas there is a problem when setting the collision shape since my "new" single sprite PNG is an "exact" copy of the original triangle found in the image atlas.

Very odd!!

I would prefer to make use of an image atlas if possible because this project will have well over 100 sprites and I don't want to have to create a separate image file for each one and then load each image one at a time - much nicer to use an atlas for things like this.

Has anyone else had a similar issue?
Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 15th Sep 2011 14:48
OK, so AppGameKit doesn't recalculate collision shapes on sprites when you change their frames. In one way this is good, because it saves a massive amount of overhead when there is very little that changes between frames.

In your case it's bad because there is obviously a very large difference between the animation frames.

The only thing I can think to do is that as you change from a rounded box sprite to a triangle sprite, you issue the following:

// code to change sprite from box to triangle...
SetSpriteShape(l_sprite_id,0)
SetSpriteShape(l_sprite_id,3)

That should remove the existing collision box and setup a new one bsaed on the new image shape.
Red5
12
Years of Service
User Offline
Joined: 26th Aug 2011
Location:
Posted: 15th Sep 2011 15:05
Sure, I agree that it is good in some ways when using an image atlas to store frames of animation, but in this case it is not for animation but just as a repository for holding lots of different sprites.

What would be nice is if we had more control of things like this "programmatically", for example, being able to tell AppGameKit to re-calculate the collision shape at the time you load a SubImage from the atlas - perhaps I'll log this as an enhancement request.

I will go and try your suggestion.

Thanks.
Red5
12
Years of Service
User Offline
Joined: 26th Aug 2011
Location:
Posted: 15th Sep 2011 15:08
That didn't work either.

I just downloaded an image splitter tool that will auto-create all the sprites as separate files based on the parent image and a grid size; I'll go for this solution for now I think and besdies, I suppose having them as separate images will give me better control of runtime memory consumption since I only need load those images required for the current moment in time rather than having the entire atlas loaded.

Thanks for your help anyway
Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 15th Sep 2011 15:18
Looking at the docs, SetSpriteShape says:
Quote: "Setting a shape removes all other shapes assigned to the sprite and replaces it with this one"


Based on your experience, it seems like it's not taking into account that it's anything other frame 0 when it comes to atlas textures.

I'd raise it as a bug rather than a feature request.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 15th Sep 2011 19:48 Edited at: 15th Sep 2011 20:45
Loading a SubImage from an atlas is supposed to create a "standalone image into a blank image ID". If a sprite cannot be assigned this standalone image for it's polygon shape, then I would say that's a bug.

I've gone ahead and posted this on the bug board, and attached a project that illustrates the problem.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-20 02:39:50
Your offset time is: 2024-04-20 02:39:50