private void initCaveTrigger() { var caveEntry = addEntity(new TriggerAbleObject(16, "摁E:进入")); caveEntry.setPosition(caveTrigger.position + new Vector2(caveTrigger.width / 2, caveTrigger.height / 2)); caveEntry.triggerEvent = () => { var cave = new Cave1(); var transition = new FadeTransition(() => { player.detachFromScene(); player.attachToScene(cave); player.setPosition(250, 100); return(cave); }); transition.onTransitionCompleted += () => { GameSetting.isGamePause = false; }; Core.startSceneTransition(transition); GameSetting.isGamePause = true; }; }
private void initSceneChnageTrigger() { var objectLayer = tiledMap.getObjectGroup("Position"); var cave1TriggerObject = objectLayer.objectWithName("cave1Trigger"); var cave3TriggerObject = objectLayer.objectWithName("cave3Trigger"); var cave1TriggerEntity = createEntity("cave1Trigger"); cave1TriggerEntity.setPosition(cave1TriggerObject.position + new Vector2(cave1TriggerObject.width / 2, cave1TriggerObject.height / 2)); cave1TriggerEntity.addComponent <FSRigidBody>() .setBodyType(BodyType.Dynamic); var cave1Trigger = cave1TriggerEntity.addComponent <SceneChangeTriggerComponent>(); cave1Trigger.setSize(cave1TriggerObject.width, cave1TriggerObject.height); cave1Trigger.setIsSensor(true); cave1Trigger.setCollisionCategories(CollisionSetting.tiledObjectCategory); cave1Trigger.setCollidesWith(CollisionSetting.playerCategory); cave1Trigger.onAdded += () => { cave1Trigger.GetFixture().onCollision += (fixtureA, fixtureB, contact) => { var cave1 = new Cave1(); var transition = new FadeTransition(() => { player.detachFromScene(); player.attachToScene(cave1); player.setPosition(230, 400); return(cave1); }); transition.onTransitionCompleted += () => { GameSetting.isGamePause = false; }; Core.startSceneTransition(transition); GameSetting.isGamePause = true; return(true); }; }; var cave3TriggerEntity = createEntity("cave3Trigger"); cave3TriggerEntity.setPosition(cave3TriggerObject.position + new Vector2(cave3TriggerObject.width / 2, cave3TriggerObject.height / 2)); cave3TriggerEntity.addComponent <FSRigidBody>() .setBodyType(BodyType.Dynamic); var cave3Trigger = cave3TriggerEntity.addComponent <SceneChangeTriggerComponent>(); cave3Trigger.setSize(cave3TriggerObject.width, cave3TriggerObject.height); cave3Trigger.setIsSensor(true); cave3Trigger.setCollisionCategories(CollisionSetting.tiledObjectCategory); cave3Trigger.setCollidesWith(CollisionSetting.playerCategory); cave3Trigger.onAdded += () => { cave3Trigger.GetFixture().onCollision += (fixtureA, fixtureB, contact) => { var cave3 = new Cave3(); var transition = new FadeTransition(() => { player.detachFromScene(); player.attachToScene(cave3); player.setPosition(215, 420); return(cave3); }); transition.onTransitionCompleted += () => { GameSetting.isGamePause = false; }; Core.startSceneTransition(transition); GameSetting.isGamePause = true; return(true); }; }; }