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 / is it my code?

Author
Message
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 21st Jan 2013 13:59
hi, i am trying to make a level with physics, following some code i saw on here about using strings for placing objects, i modified it to use switch statements, which seems better! but the problem is the blocks wont stay vertical and tend to move every so often to the point of them collapsing by themselves after a while, where am i going wrong? here is the code:





tnx for any help

Hail to the king, baby!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Jan 2013 14:09
Maybe you need to set the sprite as static before the first sync. I'm thinking that your parsing and positioning code is fine - but placing the physics objects sometimes glitches out and an overlap is detected, forcing sprites off-centre. So if you set them as static (sorry, can't remember the command) - they should know to stay where they are, rather than popping out of a stack for instance.

I got a fever, and the only prescription, is more memes.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 21st Jan 2013 15:23 Edited at: 21st Jan 2013 15:58
well, i have tried putting in a sync() at the bottom of the create_level routine before its return, but still they seem to push out.

also i just noticed if i change both instances of setSpritePhysicsOn to 2 like so:

I noticed some odd behaviour, predictably they nearly all fall down as they are now all dynamic and not just the stacks, but they seem to end up overlapping and one horizontal beam gets stuck in the top left of the screen!

Edit** I missed out a return from the level1 routine, but i have put it in,strangely it made no odds!!

Hail to the king, baby!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 21st Jan 2013 17:06 Edited at: 21st Jan 2013 17:07
You probably need to turn off gravity "SetPhysicsGravity(0,0)".

The AppGameKit engine is assuming your things are stacked and wants to have them behave as though it was a structure built from building blocks.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 21st Jan 2013 18:50
If you were to build this in real life with building blocks they wouldn't shuffle about and fall over, largely due to inertia.

You may be able create a similar effect by adjusting the mass and friction on the objects.

Make them heavy enough and rough enough and they won't slide around.

It depends what you want to do with the physics, but as AL says, if you don't need gravity turn it off.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Jan 2013 19:00
When your building the level, you set the smaller bricks to physics mode 2, but if you set that to 1, it'll make them static - then they won't react with each other.

Use setSpritePhysicsOn(wSpr,1) instead of setSpritePhysicsOn(wSpr,2) - 1 means static, 2 means dynamic (moving), and 3 means kinematic (I think that means it only moves by force).



I got a fever, and the only prescription, is more memes.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 21st Jan 2013 19:09 Edited at: 21st Jan 2013 19:10
Quick tip.

Use constants for the Physics modes and you'll see at a glance what each sprite is being set to.

Also saves remembering which is which
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 23rd Jan 2013 14:33
Marl, yeh true . Anyhow i wanted static and dynamic in the level, still cant work it all out as to why it doesn't work, i also added another case of 3, putting a few 3's in the string, has very odd behavior and reports sprite number already used despite the wSpr var getting incremented!

Hail to the king, baby!
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 23rd Jan 2013 15:03 Edited at: 23rd Jan 2013 15:17
ok it was my code,sorry for that,lots of errors in there, i have fixed it now and basically was after this:





I am posting it here to hope it at leasts helps other N00bz like myself ! And thanks Marl, I really should know better about using vars instead of numerics, sometimes I am simply too damned lazy for my own good

Hail to the king, baby!

Login to post a reply

Server time is: 2024-11-24 05:49:04
Your offset time is: 2024-11-24 05:49:04