Cocos2d-X animation blinking red - c++

When i start an Animation (using the code below), allof the sprites.png's are misscolored (red) except for the starting picture, so it looks like it's blinking red.
I wondered if anyone know what causes this?
I use TexturePacker to make the sprite sheet, with the settings: Pixel Format: RGBA8888, Texture Format: PVR+zlib.
Here is the code for my animation, which I have in my Player class and it's iniated when it's created:
FileUtils::getInstance()->addSearchResolutionsOrder("indian_spreedsheet/HD");
// load and cache the texture and sprite frames
auto cacher = SpriteFrameCache::getInstance();
cacher->addSpriteFramesWithFile("indian_walk.plist");
#include <sstream>
// load all the animation frames into an array
const int kNumberOfFrames = 4;
Vector<SpriteFrame*> frames;
for (int i = 1; i < kNumberOfFrames; i++)
{
std::string s = std::to_string( i );
SpriteFrame* aFrame =
cacher->getSpriteFrameByName( "indian_walk" + s + ".png" );
frames.pushBack(aFrame);
}
// play the animation
auto animation = Animation::createWithSpriteFrames(frames, 0.40f);
animation->setRestoreOriginalFrame(true);
moveAnimate = Animate::create(animation);
moveAnimate->retain();
I work in Visual Studio, with Cocos2d-x version 3.3.
I can include pictures of the event if anyone feel it's needed.
Thanks in advance!

check your "indian_walk.png", is there some red color on it?
as described in the official document:
Is there a trial version?
Yes, there is a 7-day trial mode with
unrestricted features. After that period TexturePacker goes into
Essential mode. It is restricted to basic features. If you use Pro
features in this mode, you will get a warning before publishing and
some of your sprites will turn red in the output.
link is here

Related

Cocos2d-x V3.2. Create sprite with RenderTexture

I have a problem.
i'm trying to make a screenshot of a scene then make a sprite and pass this sprite to other scene.
i'm doing this:
RenderTexture* texture = RenderTexture::create((int)Director::getInstance()->getWinSize().width, (int)Director::getInstance()->getWinSize().height, Texture2D::PixelFormat::RGBA8888);
texture->begin();
Director::getInstance()->getRunningScene()->visit();
texture->end();
Sprite* bgSprite = Sprite::createWithTexture(texture->getSprite()->getTexture());
bgSprite->setRotationX(180);
/-------------------------------------
LoadScreen* loadLayer = LoadScreen::create(GameScene, this->_carModel, bgSprite/*, this*/);
/-------------------------------------
then in next scene i do:
bgSprite->setPosition(Point(Director::getInstance()->getVisibleSize().width / 2, Director::getInstance()->getVisibleSize().height / 2));
bgSprite->setOpacity(200);
this->addChild(bgSprite, 1, 1);
I debug this. Sprite is not null. The texture in this sprite has size and etc.
I try to save texure in file. The result is empty .png file.
It's an engine problem, the file is alway saved with RGB in the previous version.
Since the rendering of cocos2d-x 3.0 is based on the command queue, we should always wrap the read/write frame buffer operations with commands. Invoking newImage() directly is not guaranteed to work fine. But "RenderTexture::saveToFile" should work fine because it's wrapped with a custom command in code.
I think this issue has already been solved in cocos2d-x v3.3, please refer http://www.cocos2d-x.org/issues/5562 for more information.
And also you could take a look at "cpp-tests" bundled with cocos2d-x to see how to save screenshot of your scene or sprite.

Zoom the picture within the picturebox of Visual Studio C++

I have a problem about zooming into the picture displayed in a picturebox Picture Control. The expected result is similar to the following link: A scrollable, zoomable, and scalable picture box. The picture is zoomed in within the picturebox. Note the picturebox is zoomed in.
However, this can be implemented in .NET Framework 2.0. I have searched some information on the Internet, but none used C/C++ Windows API of Visual Studio. How can I zoom a picture within a the picturebox Picture Control when I work on Windows Forms of Visual Studio C++ 2010. Thank you for anyone's reply.
I have faced the same issue and I searched a lot but didn't get the solution in cpp(freely available in c# and VB).
So finally i decided to implement it by my own. If your Image size is bigger than the picture box then only 1 level of zoom(original size of image) you can do with my implementation.
I will help you with the implementation. In current implementation
if you do left click of mouse it will ZoomIn and
if you do right click of mouse it will ZoomOut.
Assuming you have read the image file(.png, .jpg, .bmp, ...) in bmpPicture.
Bitmap ^bmpPicture = gcnew Bitmap(strFilename);// if not it can help
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
MouseEventArgs ^ms = (MouseEventArgs^)e;
if (ms->Button == System::Windows::Forms::MouseButtons::Left)
{
int pbx = ms->X;
int pby = ms->Y;
int img_x = (pbx * mwidth / pbwidth * 1.0f);
int img_y = (pby * mheight / pbheight * 1.0f);
pictureBox1->Location = System::Drawing::Point(pbx - img_x, pby - img_y);
pictureBox1->SizeMode = PictureBoxSizeMode::AutoSize;
pictureBox1->Image = bmpPicture;
}
else if(ms->Button == System::Windows::Forms::MouseButtons::Right)
{
int pbx = ms->X;
int pby = ms->Y;
pictureBox1->Location = System::Drawing::Point(0, 0);
pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage;
pictureBox1->Image = bmpPicture;
}
}
Hope this will help you...
Without any source code, it is difficult to comment.
StackOverflow is for problem solving; we can troubleshoot your starting code and get it working and during the course of which we can also fine tune design.
Anyway, I would like to give some pointers:
One or two picture boxes: entirely depends on your UI requirement.
Showing full or partial region of an image: StretchBlt is a powerful
API that can be used to achieve. See MSDN documentation for details.
Which class to use for picture box: if MFC is being used, then
derive a class from CStatic, overload the OnPaint() and use
StretchBlt to paint the image.
Classes to use for image: CBitmap, CImage, Gdiplus::Image.
Each have their own pros and cons.
If transparent images/PNGs are to be suported, better go for CImage or Gdiplus::Image.
You can get enough info here: CBitmap CImage Gdiplus::Image
Hope this would give you some starter.

Taking Screenshot of Full Desktop with Qt5

I figured out how to take a screenshot of the desktop today with Qt5 from an included example which gets the primary screen, grabs it, and then saves it.
I'm translating the code from Python without testing so if there's a small syntax error, then yeah you know. So I can easily take a screenshot of the primary screen with:
QApplication a(argv, argc);
QScreen *screen = a.primaryScreen();
QPixmap screenshot = screen->grabWindow(0);
screenshot.save('screenshot.png', 'png');
This will (obviously) take a screenshot of the primary monitor. The problem is I need to take a screenshot of all of the monitors. So I came up with this:
QList<QScreen*> screens = a.screens();
QScreen *screen;
QPixmap screenshot;
for(int i = 0; i < screens.length(); i++){
screen = screens.at(i);
screenshot = screen->grabWindow(0);
screenshot.save(QString::number(i) + ".png", 'png');
}
//takes and saves two screenshots on my end
This finds both of my monitors but the saved images are all a screenshot of the primary monitor and I can't figure out how to get the others. I've been playing with this for a few hours now and still can't figure it out. So can someone help me out?
I figured out a simple fix for this problem. When I was looking through the documentation recently, I found that the 'getWindow' method had default parameters of
(x = 0, y = 0, width = -1, height = -1)
So no matter what screen I called the getWindow method with, it kept giving me the same geometry. So to fix this, it's simply:
//Screen geometry
QRect g = screen->geometry();
//Take the screenshot using the geometry of the screen
QPixmap screenShot = screen->grabWindow(0, g.x(), g.y(), g.width(), g.height());

AI88 textures bug on Cocos2D 1.1beta2 with TMX tile maps

Recently I migrate my project to Kobold2D 1.1 with Cocos2D 1.1beta2 inside for iPad Retina Display. But when I run my project and try to put a TMX tile map, the program hung up. The problem is CCTexture2D is call in InitWithImage and there's no Case for texture format AI88. Because of that, program goes to default and hang up.
I add to the code:
case kCCTexture2DPixelFormat_AI88:
data = malloc(POTHigh * POTWide);
info = kCGImageAlphaOnly;
context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, NULL, info);
break;
Is the same config as kCCTexture2DPixelFormat_A8 and now code works. I used a TMX made with Tile Editor 0.8 and uses a simple PNG not in any texture packer. The name inside TMX is fondomaze.png but in the project I must rename to fondomaze-ipad.png.
Hope you find useful. Now I can breathe relax with my project still working!
Discover a workaround for Retina Display iPad... Must to increase malloc by 4.
data = malloc(POTHigh * POTWide * 4);
Hope helps people who want to work with RD iPad.

Manually drawing gradients for buttons, toolbars, tabs etc?

I would like to update some toolbar-like code we have to have a Vista/Win7 gradient roundedness to them.
Currently, the buttons have the Windows 2000 look & feel: blocky, single-tone.
I've played around with the XP themes, and using DrawThemeBackground, DrawThemeEdge, etc.; but I'm very dissatisfied with the theme drawing mechanics (the buttons are large, and the theme draws them as 2-tone, top half and bottom half, which looks okay when the buttons are small - it gives them a halfway decent appearance of being a gradient or having a rounded quality to them. But as large as these buttons are, they look stupid.
Experimenting by simply observing how many of the controls are drawn in various apps and controls, I can see that most of them seem to use gradients - where the top of the control appears a light color and fades to the bottom to a darker color - OR - where it is a lighter color than the background at the top, increases towards near-white at the middle, then fades back to a darker color towards the bottom.
I'm not really sure where to go from here. DrawThemeXXX seem to be inadequate. I don't really want to replace the entire control with a new one that has improved drawing but would require that I swap out some of the code for how the current custom control works, and risk various problems with some other library. I'd rather just have a way to draw arbitrary objects in the style of the current version of Windows that I'm running on. I would have thought that the theme drawing functions would have covered this. But they're fairly brain damaged, as I described.
Can someone point me towards 'How are modern C++ applications supposed to draw custom GUI elements so that they might reasonably expect a graceful appearance under XP, Vista, and Windows 7?'
We use MFC, Gdiplus, and raw Win32 APIs in our code, currently.
Here's to hoping someone knows a great deal about drawing modern GUIs under Windows from C++!
Just so that this isn't a wall of text, here's the current version of the paint handler, which draws the button with an etched border when 'hot-tracking' and both an etched border and the icon + text "depressed" (shifted by 1,1) when in a pressed state:
void CPlacesButton::PaintButton(CDC & dc, CRect & rcClient)
{
const int kLabelHeight = 8;
COLORREF clrHiLt = GetSysColor(COLOR_BTNHIGHLIGHT);
COLORREF clrShdo = GetSysColor(COLOR_BTNSHADOW);
COLORREF clrText = GetSysColor(COLOR_BTNTEXT);
COLORREF clrFace = GetSysColor(COLOR_BTNFACE);
// draw the button's background & border
if (m_bPressed || m_bDrawPressed || m_bMouseOnButton)
{
COLORREF clrDarkened = Darken(clrFace, -0.01f);
dc.FillRect(rcClient, &CBrush(clrDarkened));
//dc.Draw3dRect(rcClient, clrShdo, clrHiLt);
//dc.RoundRect(&rcClient, CPoint(10,10));
dc.DrawEdge(&rcClient, EDGE_ETCHED, BF_RECT|BF_FLAT);
//dc.DrawFrameControl(&rcClient, DFC_BUTTON, DFCS_BUTTONPUSH|DFCS_PUSHED);
}
// else if (m_bMouseOnButton) // hot draw
// //dc.Draw3dRect(rcClient, clrShdo, clrHiLt);
// dc.DrawEdge(&rcClient, EDGE_ETCHED, BF_RECT);
// //dc.RoundRect(&rcClient, CPoint(10,10));
else
dc.FillRect(rcClient, &CBrush(clrFace));
// use transparent mode for everything that follows
dc.SetBkMode(TRANSPARENT);
// center icon
CPoint ptIcon((rcClient.Width() - m_nIconSize) / 2, ((rcClient.Height() - m_nIconSize) / 2) - kLabelHeight);
if (m_bPressed || m_bDrawPressed)
ptIcon.Offset(1, 1);
// determine the state to draw ourselves in
const UINT nState = DST_ICON | (IsEnabled() ? DSS_NORMAL : DSS_DISABLED);
// draw our icon
dc.DrawState(ptIcon, CSize(m_nIconSize, m_nIconSize), m_hIcon, nState, (HBRUSH)NULL);
// create & select the font to use for the button's label
CFont guiFont;
VERIFY(guiFont.CreateStockObject(DEFAULT_GUI_FONT));
AutoSelectGDIObject select_font(dc, guiFont);
// determine clipping rect for label
CRect rcText(0, ptIcon.y+m_nIconSize+kLabelHeight, rcClient.Width(), ptIcon.y+m_nIconSize+kLabelHeight);
rcText.InflateRect(0,20);
if (m_bPressed || m_bDrawPressed)
rcText.OffsetRect(1, 1);
dc.SetTextColor(clrText);
if (IsEnabled())
dc.DrawText(m_strCaption, rcText, DT_VCENTER|DT_SINGLELINE|DT_CENTER);
else
dc.GrayString(NULL, NULL, (LPARAM)(LPCTSTR)m_strCaption, 0, rcText.TopLeft().x, rcText.TopLeft().y, rcText.Width(), rcText.Height());
}
I left some of the commented out variations in the code to indicate some hints as to what other possibilities I've tried. However, they're just a hint, as the complete alternate examples are not present.
Actually duplicating the look of the various flavors of Windows is ridiculously difficult, especially if your app can run on more than one version of windows.
I think that they intended to give you the api's to do this back in the Win2k/Win95 days, but then WinXP came along with shading and overlays, and the old API was completely inadequate.
So they came up with the theme stuff, which isn't really even an API so much as an API and a set of graphical primitives all jammed together. But they didn't follow through and allow the set of graphical primitives to be extended or replaced, so themes only works when your controls are a close match to the standard set.
So, for Win9x/Win2k. You use
DrawFrameControl
DrawEdge
For WinXP
DrawTheme
For WinVista/7
DrawTheme
DwmXXX functions
GradientFill ??
Now I suspect that Windows isn't actually using GradientDraw. I suspect it's actually using some DX10 shaders that are built in to the window manager code, but I don't know how to get at that, s I've been using GradientDraw instead. This code will give you a linear fade from the top of the control to the bottom.
INLINE void SetTrivertex(TRIVERTEX & vtx, int x, int y, COLORREF cr)
{
vtx.x = x;
vtx.y = y;
vtx.Red = (SHORT)(GetRValue(cr) * 256L);
vtx.Green = (SHORT)(GetGValue(cr) * 256L);
vtx.Blue = (SHORT)(GetBValue(cr) * 256L);
vtx.Alpha = (SHORT)(255 * 256L);
}
...
// fill the interior from the top down with a gradient that starts at crTop
// and ends with the crBottom
TRIVERTEX vtx[2];
SetTrivertex (vtx[0], prc->left+1, prc->top+1, crTop);
SetTrivertex (vtx[1], prc->right-1, prc->bottom-1, crBottom);
GRADIENT_RECT gRect = { 0, 1 };
GradientFill(hdc, vtx, 2, &gRect, 1, GRADIENT_FILL_RECT_V);
You never mentioned the MFC Feature Pack. Have you taken a look at it yet? Download for VS2008, included with VS2008 SP1. The CDrawingManager has lots of special effects. It has great support for application themes.
MFC alone isn't exactly skinning friendly. Apart from using another GUI (Qt is great for custom skinning) you can look at solutions like SkinCrafter.