本文整理汇总了C#中Box2D.Dynamics.b2World.SetContactListener方法的典型用法代码示例。如果您正苦于以下问题:C# b2World.SetContactListener方法的具体用法?C# b2World.SetContactListener怎么用?C# b2World.SetContactListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box2D.Dynamics.b2World
的用法示例。
在下文中一共展示了b2World.SetContactListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize(float mapSizeWidth, Character Character, CCTileMapLayer physicsLayer, CCTileMap physicsMap, Container gameContainer)
{
mapSizeWidth /= pixelPerMeter;
gameWorld = new b2World (new b2Vec2 (0, -9.8f));
gameWorld.AllowSleep = false;
//definiert den MainCharacter
Character.createPhysicsBody (gameWorld);
defineGround (mapSizeWidth);
createBox2DWorldByLayer (physicsLayer, physicsMap);
debugDrawer = new DebugDraw ();
gameWorld.SetDebugDraw (debugDrawer);
debugDrawer.AppendFlags (b2DrawFlags.e_shapeBit);
collusionSensor = new CollusionSensor (gameContainer);
gameWorld.SetContactListener (collusionSensor);
}
示例2: AddedToScene
//.........这里部分代码省略.........
// Define the ground body.
var groundBodyDef = new b2BodyDef(); // Make sure we call
groundBodyDef.position.Set(0, 0); // bottom-left corner
// Call the body factory which allocates memory for the ground body
// from a pool and creates the ground box shape (also from a pool).
// The body is also added to the world.
b2Body groundBody = world.CreateBody(groundBodyDef);
// Define the ground box shape.
b2EdgeShape groundBox = new b2EdgeShape();
int worldMaxWidth = screenWidth * 4; //If you ever want the BOX2D world width to be more than it is then increase this (currently, this should be plenty of extra space)
int worldMaxHeight = screenHeight * 3; //If you ever want the BOX2D world height to be more than it is then increase this (currently, this should be plenty of extra space)
// bottom
groundBox.Set(new b2Vec2(-4, 0), new b2Vec2(worldMaxWidth / Constants.PTM_RATIO, 0));
groundBody.CreateFixture(groundBox, 0);
// top
groundBox.Set(new b2Vec2(-4, worldMaxHeight / Constants.PTM_RATIO), new b2Vec2(worldMaxWidth / Constants.PTM_RATIO, worldMaxHeight / Constants.PTM_RATIO));
groundBody.CreateFixture(groundBox, 0);
// left
groundBox.Set(new b2Vec2(-4, worldMaxHeight / Constants.PTM_RATIO), new b2Vec2(-4, 0));
groundBody.CreateFixture(groundBox, 0);
// right
groundBox.Set(new b2Vec2(worldMaxWidth / Constants.PTM_RATIO, worldMaxHeight / Constants.PTM_RATIO), new b2Vec2(worldMaxWidth / Constants.PTM_RATIO, 0));
groundBody.CreateFixture(groundBox, 0);
//Contact listener
contactListener = new ContactListener();
world.SetContactListener(contactListener);
//Set up the ground plane
theGroundPlane = new GroundPlane(world, groundPlaneStartPosition, GameData.SharedData.GroundPlaneFileName);
AddChild(theGroundPlane, Constants.DepthFloor);
//Set up the starting platform
thePlatform = new StartPlatform(world, platformStartPosition, "platform");
AddChild(thePlatform, Constants.DepthPlatform);
//Set up ninjas
ninjaBeingThrown = 1; //always starts at 1 (first ninja, then second ninja, and so on)
ninjasToTossThisLevel = GameData.SharedData.NumberOfNinjasToTossThisLevel; //total number of ninjas to toss for this level
ninja1 = new Ninja(world, ninjaStartPosition1, @"ninja");
AddChild(ninja1, Constants.DepthNinjas);
currentBodyNode = ninja1;
currentBodyNode.SpriteInSlingState();
if (ninjasToTossThisLevel >= 2)
{
ninja2 = new Ninja(world, ninjaStartPosition2, @"ninjaRed");
AddChild(ninja2, Constants.DepthNinjas);
ninja2.SpriteInStandingState();
示例3: GameScene
public GameScene(Game game)
{
this.game = game;
// ��ʼ��world
b2Vec2 gravity = new b2Vec2(0f, -20f);
world = new b2World(gravity);
world.AllowSleep = false;
InitBack();
AddBarLayer();
InitScore();
AddGround();
AddBird();
world.SetContactListener(new BirdContactListener(this, (CCSprite)(birdBody.UserData)));
this.schedule(tick);
SimpleAudioEngine.sharedEngine().playBackgroundMusic(@"musics/background", true);
}
示例4: Test
public Test()
{
m_destructionListener = new DestructionListener();
m_debugDraw = new CCBox2dDraw("fonts/arial-12", 1);
b2Vec2 gravity = new b2Vec2();
gravity.Set(0.0f, -10.0f);
m_world = new b2World(gravity);
m_bomb = null;
m_textLine = 30;
m_mouseJoint = null;
m_pointCount = 0;
m_destructionListener.test = this;
m_world.SetDestructionListener(m_destructionListener);
m_world.SetContactListener(this);
m_world.SetDebugDraw(m_debugDraw);
m_world.SetContinuousPhysics(true);
m_world.SetWarmStarting(true);
m_bombSpawning = false;
m_stepCount = 0;
b2BodyDef bodyDef = new b2BodyDef();
m_groundBody = m_world.CreateBody(bodyDef);
}
示例5: StarlingGameSpriteWithPhysics
public StarlingGameSpriteWithPhysics()
{
sessionid = random.Next();
//b2Body ground_current = null;
//b2Body air_current = null;
#region ground_b2world
// first frame ... set up our physccs
// zombies!!
ground_b2world = new b2World(new b2Vec2(0, 0), false);
ground_b2world.SetContactListener(
new XContactListener()
);
var ground_b2debugDraw = new b2DebugDraw();
ground_dd = new ScriptCoreLib.ActionScript.flash.display.Sprite();
ground_dd.transform.colorTransform = new ColorTransform(0.0, 0, 1.0);
ground_b2debugDraw.SetSprite(ground_dd);
// textures are 512 pixels, while our svgs are 400px
// so how big is a meter in our game world? :)
ground_b2debugDraw.SetDrawScale(16);
ground_b2debugDraw.SetFillAlpha(0.1);
ground_b2debugDraw.SetLineThickness(1.0);
ground_b2debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
ground_b2world.SetDebugDraw(ground_b2debugDraw);
#endregion
#region groundkarma_b2world
// first frame ... set up our physccs
// zombies!!
groundkarma_b2world = new b2World(new b2Vec2(0, 0), false);
var groundkarma_b2debugDraw = new b2DebugDraw();
groundkarma_dd = new ScriptCoreLib.ActionScript.flash.display.Sprite();
groundkarma_dd.transform.colorTransform = new ColorTransform(0.0, 1.0, 0.0);
groundkarma_b2debugDraw.SetSprite(groundkarma_dd);
// textures are 512 pixels, while our svgs are 400px
// so how big is a meter in our game world? :)
groundkarma_b2debugDraw.SetDrawScale(16);
groundkarma_b2debugDraw.SetFillAlpha(0.1);
groundkarma_b2debugDraw.SetLineThickness(1.0);
groundkarma_b2debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
groundkarma_b2world.SetDebugDraw(groundkarma_b2debugDraw);
#endregion
#region air_b2world
// first frame ... set up our physccs
// zombies!!
air_b2world = new b2World(new b2Vec2(0, 0), false);
var air_b2debugDraw = new b2DebugDraw();
air_dd = new ScriptCoreLib.ActionScript.flash.display.Sprite();
// make it red!
air_dd.transform.colorTransform = new ColorTransform(1.0, 0, 0);
// make it slave
air_dd.alpha = 0.3;
air_b2debugDraw.SetSprite(air_dd);
// textures are 512 pixels, while our svgs are 400px
// so how big is a meter in our game world? :)
air_b2debugDraw.SetDrawScale(16);
air_b2debugDraw.SetFillAlpha(0.1);
air_b2debugDraw.SetLineThickness(1.0);
air_b2debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
//.........这里部分代码省略.........
示例6: SetupWorld
static void SetupWorld(bool setupGround)
{
var gravity = new b2Vec2(0.0f, -10.0f);
_world = new b2World(gravity);
_world.SetAllowSleeping(true);
_world.SetContinuousPhysics(true);
_world.SetSubStepping(true);
_world.SetWarmStarting(true);
_world.SetDestructionListener(new Destructo());
_world.SetContactListener(new Contacto());
if (!setupGround)
{
return;
}
// Call the body factory which allocates memory for the ground body
// from a pool and creates the ground box shape (also from a pool).
// The body is also added to the world.
b2BodyDef def = b2BodyDef.Create();
def.allowSleep = true;
def.position = b2Vec2.Zero;
def.type = b2BodyType.b2_staticBody;
b2Body groundBody = _world.CreateBody(def);
groundBody.SetActive(true);
// bottom
b2EdgeShape groundBox = new b2EdgeShape();
groundBox.Set(b2Vec2.Zero, new b2Vec2(width, 0));
b2FixtureDef fd = b2FixtureDef.Create();
fd.shape = groundBox;
groundBody.CreateFixture(fd);
// top
groundBox = new b2EdgeShape();
groundBox.Set(new b2Vec2(0, height), new b2Vec2(width, height));
fd.shape = groundBox;
groundBody.CreateFixture(fd);
// left
groundBox = new b2EdgeShape();
groundBox.Set(new b2Vec2(0, height), b2Vec2.Zero);
fd.shape = groundBox;
groundBody.CreateFixture(fd);
// right
groundBox = new b2EdgeShape();
groundBox.Set(new b2Vec2(width, height), new b2Vec2(width, 0));
fd.shape = groundBox;
groundBody.CreateFixture(fd);
_world.Dump();
}