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 Studio Chat / [SOLVED] Physics Question

Author
Message
TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 12th May 2020 10:58 Edited at: 12th May 2020 11:08
Any on can explain this . Thanks in advance

SetSpriteShapePolygon( iSpriteID, numPoints, index, x, y )
SetSpriteShapePolygon( iSpriteID, numPoints, index, x, y, shapeID )

spriteID and no of point understand but the index , x, y , shapeID ?



Attachments

Login to view attachments

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

Go to answer

Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 12th May 2020 11:39 Edited at: 12th May 2020 11:43
Its described in the documentation:
https://www.appgamekit.com/documentation/Reference/Sprite/SetSpriteShapePolygon.htm

numPoints - The number of points to use in the polygon (minimum 2, maximum 12)
index - The index of the point to set, from 0 to numPoints-1
x - X coordinate of the polygon point to be added
y - Y coordinate of the polygon point to be added

So if you wanted to create a 4 sided polygon then you would call SetSpriteShapePolygon() 4 times with the locations of each of the points. The index indicates which point you are setting the values for (0-3 for four points)

SetSpriteShapePolygon( ID, 4, 0, x1, y1 ) <- this sets the first point
SetSpriteShapePolygon( ID, 4, 1, x2, y2 )
SetSpriteShapePolygon( ID, 4, 2, x3, y3 )
SetSpriteShapePolygon( ID, 4, 3, x4, y4 ) <- this sets the last point

If you dont specify a shapeID, then you are setting the points for the default shape: shapeID =1

Typically, most sprites will have just one shape (a single box, circle or single polygon etc...). Each sprite can have multiple shapes assigned to it if you wanted though. So for a sprite with a really complicated outline, you could cover it with a number of different shapes...Eg,,, 4 boxes, 2 circles and a polygon (7 shapes in total)

If you want to use multiple shapes (more than 1), then you need to add them

AddSpriteShapeBox()
AddSpriteShapeChain()
AddSpriteShapeCircle()
AddSpriteShapePolygon()

These work the same as the setspriteshapebox/circle/polygon commands but instead of overiding the shape at shapeID=1 they allow you to add multiple shapes instead. The default shape is always at shapeID=1. You can add id 2,3,4 etc... if you wanted

You can get the total number of shapes assigned to a sprite with GetSpriteNumShapes()


One last important thing. If you do add polygon shapes. they need to be convex to work correctly! Any concave shapes do not work and wont collide as expected. Break up any concave shapes into multiple convex shapes to allow the physics collision to work.
TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 12th May 2020 13:02 Edited at: 12th May 2020 13:11
Thanks dear . 80% I understand
Help me just little more ---

SetSpriteShapePolygon( ID, 6, 0, x1, y1 ) <- this sets the first point
SetSpriteShapePolygon( ID, 6, 1, x2, y2 )
SetSpriteShapePolygon( ID, 6, 2, x3, y3 )
SetSpriteShapePolygon( ID, 6, 3, x4, y4 )
SetSpriteShapePolygon( ID, 6, 4, x5, y5 )
SetSpriteShapePolygon( ID, 6, 5, x6, y6 ) <- this sets the last point

look at the pic - and tell me this curve image 512x512 pixel if I div 6 part then what will be the x1,y1 = x2,y2 = x3,y3 = x4,y4 = x5,y5 = x6,y6 Thank you

Attachments

Login to view attachments
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 12th May 2020 13:25 Edited at: 12th May 2020 13:40
Its up to you to set how many points you want in your polygon and where they should be. It can be 2 to 12 points.

If you want to make the barriers in your image into a physics shape then it would probably be easier for you to simply make it out of multiple box shapes placed along the curve. that makes more sense as the polygon cant be concave which you would want it to be.

A quick example using boxes for the corner:


The points on the curve are just points on a constant radius circle and you can set the locations with sin() and cos() functions or hardcoding them.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 12th May 2020 13:43
You could set the points as follows but bengismos box method may work better

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 12th May 2020 13:49 Edited at: 12th May 2020 13:49
Thats not a good idea fubarpk...that would create a concave polygon and so collision with the shape wouldnt work correctly.

Also...with that many points you would probably end up with more than 12...which is the limit for polygons.

A chain might be a good idea but it only works with physics simulation, not with sprite collision checks. Hence why i suggested multiple boxes.
TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 12th May 2020 14:32 Edited at: 12th May 2020 14:35
Bengismo ! thanks for your answer can you please upload your code with my image please it would better to understand . thanks again to all .

or you just Help me ---

SetSpriteShapePolygon( ID, 6, 0, x1, y1 ) <- this sets the first point
SetSpriteShapePolygon( ID, 6, 1, x2, y2 )
SetSpriteShapePolygon( ID, 6, 2, x3, y3 )
SetSpriteShapePolygon( ID, 6, 3, x4, y4 )
SetSpriteShapePolygon( ID, 6, 4, x5, y5 )
SetSpriteShapePolygon( ID, 6, 5, x6, y6 ) <- this sets the last point

the image 512x512 pixel if I div 6 part then what will be the x1,y1 = x2,y2 = x3,y3 = x4,y4 = x5,y5 = x6,y6
and this is the physics car game .
Thank-you
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 12th May 2020 15:03
oh yes I forgot about concave being a problem

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 13th May 2020 01:35
please someone sent some code
so I can understand clearly
thank-you
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 13th May 2020 02:08
ide be tempted to make each if those gray blocks a sprite of its own

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Qugurun
Valued Member
9
Years of Service
User Offline
Joined: 8th Dec 2014
Playing: AppGameKit
Posted: 13th May 2020 02:10 Edited at: 13th May 2020 03:01
This post has been marked by the post author as the answer.
TamBam.



Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 13th May 2020 04:04 Edited at: 13th May 2020 04:27
Use SpriteShapeChain, it allows concave shapes

I outlined the islands that make up the track. So to do a figure 8 the shapes would look like this;



I attached a game i was working on that uses this technique (Only using SetSpriteShapePolygon)

Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 13th May 2020 10:25
Here is a simple example of using SetSpriteShapeChain() to define the islands in your race track.
There are three .json files that define the points for each shape island (As shown in the previous post)

Attachments

Login to view attachments
TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 13th May 2020 14:06 Edited at: 13th May 2020 14:39
Thanks to Bengismo, fubarpk, Qugurun, blink0k all and special thanks to Qugurun my problems solve ..
after complete my design/game I will post here .... Thanks again

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 13th May 2020 14:19
That example is quite good blink I changed the scale to setPhysicsScale(0.09)
made it a bit more fun best way I could see to increase the speed without
messing everything else up

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 13th May 2020 22:14
Just a tip on creating shapes.
If you have access to illustrator or an app that generates .ai files (generally a standard for vector files. I use flash which is now called animator)
You can use your proggy to draw boundary outlines using the line drawing tools in the app then export to .ai format (Make sure you only use outlines because it makes the output easier to read)
The .ai format is text based and although at first glance it seems intimidating, with a closer look you can see it gives you a nice list of points that define the outline (See from 190.1 163.2 m through 190.1 163.2 L)



With a little bit of editing, or you could parse it, you can produce a .json file


TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 30th May 2020 20:17
Thankyou

Login to post a reply

Server time is: 2024-04-20 12:23:20
Your offset time is: 2024-04-20 12:23:20