Sprite occasionally not appearing

This is odd - and new (to me) with 3.15

I am adding a dozen or so sprites using the same texture at different positions on screen. Simple stuff. Very occasionally, like, 1 in 100, one of the sprite will not appear. What can be causing it? Something uninitialised in the cocos sprite?

Code is -

		auto tile = cocos2d::Sprite::createWithSpriteFrameName(divV.str());
		tile->setPosition(Vec2(m_initialX+(j*m_spacing), m_initialY - ((m_spacing*(m_boardSize-1))*0.5f)));
		tile->setAnchorPoint(Vec2(Vec2::ANCHOR_MIDDLE));
		tile->setScale(m_dividerScale);
		tile->setOpacity(dividerOpacity);
		tile->setGlobalZOrder(Z_PIECES);
		node()->addChild(tile);

does node() return a cocos2d-x Node object?
If not then that could be the issue - you would need to retain the sprite yourself.

If it does return a Node then are you certain your calculations aren’t putting the sprite off screen?

(try zooming the layer out to see!)

1 Like

Yes, it returns a node. The thing is that it works 99% of the time. It worked 100% of the time on older cocos - game is published. This occasional drop out is new to 3.15 :frowning:

Wow - sounds very strange!
I can only think of debugging, and setting a breakpoint when you see one is missing, and looking at the properties of all the sprites and see if you can see something different about the missing ones?

(or go back to a prev. version of cocos2d-x!!)

1 Like

I’ve had problems with textures and sprites becoming black boxes, out of nowhere. It turned out on release mode I was using bad memory or something and it got all messed up. Took me quite a few hours to figure out, but that could explain why it’s inconsistent for you too.

1 Like