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 / Bending a sprite?

Author
Message
DerCel
11
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 3rd Jul 2012 14:50
Hi all,

I was wondering if there's an easier way of bending sprites than using joints? Looking through the forum I could only get results for the other products like DBP (cloth for example) but nothing for AGK.

Let me provide you with an example of what I'm trying to do -
Imagine we have a platform glued to a pole. Now depending on where the player stands on the platform, I'd like it to bend down a bit.

For the example above I guess I could do it with a few welded(?) sprites to build the pole but for organic shapes like flowers or grass this wouldn't work too well.

Maybe I'm overlooking something (just started one day ago so I'm still in my trial & error mode working with the example files).

If you could point me to the right direction that would be really great.

Thanks a lot for your help,
Cel
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Jul 2012 15:40
Not much you can do yet unfortunately.

I think that everything you need would be unlocked if the allowed vertex modification, like taking a square sprite, and adjusting the corners to suit any shape. Then, you could bend sprites no problem - would open up so many doors. Frustratingly, this is actually quite straightforward in OpenGL - the sprites would most likely be constructed vertex by vertex anyway. Even if we had a command to set a vertex position and UV coord on a sprite, that would suit me.

So, I imagine that this will be added soon, maybe alongside the 3D support, but without vertex modification support, there's nothing we can do. In the meantime, I'd use Box2D to make my flowers, like negative gravity bud attached to a stem, then it would react to the other objects and still try and stay upright - have it shed a petal now and then when you run over it. Ohh, and have the gravity very weak, like just strong enough to lift the bud, then it would look like it's growing slowly, rather than bouncing right back to shape.

Health, Ammo, and bacon and eggs!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Jul 2012 16:41
All four UV corners can be offset using setSpriteUV but it's very complicated. You'd be better here welding or using revolute joints with limits. What you're trying to do is not impossible but neither is it easy.

VanB your flower idea is equally possible but also a little tricky (the kind of problem I love to solve). One future enhancement that might be on its way is the ability to have multiple B2D worlds which would allow you to create your flowers in a separate world and affect them based on wind or whatever is close to them.


this.mess = abs(sin(times#))
DerCel
11
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 3rd Jul 2012 16:50
Thanks a lot for your replies! I'll try your suggestions and if I ever succeed, I'll let you know how I solved this.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Jul 2012 17:09
If you have any problems post it here, I'll watch the thread and help where I can.


this.mess = abs(sin(times#))
DerCel
11
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 4th Jul 2012 11:49
Good morning,

I tried to follow your instructions by looking at the physics examples in the documentation but I cannot get it right.

I created a static joint for the ground sprite which connects to the first part of the stem, followed by revolute joints connecting the 2 parts of the stem and the upper part of the stem with the bud.

Since I didn't know how to apply negative gravity to the bud (couldn't find anything in the documentation which doesn't automatically apply to all objects) I tried with sprite velocity inside the main loop but this doesn't work as expected - the stem is not straight but bends until it reaches the joint limit.

Please find below my code -
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Jul 2012 17:53
As a quick look, when you use the SetSpritePhysicsVelocity command in every sync loop, it never has a chance to actually work.

You need some event that calls the command occasionally, not continuously.

Cheers,
Ancient Lady
AGK Community Tester
DerCel
11
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 4th Jul 2012 18:13
Thanks for the help Ancient Lady,

it works! My first idea was do achieve this via SetJointMotor but I couldn't get it to work.

I added a player sprite now to test the behavior and there's an effect that's not intended (in my previous code this happened as well):

If the player rests on the bud after a short while the bud object seems like it want to get rid of the player sprite resulting in a bounce/spring behavior of the bud sprite which sends the player sprite up and away.

Thanks again,
Cel
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Jul 2012 19:38
That bounce affect actually sounds like it might be a fun thing in the game. Unintended consequences can be interesting.

What kind of Joint were you trying to do (there is no SetJointMotor command that I can see)?

Cheers,
Ancient Lady
AGK Community Tester
DerCel
11
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 5th Jul 2012 10:42
Good morning!

I tried to apply the JointMotor on a revoluteJoint. It's the line right above SetPhysicsDebugOn ( ).

Thanks for your help,
Cel
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 5th Jul 2012 17:45
DerCel, sorry, I didn't look at your code close enough.

This statement is a problem: 'SetJointLimitOn( 1, 0.5, -0.5 )'

For starters, angles in AppGameKit T1 go from 0 to 360, it doesn't work with negative numbers.

Next, the values are supposed to be from the smallest to the largest, which is not the order you have them in.

But your main problem is that you set the desired speed to zero, so it will never move: SetJointMotorOn( 2, 0, 2000 )

The second value needs to be the speed you want it to move at. The third is the force that may be applied to get it there.

Cheers,
Ancient Lady
AGK Community Tester
DerCel
11
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 5th Jul 2012 21:08
Thanks again Ancient Lady,

That makes a lot of sense of course! I should have double-checked the command syntax ...
I'll try again tomorrow morning with a "fresh" mind.

Meanwhile I almost gave up on this, thinking that it would be better to start with something as simple as Pong (using physics) ... But even then I got stuck. I guess it will take me a couple of weeks to get into it.

Thanks a lot,
Cel

Login to post a reply

Server time is: 2024-05-04 14:30:11
Your offset time is: 2024-05-04 14:30:11