Wednesday 15 April 2015

cocos2d js - Setting Schedule in Custom Layer and Callback Not Firing -


I'm working on a simple Risajh custom layer to manage the classic continuous background scroller Cocos-2D-Actimar 5 I am here. I initially made it into my main game layer, where I had to do this work, but when I took it to my own background scroller layer, it works as long as the schedule is set to the main layer. The function "scroll" is never called in any method of being or within the background controller.

What could happen because a schedule is registered but not a fire? Is this a scope issue? Should I schedule that event on the backgroundcrawler or from within the code that is giving it immediately?

  onEnter: function () {var self = this; This._super (); WinSize = cc.director.getWinSize (); CenterPos = CCP (winSize.width / 2, winSize.height / 2); bs = new BackgroundScroller ( "https://fbcdn-sphotos-fa.akamaihd.net/hphotos-ak-xap1/v/t1.0-9/1014377_10153225997278888_209146662968373758_n.jpg?oh=287c045d5b8752581f8bdce968312c5c&oe=55BBA0B3&__gda__=1437658479_65b312f58967c3e1bd0ddb07260395cb" , WinSize, Centrepos, BackwardsScroller. Speed.MIDIIMSSLLOO); This.addChild (bs); Bs.startScroll (); }  

Here is BackgrounScroller custom layer code:

  var BackgroundScroller = cc.Layer.extend (/ ** @lends cc.Layer # * / { _bgSprites: function (scrollSpeed) {scrollSpeed ​​= scrollSpeed ​​|| this.scrollSpeed; cc.log ( 'start scrolling ::' + scrollSpeed); [], / * this interesting bit * / startScroll is this.schedule ( it. scroll, scrollSpeed); this.scheduleUpdate ();}, scroll function (DT) for {debugger; (var i = 0; i & LT; this._bgSprites.length; i ++) {var bgSprite = this._bgSprites [i]; bgSprite.setPositionX (bgSprite.getPosition () x - 1.); this.checkIsOffEdge (bgSprite);}}, ctor: function (bgSpriteOrCallbackFunction, winSize, centerPos, scrollSpeed) {this._super () ; This.scrollSpeed ​​= scrollSpeed; this.winSize = winSize || cc .director.getWinSize (); this.centerPos = centerPos || cc.p (this.winSize.width / 2, / 2 this.winSize.height); if (typeof bgSpriteOrCallbackFunction == "function") {This.setupBackgroundSprite = BgSpriteOrCallbackFunction;} Else {this.bgSpriteName = bgSpriteOrCallbackFunction; } This._bgSprites = []; }, But: function () {this.setupBackgroundSprites (); }, Stop scarf: function () {this.pause (); }, / ** * sprites either with the name of the background sprite or the callback function specified in ctor. * @RerennessWide * / Setup BackgroundSprit: Function () {cc.log ("Setup Background Spirits"); This.totalBgWidth = 0; Var bgSpriteWidth = 0; While (this.totalbgWidth & lt; this.winSize.width * 2) {var bgSprite = this.setupBackgroundSprite (); This._bgSprites.push (bgSprite); BgSprite.setAnchorPoint (0, 0); BgSpriteWidth = bgSprite.getBoundingBox (). Width; This.addChild (bgSprite); This.totalBgWidth + = bgSpriteWidth; This.maximumBgExtent = this.totalBgWidth - bgSpriteWidth; Var posN = (this._bgSprites.length - 1) * bgSprite.getBoundingBox () Width; // bgSprite.setPositionX (posN) from left to right; } Cc.log ("BgSprites in background sprites:" + this._bgSprites); }, SetupBackgroundSprite: function () {var bgSprite = new cc.Sprite (this.bgSpriteName) bgSprite back; }, CheckIsoff is function: (sprite) {var spriteBB = sprite.getBoundingBox (); If (spriteBB.x + spriteBB.width & lt; 0) {sprite.setPositionX (this.maximumBgExtent - 1); }}}); BackgroundScroller.Speeds = {"Slow": 0.5, "MEDIUM_SLOW": 0.005, "Medium": 0.001, "MEDIUM_FAST": 0.0005, "Fast": 0.0001};  

I understood it, I explained to everyone but in the schedule Cyclor layer, I set the schedule and it "scrolls" on the background scroller.

I still can not believe why this was not working, but it makes sense - the parent layer, where all this logic should be managed in any way.


No comments:

Post a Comment