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 / physics Layers

Author
Message
haliop
User Banned
Posted: 10th Dec 2013 06:40
lets say i have a city
(all 2d) so you see it from the front view

so just a simple code


now lets say i want to crush this city so i just add physics attributes and a force somewhere and everything falls...

but lets say i have this city and another just infront of it
and i want to crush them both ... if i have another city or a block of buildings infront of the last and i add pysics attributes then the city behind must not be with physics on becouse then everything will be a mess...

so any ideas how can i create 2d physics layers?
do you get my point?
if not i will write more code to try and figure it out.

thank u for you time.
nadav.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 10th Dec 2013 08:55
You could do the 2 cities in separate places and use copies of the sprites to overlay the two.

Similar to how Baxslash used Box2D to add physics to 3D. The version on screen uses copies of the one using the physics.
haliop
User Banned
Posted: 10th Dec 2013 09:27
thankx that should do the trick

have an awesome day Marl.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Dec 2013 11:08
i believe you want use SetSpriteGroup

AGK 108 B19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
haliop
User Banned
Posted: 10th Dec 2013 22:00
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Dec 2013 22:51
i think this commands are better.
means you can set a collision only for city 1 sprites,
and the other sprites for city 2 in background.
SetSpriteCollideBit
SetSpriteCategoryBit

AGK 108 B19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Dec 2013 23:00
I use the method Markus mentions, I think it would be perfect for your project.

Look at the video below, from about 1 minute 10s. You will see some balls collide and some balls don't. They have 2 different Sprite Category bits so that I have "2 layers".



haliop
User Banned
Posted: 10th Dec 2013 23:07
aha i see.. thank you i will investigate more !
thank you for your time and help.
and i will see what is better the first option where some sprites and physics are offscreen and just copy positions and see them on screen or group i wonder what would be faster.

thank you.

Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 11th Dec 2013 01:18
Groups will probably be faster. There is a good chance the off screen sprites will still be testing for collisions with the on screen ones, slowing down your app needlessly.

Groups are used to prevent calculations which are not required so that is the way to go imo.

haliop
User Banned
Posted: 11th Dec 2013 15:48 Edited at: 11th Dec 2013 16:18
im trying to get it to work but with no success
group 1 and group 2 collides as if i didnot called the command.


any small code to show ?
anyone ?


not working....
also not working

is there something im missing here? i dont get it

thank you for your time.
nadav.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Dec 2013 16:28
Don't forget...

SetSpriteCollideBit

Description

Sets or removes a category that this sprite can collide with. Sprites are assigned categories using SetSpriteCategoryBit. There are 16 categories, a value of 1 for that category represents that this sprite will collide with sprites from that category and 0 that it will not collide with that category, regardless of which category this sprite itself belongs to. By default all sprites belong to category 1 and collide with all categories. This command is similar to SetSpriteCategoryBits except this command sets one category at a time whilst that command sets them all at once using a bit mask.

haliop
User Banned
Posted: 11th Dec 2013 16:35
ok for some reason i just dont get it...
can please some one show a simple code here? for 2 groups of physics sprites ?

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Dec 2013 17:08
Here you go. Throw the blocks around with the mouse. You will see the red and green blocks never collide. But red and red will collide, green and green will collide.

I moved them to categories 2 and 3 because the screen "walls" are in category 1.



haliop
User Banned
Posted: 11th Dec 2013 17:25
ok now i see i tried to use 1 and 2 but i forgot about the default walls.


thank you, this is very helpfull also i didnot know about mousejoint.. thank you again

have an awesome day.

Login to post a reply

Server time is: 2024-11-24 23:43:28
Your offset time is: 2024-11-24 23:43:28