Comments (8)
I'm doing some error tracking and this line gives the error:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, savedBufferWidth, savedBufferHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
from cocos2d-x-irregular-button.
I'm changing the third parameter to GL_RGBA... I have no idea what I'm doing though, but the error went away.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, savedBufferWidth, savedBufferHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
Btw I am seeing an error in which a button made by this sometimes does not get any hits at all... but it's hard to reproduce, sometimes it works and sometimes it doesn't. So I noticed this opengl error and thought it might be related. I'll run with this fix for awhile and see if things get better...
Also, in my case the source sprite comes from a sprite sheet... I use TexturePacker. It might be related, or maybe not.
from cocos2d-x-irregular-button.
The above worked for a while, the opengl error is gone anyway, but I still see some occasions where the button does not respond to touches at all. This has to be fixed sometime, as for now this class is not 100% for cocos2d-x 3.10 :-(
from cocos2d-x-irregular-button.
Hi jonnyijapan,
I'm very sorry for my late reply, but I'm too busy working on my company's project these days.
Also, in my case the source sprite comes from a sprite sheet... I use TexturePacker. It might be related, or maybe not.
Yes, it's related to your problem, because I didn't consider the case of sprite sheet when I implemented the IrregularButton. In my implementation, I treat the normal state of the button as a image file rather than a sprite frame. If a sprite sheet is used, the actual region of the sprite frame must be taken into account when loading the pixels of it. It may be more tricky if you trim the transparent pixels from sprite frames' borders when generating the sprite sheet.
As for the OpenGL error, I can't reproduce it on cocos2d-x v3.2, which is used by me now. I'm not sure whether it's related to v3.10. I'll try to figure out the problem when I'm free.
from cocos2d-x-irregular-button.
Thanks for your reply. So actually, I should try to use this class with a single sprite file rather than a sprite sheet? I might actually test that for a quick fix. My updated version ran fine for one or two weeks but all of a sudden it stopped working. Yesterday I probably updated the sprite sheet of the game screen where this button exists. I update that sprite sheet a couple of times a week. What you say about the offset region in the sprite sheet sounds like it might be true but its weird that it worked for some weeks :-)
from cocos2d-x-irregular-button.
So actually, I should try to use this class with a single sprite file rather than a sprite sheet?
This is how I use the IrregularButton
now XD
My updated version ran fine for one or two weeks but all of a sudden it stopped working. What you say about the offset region in the sprite sheet sounds like it might be true but its weird that it worked for some weeks :-)
I see. In IrregularButton::loadNormalTransparentInfo
, the member variable _buttonNormalRenderer
of cocos2d::ui::Button
class is used for obtaining its texture and loading its pixels via glReadPixels
. _buttonNormalRenderer
can be initialized either from a single file or from a sprite frame. Now it depends on how cocos2d-x implements getTexture
. If normalRenderer->getTexture()
returns only the correctly cropped texture of the sprite frame, then IrregularButton
can handle the case of sprite sheets.
That gives me a hint that IrregularButton
can be extended to support sprite sheets. However, that doesn't mean the current version of IrregularButton
is appropriate. Because I store all the transparency information of a picture to check whether the touch is valid, that may cause large memory consumption if sprite sheets are used.
from cocos2d-x-irregular-button.
I tried using a single file instead of sprite sheet, but it didn't help. The button did not respond at all. I'm busy too so I haven't looked into the real reason. It worked well for weeks even with sprite sheets 👍 The problem is probably elsewhere.
from cocos2d-x-irregular-button.
Hi jonnyijapan,
You can try my previous implementation to see if it works: replace the line
loadNormalTransparentInfo();
in the following function
bool IrregularButton::init(const std::string &normalImage,
const std::string& selectedImage ,
const std::string& disableImage,
TextureResType texType)
{
bool ret = true;
do {
if (!Button::init(normalImage, selectedImage, disableImage, texType)) {
ret = false;
break;
}
} while (0);
loadNormalTransparentInfo();
// loadNormalTransparentInfoFromFile();
return ret;
}
with
loadNormalTransparentInfoFromFile();
from cocos2d-x-irregular-button.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cocos2d-x-irregular-button.