/** Initializes a timer with a target, a selector, an interval in seconds, repeat in number of times to repeat, delay in seconds */
 public CCTimerTargetSelector(System.Object t, TICK_IMP selector, float interval = 0, uint repeat = CCScheduler.kCCRepeatForever, float delay = 0)
 {
     if (CCDebug.COCOS2D_DEBUG >= 1)
     {
         NSUtils.Assert(selector != null, "Method not found for selector - does it have the following form? void name(float dt)");
     }
     _target   = t;
     _selector = selector;
     setupTimer(interval, repeat, delay);
 }
        void readHeader(byte[] data, Cursor cursor)
        {
            int len      = Utils.ReadLength(data, cursor);
            int newIndex = cursor.index + len;

            version = Utils.ReadInt32(data, cursor);

            int supportedVersion = Utils.ReadInt32(data, cursor);

            NSUtils.Assert(LIB_VERSION >= supportedVersion, "BBGamelib:flash: library {0} is not supported by swf parser {1} ",
                           versionToString(LIB_VERSION), versionToString(supportedVersion));

            flashVersion = Utils.ReadByte(data, cursor);
            frameRate    = Utils.ReadByte(data, cursor);
            frameSize    = Utils.ReadVector2(data, cursor);
            prefix       = Utils.ReadString(data, cursor);

            cursor.index = newIndex;
        }
        public Flash(string path, DisplayFactory aFactory)
        {
            displayFactory = aFactory;
            string ext = Path.GetExtension(path);

            if (ext != null && ext.Length > 0)
            {
                path = path.Replace(ext, "");
            }
            TextAsset asset = Resources.Load <TextAsset> (path);

            NSUtils.Assert(asset != null, "BBGamelib:flash:{0} file not found!", path);

            byte[] data = asset.bytes;

            Cursor cursor = new Cursor();

            readHeader(data, cursor);
            readDefines(data, cursor);
            Resources.UnloadAsset(asset);
        }
Exemple #4
0
        public void apply(Movie movie, FrameObject frameObj)
        {
            Display display = movie.depthDisplays [depth - 1];

            if (hasCharacter)
            {
                if (display != null)
                {
                    if (hasMove || characterId != display.define.characterId)
                    {
//                        display.removeFromParent();
                        display.removed = true;
                        display.visible = false;
                        movie.caches.DL_APPEND(display);

                        movie.depthDisplays [depth - 1] = null;
                        display = null;
                    }
                    else
                    {
                        //reuse cache
                        display.removed = false;
                    }
                }
                if (display == null)
                {
                    for (var ent = movie.caches.head; ent != null; ent = ent.next)
                    {
                        if (ent.obj.define.characterId == characterId)
                        {
                            display         = ent.obj;
                            display.removed = false;
                            display.visible = true;
                            movie.caches.DL_DELETE(ent);
                            movie.depthDisplays [depth - 1] = display;
                            if (display is Movie)
                            {
                                (display as Movie).movieCtrl.start();
                            }
                            break;
                        }
                    }
                }
                if (display == null)
                {
                    TagDefine newCharacterDefine = flash.getDefine(characterId);
                    if (newCharacterDefine is TagDefineDisplay)
                    {
                        display = flash.displayFactory.ctDisplay(newCharacterDefine as TagDefineDisplay);
                        movie.depthDisplays [depth - 1] = display;
                        movie.addChild(display);
                        if (display is Movie)
                        {
                            (display as Movie).movieCtrl.start();
                        }
                    }
                }
                NSUtils.Assert(display != null, "TagPlaceObject#apply failed to create display.");

                display.position = Vector2.zero;
                display.rotation = 0;
                display.scaleX   = 1; //display.define.preScale;
                display.scaleY   = 1; //display.define.preScale;
                display.zOrder   = depth;
                if (display.hasUserVisible)
                {
                    display.visible = display.userVisible;
                }
                else
                {
                    display.visible = true;
                }
                if (display.hasUserColorTransform)
                {
                    display.colorTransform   = display.userColorTransform;;
                    display.opacityTransform = new OpacityTransform(display.userColorTransform.tint.a, display.userColorTransform.add.a);
                }
                else
                {
                    display.colorTransform   = ColorTransform.Default;
                    display.opacityTransform = new OpacityTransform(display.userColorTransform.tint.a, display.userColorTransform.add.a);
                }
            }
            NSUtils.Assert(display != null, "TagPlaceObject#apply try to reference a null display.");


            if (display != null)
            {
                if (hasMatrix)
                {
                    float preScale = display.define.preScale;
                    display.position = new Vector2(position.x, -position.y);
                    display.rotation = rotation;
                    display.scaleX   = scaleX / preScale;
                    display.scaleY   = scaleY / preScale;
                }
                if (hasVisible)
                {
                    if (display.hasUserVisible)
                    {
                        display.visible = display.userVisible;
                    }
                    else
                    {
                        display.visible = visible;
                    }
                }
                if (hasColorTransform)
                {
                    if (display.hasUserColorTransform)
                    {
                        display.colorTransform   = display.userColorTransform;;
                        display.opacityTransform = new OpacityTransform(display.userColorTransform.tint.a, display.userColorTransform.add.a);
                    }
                    else
                    {
                        display.colorTransform   = colorTransform;
                        display.opacityTransform = new OpacityTransform(colorTransform.tint.a, colorTransform.add.a);
                    }
                }
                display.instanceName = instanceName;
            }
        }