Пример #1
0
        /// <summary>
        /// Post-carga de los objetos cargados del xml
        /// </summary>
        /// <param name="json"></param>
        public override void AfterLoadProcessing(Nb2dJson json)
        {
            //Movemos todos los objetos al offset que deseemos
            var delta = GetOffset(); // move all bodies by this offset

            if (delta.x != 0 && delta.y != 0)
                foreach (var body in json.GetAllBodies())
                    body.SetTransform(body.Position + delta, body.Angle);

            //Obtenemos las imageInfos con todos los objetos
            m_imageInfos = json.GetAllImages().ToList();

            //Recorremos todas
            CCSprite tmpSprite;
            foreach (var img in m_imageInfos)
            {
                //Generamos el sprite en la posición
                tmpSprite = new CCSprite(img.File);
                tmpSprite.Position = new CCPoint(0, 0);
                AddChild(tmpSprite, (int)img.RenderOrder);

                //Guardamos el sprite
                img.Sprite = tmpSprite;

                // Asignamos el volteo y la escala del sprite
                img.Sprite.FlipX = img.Flip;
                img.Sprite.Scale = img.Scale / img.Sprite.ContentSize.Height;

                //Si es el bicho
                if (img.Name.Equals(PLAYER_LAYER_IMAGE_NAME))
                {
                    //img.fixture = json.GetFixturesByName("ball");
                    Player = img;
                }

            }

            OnSetImagePositionsFromPhysicsBodies();

            OnFinishedLoading();
        }
Пример #2
0
 /// <summary>
 /// Override this in subclasses to do some extra processing (eg. acquire references
 /// to named bodies, joints etc) after the world has been loaded, and while the b2dJson
 /// information is still available.
 /// </summary>
 /// <param name="json"></param>
 public virtual void AfterLoadProcessing(Nb2dJson json)
 {
 }
Пример #3
0
        /// <summary>
        /// Attempts to load the world from the .json file given by getFilename.
        /// If successful, the method afterLoadProcessing will also be called,
        /// to allow subclasses to do something extra while the b2dJson information
        /// is still available.
        /// </summary>
        private void LoadWorld()
        {
            Clear();

            m_debugDraw = new CCBox2dDraw(DEFAULT_FONT);

            m_debugDraw.AppendFlags(b2DrawFlags.e_shapeBit | b2DrawFlags.e_aabbBit | b2DrawFlags.e_centerOfMassBit | b2DrawFlags.e_jointBit | b2DrawFlags.e_pairBit);

            string fullpath = GetFilename();

            Console.WriteLine("Full path is: %s", fullpath);

            Nb2dJson json = new Nb2dJson();

            StringBuilder tmp = new StringBuilder();

            m_world = json.ReadFromFile(fullpath, tmp);

            if (m_world != null)
            {
                Console.WriteLine("Loaded JSON ok");

                m_world.SetDebugDraw(m_debugDraw);

                b2BodyDef bodyDef = new b2BodyDef();

                m_touch = new MouseTouch(m_world, this);

                m_touch.m_mouseJointGroundBody = m_world.CreateBody(bodyDef);

                AfterLoadProcessing(json);
            }
            else
                Console.WriteLine(tmp); //if this warning bothers you, turn off "Typecheck calls to printf/scanf" in the project build settings
        }
Пример #4
0
        // This is called after the Box2D world has been loaded, and while the b2dJson information
        // is still available to do extra loading. Here is where we obtain the named items in the scene.
        public override void AfterLoadProcessing(Nb2dJson json)
        {
            // call superclass method to load images etc
            base.AfterLoadProcessing(json);

            // preload the sound effects
            //SimpleAudioEngine::sharedEngine()->preloadEffect("jump.wav");
            //SimpleAudioEngine::sharedEngine()->preloadEffect("pickupgem.wav");
            //SimpleAudioEngine::sharedEngine()->preloadEffect("pickupstar.wav");

            // find player body and foot sensor fixture
            m_playerBody = json.GetBodyByName("player");
            m_footSensorFixture = json.GetFixtureByName("footsensor");

            // find all fixtures in the scene named 'pickup' and loop over them
            List<b2Fixture> pickupFixtures;
            pickupFixtures = json.GetFixturesByName("pickup").ToList();

            foreach (var f in pickupFixtures)
            {
                //For every pickup fixture, we create a FixtureUserData to set in
                //the user data.
                PlanetCuteFixtureUserData fud = new PlanetCuteFixtureUserData();
                m_allPickups.Add(fud);
                f.UserData = fud;

                // set some basic properties of the FixtureUserData
                fud.fixtureType = _fixtureType.FT_PICKUP;
                fud.body = f.Body;
                fud.originalPosition = f.Body.Position;

                // use the custom properties given to the fixture in the RUBE scene
                //fud.pickupType = (_pickupType)json.GetCustomInt(f, "pickuptype", PT_GEM);
                //json.Equals
                //fud.bounceSpeedH = json.GetCustomFloat(f, "horizontalbouncespeed");
                //fud.bounceSpeedV = json.GetCustomFloat(f, "verticalbouncespeed");
                //fud.bounceWidth  = json.GetCustomFloat(f, "bouncewidth");
                //fud.bounceHeight = json.GetCustomFloat(f, "bounceheight");

                //these "bounce deltas" are just a number given to sin when wobbling
                //the pickups. Each pickup has its own value to stop them from looking
                //like they are moving in unison.
                fud.bounceDeltaH = CCRandom.Float_0_1() * (float)Math.PI;
                fud.bounceDeltaV = CCRandom.Float_0_1() * (float)Math.PI;
            }

            // find the imageInfos for the text instruction images. Sprites 2 and 3 are
            // hidden initially
            m_instructionsSprite1 = null;
            m_instructionsSprite2 = null;
            m_instructionsSprite2 = null;

            foreach (var imgInfo in m_imageInfos)
            {
                if (imgInfo.Name == "instructions1")
                    m_instructionsSprite1 = imgInfo;
                if (imgInfo.Name == "instructions2")
                {
                    m_instructionsSprite2 = imgInfo;
                    m_instructionsSprite2.Sprite.Opacity = 0; // hide
                }
                if (imgInfo.Name == "instructions3")
                {
                    m_instructionsSprite3 = imgInfo;
                    m_instructionsSprite3.Sprite.Opacity = 0; // hide
                }
            }

            // Create a contact listener and let the Box2D world know about it.
            m_contactListener = new PlanetCuteContactListener();
            m_world.SetContactListener(m_contactListener);

            // Give the listener a reference to this class, to use in the callback
            m_contactListener.m_layer = this;

            // set the movement control touches to nil initially
            //m_leftTouch = null;
            //m_rightTouch = null;

            // initialize the values for ground detection
            m_numFootContacts = 0;
            m_jumpTimeout = 0;

            // camera will start at body position
            m_cameraCenter = m_playerBody.Position;
        }