saiy2k
October 27, 2015, 10:45am
1
Hi,
I am loading and using my Spritesheet as follow:
cc.spriteFrameCache.addSpriteFrames(res.boardSheet_PLIST);
this.batchNode = cc.SpriteBatchNode.create(res.boardSheet_PNG);
this.addChild(this.batchNode);
var bottomY = 50;
this.chalkSprite = cc.Sprite.create('#chalk.png');
this.chalkSprite.setPosition(cc.p(size.width * 0.912, bottomY + 10));
this.batchNode.addChild(this.chalkSprite);
This is working fine in web. But in Android its throwing the following error:
D/cocos2d-x debug info(23983): JS: assets/src/MainMenu.js:30:TypeError: this.chalkSprite is null
Edit 1:
The error happens in the setPosition() line. this.chalkSprite is null in Device. I checked the file name case and it is set right.
Any help please
Are you sure that the asset is being included when you deploy to your device? the web will reference the resources folder but for devices make sure its properly included
saiy2k
October 27, 2015, 5:23pm
3
Yes. The assets are being copied to APK. I extracted it and verified.
Actually, Regular sprites are getting rendered. The issue is only with Sprite Sheets.
I currently wonder about the “#”… are you sure that you need that one? How are the sprites named in your .plist file?
Btw. you usually don’t need the SpriteBatchNode - cocos2d implements auto batching which should already handle the drawing.
saiy2k
October 28, 2015, 7:02am
5
To access sprites inside a spriteSheet, # has to be added. And Wow, I didnt know cocos2d autobatches the Images
Anyways, I am now loading the individual sprites rather than loading them through SpriteBatchNode and it’s working fine.
efares
October 28, 2015, 10:51pm
6
This is what I’m doing:
cc.spriteFrameCache.addSpriteFrames(res.playScene_plist);
var playSceneSpriteSheet = new cc.SpriteBatchNode(res.playScene_png);
this.addChild(playSceneSpriteSheet);
And then I access sprites like this:
this.playerSprite = new cc.PhysicsSprite.create("#player.png");
So how would I do this correctly without using SpriteBatchNode? @saiy2k
saiy2k
November 2, 2015, 7:01pm
7
Ideally it should be
playSceneSpriteSheet.addChild(this.playerSprite);
But its not working for me!