public static LHSprite nodeWithDictionary(PlistDictionary dict, CCNode prnt) { LHScene scene = ((LHNodeProtocol)prnt).getScene(); string imageFileName = dict ["imageFileName"].AsString; string relativeImagePath = dict ["relativeImagePath"].AsString; // string imagePath = LHUtils.imagePathWithFilename (imageFileName, relativeImagePath, scene.currentDeviceSuffix (false)); // string imageDevPath = LHUtils.imagePathWithFilename (imageFileName, relativeImagePath, scene.currentDeviceSuffix (true)); string imagePath = LHUtils.imagePathWithFilename(imageFileName, "", scene.currentDeviceSuffix(false)); string imageDevPath = LHUtils.imagePathWithFilename(imageFileName, "", scene.currentDeviceSuffix(true)); CCTexture2D texture = scene.textureWithImagePath(imagePath); CCSpriteFrame spriteFrame = null; string imageFilePath = imageDevPath; string spriteFrameName = dict["spriteName"].AsString; if (spriteFrameName != null) { LHSprite.cacheSpriteFramesInfo(imageDevPath, scene); spriteFrame = CCSpriteFrameCache.SharedSpriteFrameCache [spriteFrameName]; } else { //spriteFrame = [texture createSpriteFrame]; } LHSprite spr = new LHSprite(spriteFrame, dict, prnt, spriteFrameName, imageDevPath); return(spr); }
static void cacheSpriteFramesInfo(string imageDevPath, LHScene scene) { string sceneRelative = scene.relativePath; string curDevSuffix = scene.currentDeviceSuffix(true); string atlasName = LHUtils.stripExtension(imageDevPath); // string atlasName = Path.GetFileNameWithoutExtension(imageDevPath); string atlasPlist = atlasName + ".plist"; // string atlasPlist = Path.ChangeExtension (atlasName, "plist"); string sceneSuf = sceneRelative + curDevSuffix; // atlasPlist = sceneSuf + atlasPlist; // Debug.WriteLine ("atlasPlist"); // Debug.WriteLine (atlasPlist); // string sceneSuf = Path.Combine (sceneRelative, curDevSuffix); // atlasPlist = Path.Combine (sceneSuf, atlasPlist); CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFrames(atlasPlist); atlasName = sceneRelative + atlasName; // atlasName = Path.Combine (sceneRelative, atlasName); if (false == scene.hasEditorBodyInfoForImageFilePath(atlasName)) { string path = CCFileUtils.FullPathFromRelativePath(atlasPlist); PlistDocument document = CCContentManager.SharedContentManager.Load <PlistDocument>(path); PlistDictionary dict = document.Root.AsDictionary; PlistDictionary framesDict = dict ["frames"].AsDictionary; foreach (var pair in framesDict) { string sprName = pair.Key; PlistDictionary frmInfo = pair.Value.AsDictionary; if (null != frmInfo) { PlistDictionary bodyInfo = frmInfo ["body"].AsDictionary; if (null != bodyInfo) { Debug.WriteLine("CACHING BODY " + sprName + " atlas " + atlasName + " body " + bodyInfo); scene.setEditorBodyInfoForSpriteName(sprName, atlasName, bodyInfo); } } } } }
public void loadPhysicsInfoFromDictionary(PlistDictionary dict, CCNode nd) { _node = nd; if (null != dict) { int shapeType = dict ["shape"].AsInt; int type = dict ["type"].AsInt; LHScene scene = ((LHNodeProtocol)_node).getScene(); b2World world = scene.getBox2dWorld(); var bodyDef = new b2BodyDef(); bodyDef.type = (b2BodyType)type; CCPoint position = _node.Parent.ConvertToWorldspace(_node.Position); // bodyDef.position = scene.metersFromPoint (position); bodyDef.position = new b2Vec2(position.X, position.Y); float angle = CCNodeTransforms.GlobalXAngleFromLocalAngle(_node, _node.RotationX); bodyDef.angle = LHUtils.LH_DEGREES_TO_RADIANS(angle); bodyDef.userData = _node; _body = world.CreateBody(bodyDef); _body.UserData = _node; Debug.WriteLine("BODY:" + _body); _body.SetFixedRotation(dict ["fixedRotation"].AsBool); //_body->SetGravityScale _body.SetSleepingAllowed(dict ["allowSleep"].AsBool); _body.SetBullet(dict ["bullet"].AsBool); _body.AngularDamping = dict ["angularDamping"].AsFloat; _body.AngularVelocity = -360.0f * dict ["angularVelocity"].AsFloat; _body.LinearDamping = dict ["linearDamping"].AsFloat; CCPoint linearVel = CCPoint.Parse(dict ["linearVelocity"].AsString); _body.LinearVelocity = new b2Vec2(linearVel.X, linearVel.Y); CCSize size = _node.ContentSize; // size.Width = scene.metersFromValue (size.Width); // size.Height = scene.metersFromValue (size.Height); CCPoint scale = new CCPoint(_node.ScaleX, _node.ScaleY); scale = CCNodeTransforms.ConvertToWorldScale(_node, scale); previousScale = scale; size.Width *= scale.X; size.Height *= scale.Y; PlistDictionary fixInfo = dict ["genericFixture"].AsDictionary; Debug.WriteLine("FIX INFO " + fixInfo); Debug.WriteLine("SHAPE TYPE " + shapeType); if (shapeType == 0) //RECTANGLE { LHBodyShape shape = new LHBodyShape(); shape.createRectangleWithDictionary(fixInfo, _body, _node, scene, size); _subShapes.Add(shape); } else if (shapeType == 1) //CIRCLE { LHBodyShape shape = new LHBodyShape(); shape.createCircleWithDictionary(fixInfo, _body, _node, scene, size); _subShapes.Add(shape); } else if (shapeType == 4) //oval { PlistArray shapePoints = dict ["ovalShape"].AsArray; if (shapePoints != null) { LHBodyShape shape = new LHBodyShape(); shape.createShapeWithDictionary(fixInfo, shapePoints, _body, _node, scene, scale); _subShapes.Add(shape); } } else if (shapeType == 5) //traced { String fixUUID = dict ["fixtureUUID"].AsString; Debug.WriteLine("TRACED " + fixUUID); PlistArray shapePoints = scene.tracedFixturesWithUUID(fixUUID); Debug.WriteLine("RETURNS " + shapePoints); if (shapePoints == null) { //CHECK IN ASSET //LHAsset asset = _node.assetParent; /// } if (shapePoints != null) { LHBodyShape shape = new LHBodyShape(); Debug.WriteLine("WE HAVE A TRACED SHAPE"); shape.createShapeWithDictionary(fixInfo, shapePoints, _body, _node, scene, scale); _subShapes.Add(shape); } } else if (shapeType == 6) //editor { LHSprite sprite = (LHSprite)_node; if (sprite != null && sprite.GetType() == typeof(LHSprite)) { String imageFile = sprite.getImageFilePath(); imageFile = LHUtils.stripExtension(imageFile); Debug.WriteLine("WE HAVE AN EDITOR SHAPE for sprite " + sprite + " node " + _node + " tst " + imageFile); PlistDictionary bodyInfo = scene.getEditorBodyInfoForSpriteName(sprite.getSpriteFrameName(), imageFile); Debug.WriteLine("WE HAVE BODY INFO " + bodyInfo); if (bodyInfo != null) { PlistArray fixturesInfo = bodyInfo ["shapes"].AsArray; for (int i = 0; i < fixturesInfo.Count; ++i) { PlistDictionary shapeInfo = fixturesInfo [i].AsDictionary; Debug.WriteLine("SHAPE INFO " + shapeInfo); LHBodyShape shape = new LHBodyShape(); shape.createEditorWithDictionary(shapeInfo, _body, _node, scene, scale); _subShapes.Add(shape); } } } } // if (dict.ContainsKey ("alpha")) { // _node.Opacity = (byte)dict ["alpha"].AsFloat; // } } }
public void visit() { if (_body != null && scheduledForRemoval == true) { this.removeBody(); } if (_body != null) { CCAffineTransform trans = b2BodyToParentTransform(_node, this); CCPoint localPos = CCAffineTransform.Transform(_node.AnchorPointInPoints, trans); ((LHPhysicsProtocol)_node).updatePosition(localPos); ((LHPhysicsProtocol)_node).updateRotation(CCNodeTransforms.LocalXAngleFromGlobalAngle(_node, LHUtils.LH_RADIANS_TO_DEGREES(-_body.Angle))); } }
//-------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------- public LHScene(PlistDictionary dict, string plistLevelFile, CCWindow mainWindow) : base(mainWindow) { _designResolutionSize = CCSize.Parse(dict ["designResolution"].AsString); foreach (PlistDictionary devInf in dict["devices"].AsArray) { devices.Add(new LHDevice(devInf)); } currentDev = LHDevice.currentDeviceFromArray(devices, this); CCSize sceneSize = currentDev.getSize(); float ratio = currentDev.getRatio(); sceneSize.Width = sceneSize.Width / ratio; sceneSize.Height = sceneSize.Height / ratio; var aspect = dict ["aspect"].AsInt; if (aspect == 0) //exact fit { sceneSize = _designResolutionSize; } else if (aspect == 1) //no borders { } else if (aspect == 2) //show all { _designOffset.X = (sceneSize.Width - _designResolutionSize.Width) * 0.5f; _designOffset.Y = (sceneSize.Height - _designResolutionSize.Height) * 0.5f; } //loadingInProgress = true; Debug.WriteLine("plistLevelFile:|" + plistLevelFile + "|"); this.relativePath = LHUtils.folderFromPath(plistLevelFile); // this.relativePath = Path.GetDirectoryName (plistLevelFile); Debug.WriteLine("SCENE REL |" + this.relativePath + "|"); // Console.WriteLine ("SCENE REL |" + this.relativePath + "|"); if (this.relativePath == null) { this.relativePath = ""; } // loadingInProgress = true; // [[CCDirector sharedDirector] setContentScaleFactor:ratio]; // #if __CC_PLATFORM_IOS // [[CCFileUtils sharedFileUtils] setiPhoneContentScaleFactor:curDev.ratio]; // #endif // [self setName:relativePath]; _nodeProtocolImp.loadGenericInfoFromDictionary(dict, this); // self.contentSize= CGSizeMake(curDev.size.width/curDev.ratio, curDev.size.height/curDev.ratio); // self.position = CGPointZero; PlistDictionary tracedFixInfo = dict["tracedFixtures"].AsDictionary; if (tracedFixInfo != null) { tracedFixtures = new PlistDictionary(); foreach (var pair in tracedFixInfo) { string fixUUID = pair.Key; PlistArray fixInfo = pair.Value.AsArray; if (null != fixInfo) { tracedFixtures.Add(fixUUID, fixInfo); } } } // supportedDevices = [[NSArray alloc] initWithArray:devices]; // [self loadBackgroundColorFromDictionary:dict]; // [self loadGameWorldInfoFromDictionary:dict]; LHNodeProtocolImp.loadChildrenForNode(this, dict); // [self loadGlobalGravityFromDictionary:dict]; // [self loadPhysicsBoundariesFromDictionary:dict]; // [self setUserInteractionEnabled:YES]; // #if __CC_PLATFORM_IOS // pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)]; // [[[CCDirector sharedDirector] view] addGestureRecognizer:pinchRecognizer]; // #endif // #if LH_USE_BOX2D // _box2dCollision = [[LHBox2dCollisionHandling alloc] initWithScene:self]; // #else//cocos2d // #endif // [self performLateLoading]; // loadingInProgress = false; Debug.WriteLine("SCENE has children count " + this.ChildrenCount); }
public void loadGenericInfoFromDictionary(PlistDictionary dict, CCNode nd) { b2WorldDirty = false; _node = nd; if (null != dict) { name = dict ["name"].AsString; uuid = dict ["uuid"].AsString; //tags loading // { // NSArray* loadedTags = [dict objectForKey:@"tags"]; // if(loadedTags){ // _tags = [[NSMutableArray alloc] initWithArray:loadedTags]; // } // } //user properties loading // { // NSDictionary* userPropInfo = [dict objectForKey:@"userPropertyInfo"]; // NSString* userPropClassName = [dict objectForKey:@"userPropertyName"]; // if(userPropInfo && userPropClassName) // { // Class userPropClass = NSClassFromString(userPropClassName); // if(userPropClass){ // #pragma clang diagnostic push // #pragma clang diagnostic ignored "-Wundeclared-selector" // _userProperty = [userPropClass performSelector:@selector(customClassInstanceWithNode:) // withObject:_node]; // #pragma clang diagnostic pop // if(_userProperty){ // [_userProperty setPropertiesFromDictionary:userPropInfo]; // } // } // } // } if (dict.ContainsKey("alpha")) { _node.Opacity = (byte)dict ["alpha"].AsFloat; } if (dict.ContainsKey("rotation")) { _node.Rotation = -dict ["rotation"].AsFloat; } if (dict.ContainsKey("zOrder")) { _node.ZOrder = dict ["zOrder"].AsInt; } if (dict.ContainsKey("scale")) { CCPoint scl = CCPoint.Parse(dict ["scale"].AsString); _node.ScaleX = scl.X; _node.ScaleY = scl.Y; } //for sprites the content size is set from the CCSpriteFrame if (dict.ContainsKey("size") && _node.GetType() != typeof(LHSprite)) { _node.ContentSize = CCSize.Parse(dict ["size"].AsString); } if (dict.ContainsKey("generalPosition") && _node.GetType() != typeof(LHUINode) && _node.GetType() != typeof(LHBackUINode) && _node.GetType() != typeof(LHGameWorldNode)) { CCPoint unitPos = CCPoint.Parse(dict ["generalPosition"].AsString); CCPoint pos = LHUtils.positionForNode(_node, unitPos); _node.Position = pos; } // if([dict objectForKey:@"generalPosition"]&& // ![_node isKindOfClass:[LHUINode class]] && // ![_node isKindOfClass:[LHBackUINode class]] && // ![_node isKindOfClass:[LHGameWorldNode class]]) // { // // CGPoint unitPos = [dict pointForKey:@"generalPosition"]; // CGPoint pos = [LHUtils positionForNode:_node // fromUnit:unitPos]; // // NSDictionary* devPositions = [dict objectForKey:@"devicePositions"]; // if(devPositions) // { // // NSString* unitPosStr = [LHUtils devicePosition:devPositions // forSize:LH_SCREEN_RESOLUTION]; // // if(unitPosStr){ // CGPoint unitPos = LHPointFromString(unitPosStr); // pos = [LHUtils positionForNode:_node // fromUnit:unitPos]; // } // } // // [_node setPosition:pos]; // } // if([dict objectForKey:@"anchor"] && // ![_node isKindOfClass:[LHUINode class]] && // ![_node isKindOfClass:[LHBackUINode class]] && // ![_node isKindOfClass:[LHGameWorldNode class]]) // { // CGPoint anchor = [dict pointForKey:@"anchor"]; // anchor.y = 1.0f - anchor.y; // [_node setAnchorPoint:anchor]; // } } }