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.

Newcomers AppGameKit Corner / [Answered]Associating physics with a drawn line.

Author
Message
rfwarrior
9
Years of Service
User Offline
Joined: 13th Jan 2015
Location:
Posted: 13th Jan 2015 20:17
Hi,

I'm a professional programmer by trade, but new to AppGameKit and so far I'm loving it.

I've dabbled with cocos2d and in that was able to easily add physics to a line (e.g allowing for collision etc).

I'm writing my first app where a user draws a freehand line (this is actually made up of a number of short lines, the lines can be at any angle. (and was based on a snippet of code I saw on this forum). They can draw curves loops etc.

Now I want to essentially create a box2d edge (is that a polygon with just two points ) for each segment of the line.


All I can see is how to create a polygon related to a sprite. Would I have to create a sprite for each line segment, a 1 pixel width rectangle of the length of the line segment and rotate it to the right angle of the line to achieve this?

If that's the way I have to go I will but I'm guessing (and hoping) there is an easier way to do this.

By the way - I am loving AppGameKit, a fantastic product and I can't wait to get my teeth into it further.
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jan 2015 21:22
Quote: "All I can see is how to create a polygon related to a sprite. Would I have to create a sprite for each line segment, a 1 pixel width rectangle of the length of the line segment and rotate it to the right angle of the line to achieve this?"


In a word, yes. Then you would add physics joints to hold it all together. Or if the lines don't move, they can be static objects with no joints.

It's been a while since I used physics, but I think edges are available in DBPro and not AGK.

Quidquid latine dictum sit, altum sonatur
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Jan 2015 09:18
Actually I haven't tried this but you can set a polygon shape with a minimum of 2 points using SetSpriteShapePolygon. It might be possible to create an edge that way.

You could then use AddSpriteShapePolygon to add additional lines to a single sprite.


Using AppGameKit V2 Tier 1
rfwarrior
9
Years of Service
User Offline
Joined: 13th Jan 2015
Location:
Posted: 15th Jan 2015 23:50
Tried a load of things, finally got it working.

I created and rotated sprites for the lines and it now behaves as it should.

Thanks for the help.

I would have set the post title to Answered but couldn't figure out how.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Jan 2015 21:22 Edited at: 16th Jan 2015 21:23
Glad you got something working, you can't change the title once it's set. Only a MOD can do that and it seems they already have...


Using AppGameKit V2 Tier 1
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Jan 2015 12:35
Did you do it with 2 points, or did it need more?

Quidquid latine dictum sit, altum sonatur
rfwarrior
9
Years of Service
User Offline
Joined: 13th Jan 2015
Location:
Posted: 19th Jan 2015 19:49
Hi BatVink,

I create multiple sprite lines as the pointer changes position.

I actually found the sprite line drawing routine somewhere on these forums (my version was screwing up with atanfull angles).
Then added physics to the sprites created.

Worked really well.
rfwarrior
9
Years of Service
User Offline
Joined: 13th Jan 2015
Location:
Posted: 19th Jan 2015 21:07
I drew a line (using sprites) from the last pointer position to the current one.

This results in a set of lines. which I added physics to as I went along.

Found a sprite line drawing routine on here - I was on the right track but my use of atanfull to get the angle was incorrect.
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Jan 2015 13:12
My bad question. Are the physics shapes made of 2 points, or more than 2 points?

Quidquid latine dictum sit, altum sonatur
rfwarrior
9
Years of Service
User Offline
Joined: 13th Jan 2015
Location:
Posted: 23rd Jan 2015 00:57
The lines I am drawing have a width of 8. So each line is more like a rectangle so 4 points physics shape.

(sorry I didn't reply sooner. Didn't see you'd asked a question)
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Jan 2015 09:44
Thanks. I might try Baxslash' idea, it could be very useful for 'one-sided' physics. For example a Pong paddle the ball passes through from behind.

Quidquid latine dictum sit, altum sonatur

Login to post a reply

Server time is: 2024-03-28 22:57:07
Your offset time is: 2024-03-28 22:57:07