I have 3 sets of sprite sheets for my first scene.
I'm using XCode to develop for iOS using Cocos2D-X.
The first sprite sheet has an extension -sd,
the second sprite sheet has -hd,
and the third set has 3 sprite sheets (using Multipack in Texture Packer Pro) with the extension -ipadhd.
I followed a tutorial and I found a method that goes like this
CCString* file = (Utils::getArtScaleFactor() > 1) ? CCString::create("randomFile-hd.plist") : CCString::create("randomFile-sd.plist");
//The Utils::getArtScaleFactor function
float Utils::getArtScaleFactor()
{
return artScaleFactor;
}
1- Is there a similar way to choose between 3 files instead of 2?
2- Is this the common method for choosing the appropriate file size-wise?
3- This question is somewhat off the topic I was discussing but I really need an answer to it too: I have an animation and its frames are split into 3 sprite sheets, how do I cache 3 .plist files? And if that's impossible, what are my options?
Hope I provided all the necessary information!
Regards
Sure, but that ternary operator should probably be switched out with another construct (like a switch) for clarity and flexibility.
For example:
// Always init your pointers.
CCString* file = NULL;
switch (Utils::getArtScaleFactor())
{
// Scale factor shouldn't ever be 0, but we should account for it
// so it doesn't get picked up by the default case.
case 0:
case 1:
file = CCString::create("randomFile-sd.plist");
break;
case 2:
file = CCString::create("randomFile-hd.plist");
break;
// Scale factors 3 and above get the largest resource.
default:
file = CCString::create("randomFile-super-hd.plist");
break;
}
Yes, this type of logic is on the wiki, except they use if-else for three resource sizes. I've seen it on the forums and tutorials, too.
According to this thread on the cocos2d-iphone forums, yes:
CCSprite can display CCSpriteFrames with different textures.
So there’s no problem at all even to use animation that mixes frames from different textures (spritesheets) - Stepan Generalov
The implementations posted there are in obj-c but you can convert the cocos2d api calls to cpp easily.
Related
Hi i have this QUI project its based match 3 game. I have problem with checking if in row there is 3 same type pic. i try to check if the next label in row is same picture and add it to new vector adding at the moment i cant find any way i could compare two pictures. I have tried chacheKey and few other methods but don't make them work. If they are same i could use any help to this project. Thank you.
QPixmap pic_value = labels[y][x]->pixmap(Qt::ReturnByValue);
QPixmap pic_value2 = labels[y][x+1]->pixmap(Qt::ReturnByValue);
if (pic_value.cacheKey() == pic_value2.cacheKey())
{
match_set.append(labels[y][x+1]);
}
Try the following code:
if (pic_value.toImage() == pic_value2.toImage())
Reference: https://www.qtcentre.org/threads/13537-do-we-can-t-compare-QIcon-or-QPixmap
First, unfortunately you can't compare QPixmap directly with the == operator so you will compare it by transferring it to an image then compare it.
if (mLogo.toImage() == logo.toImage())
return;
Secondaly, based on the QImage comparison from this documentation
The comparison can be slow, unless there is some obvious difference (e.g. different size or format), in which case the function will return quickly.
So, the operation of setting the mLogo to logo is easier than the checking for comparison.
I'm pretty new to QT so maybe the answer to this question is simple. I'm making a terminal for our freescale car this year which is just a car that autonomously goes around a track. We're using line-scan cameras which give you a line of data 128 pixels long that you refine into either "white" or "black" (edges of the track) values. Last year the team made this terminal in QT which is used for modifying certain coefficients, stopping the motors, and all kinds of stuff through bluetooth. A text browser was used to display what the line cameras see.
Last year they combined the two cameras to create one image, but we're re configuring them this year, and they will produce two different images of the track. Naturally, I need to make two text browsers, one for each camera. Should simply be a case of copying code and changing some names right? Well apparently not.
I placed the text browser in the window using the design gui, named it, and made its settings match the other browser. I went into the code for the main window c file and adapted the code there. For every reference to the other browser I made sure one was an equal line of code for this one. When I was done and went to build the project, it told me that the browser wasn't a member of 'UI::MainWindow,' and pointed me to the ui_mainwindow.h file. So I went into that header and did the same thing in there. But when I built that, it gave me the error:
...\ui_mainwindow.h:1363: error: C2065: 'tb_camera_out_close' : undeclared identifier
How can that be? There doesn't appear to be any other reference to the other text browser and it works fine. How do I go about declaring this? Shouldn't the gui interface have done it for me when I placed it?
Here's the code from the main window's C file that is involved:
ui->tb_camera_out->setText(msgs_received[1] + '\n' + ui->tb_camera_out->toPlainText());
ui->tb_camera_out_close->setText(msgs_received[2] + '\n' + ui->tb_camera_out_close->toPlainText());
tb_camera_out is the old camera code(I am aware that the toplaintext() part won't work, I'm also attempting to get the text to scroll down instead of up like a track would if you were actually driving but I need to fix this major issue first)
Here's the code from the header that I added:
tb_camera_out = new QTextBrowser(centralWidget);
tb_camera_out->setObjectName(QStringLiteral("tb_camera_out"));
sizePolicy.setHeightForWidth(tb_camera_out->sizePolicy().hasHeightForWidth());
tb_camera_out->setSizePolicy(sizePolicy);
tb_camera_out->setMinimumSize(QSize(450, 0));
tb_camera_out->setMaximumSize(QSize(16777215, 16777215));
tb_camera_out->setStyleSheet(QLatin1String("background-color: rgb(0, 0, 0);\n" "color: rgb(31, 234, 0);"));
gridLayout_4->addWidget(tb_camera_out, 1, 0, 1, 5);
tb_camera_out_close = new QTextBrowser(centralWidget);
tb_camera_out_close->setObjectName(QStringLiteral("tb_camera_out_close"));
sizePolicy.setHeightForWidth(tb_camera_out_close->sizePolicy().hasHeightForWidth());
tb_camera_out_close->setSizePolicy(sizePolicy);
tb_camera_out_close->setMinimumSize(QSize(450, 0));
tb_camera_out_close->setMaximumSize(QSize(16777215, 16777215));
tb_camera_out_close->setStyleSheet(QLatin1String("background-color: rgb(0, 0, 0);\n" "color: rgb(31, 234, 0);"));
Again, the old code is at the top with the references to tb_camera_out. The stuff I added is associated with tb_camera_out_close.
I seem to have solved the problem. Strangely enough, to fix the errors that were showing up I not only had to edit that header, but I then had to delete it and run qmake to restore it. I then had to delete all the past builds to get the thing to even show up when I ran it.
I've got a pretty old MFC application that's been touched by many people over the years (most of them probably not even CS guys) and it follows, what I like to call the "anarchy design pattern."
Anyway, one of the dialogs has a series of 56 vertical sliders and check boxes. However, there are additional sliders and checkboxes on the dialog as shown below.
Now, the problem is that the additional sliders and checkboxes take on IDs that are in sequence with the slider/checkbox series of the dialog. My task is to add more sliders and checkboxes to the series (in the blank space in the Slider Control group box) Unfortunately, since IDC_SLIDER57 through IDC_SLIDER61 are already in the dialog (same goes for the checkboxes), existing code, such as the snippet below will break:
pVSlider = (CSliderCtrl *)GetDlgItem(IDC_SLIDER1+i);
Is there a better way to modify the resource file without doing it manually? I've seen a third party tool called ResOrg that looks like it'll help do what I want, but the software is a bit pricey, especially since I'll only use it once. I guess I can give the demo a try, but the limitations might restrict me.
FYI, I'm using Visual C++ 6.0 (yes...I know, don't laugh, it's being forced upon me).
Instead of writing:
pVSlider = (CSliderCtrl *)GetDlgItem(IDC_SLIDER1+i);
you could write:
pVSlider = (CSliderCtrl *)GetDlgItem(GetSliderID(i));
where GetSlider is a function that returns the id of slider number i.
GetSlider function
int GetSliderID(int nslider)
{
static int sliderids[] = {IDC_SLIDER1, IDC_SLIDER2, IDC_SLIDER3, .... IDC_SLIDERn};
ASSERT(nslider < _countof(sliderids));
return sliderids[nslider];
}
With this method the IDC_SLIDERn symbols dont need to have sequential values.
I've just used cocos2d-x for creating some games. When I read the HelloWorld.cpp, I saw this line
Scene* HelloWorld::createScene()
That's strange for me. How does it work? A method named creatScene that takes no parameters and returns a pointer to a Scene ?
In different libraries, there are different methods to initialize library or some part of that. So, in this case, it maybe create a new context inside library and return it without any argument. It maybe needs no arguments (use defaults) it this step of get them from somewhere else like configuration file. And note that this is convenient to use this type of initializing. Like this:
rc = redis.Redis() #uses default values for server address
It is really an easy question even it cannot be called as question when you check the source code.
In cocos2d-x, CCScene always create this way.
1. create a Layer, which coded by yourself with a lot of other widgets.
2. create a Scene
3. add the layer to the scene
4. return the scene you create.
I use Coded UI in VS2012.
I would like to solve an interesting problem.
For example, there is an application which has got a window and it has got a title with dynamic content.
I would like to search this window via it's title.
The next titles are the possible cases:
"AAAAAAAA This is a window title ASDASDASD or"
"BBBBBBBB This is a window title WSDWSDWSD or not"
"CCCCCCCC This is a window title ASDASDASD or"
"........ This is a window title ASDASDASD"
I would like to search something which contains "This is a window" and "or not".
If i could use regex, i use the following expression to find this title: *This is a window*or not*.
I emphasize, that is only an example. The essential is there is a title which contains some fix strings.
I know, that a UITestControl has PropertyExpressionCollection which name is SearchProperties.
I can add to it a PropertyExpression(propertyName, propertyValue, conditionOperator) object.
The problem is: i can decide the SearchProperties with two step (formally):
WinWindow.SearchProperties.Add(WinWindow.PropertyNames.Name,"This is a window", PropertyExpressionOperator.Contains);
WinWindow.SearchProperties.Add(WinWindow.PropertyNames.Name,"or not", PropertyExpressionOperator.Contains);
How can i do it in one simple step?
Or which solution can implement this requirements?
Thanks in advance,
Peter
For reasons mentioned above it seems the best solution is to iterate thru all the windows under the desktop. Here's a snippet (for testing I'm looking for a notepad window) I'm not too proud of, but works and finishes under one second:
UITestControl result = null;
var TM = Playback.GetCoreTechnologyManager("MSAA");
var desktop = UITestControl.Desktop.GetChildren()[1].GetProperty(UITestControl.PropertyNames.UITechnologyElement) as UITechnologyElement;
var windowEnumerator = TM.GetChildren(desktop, null);
windowEnumerator.Reset();
while (windowEnumerator.MoveNext())
{
UITechnologyElement current = windowEnumerator.Current as UITechnologyElement;
if (current.Name != null &&
current.Name.Contains("Notepad") &&
current.Name.Contains("Untitled"))
{
result = UITestControlFactory.FromNativeElement(current.NativeElement, "MSAA");
break;
}
}
}
I used the MSAA technology manager because it was about seven times faster than using the UITestControls. Going down to MSAA level (IAccessible) can finish the job in about 50 milliseconds but using WinApi functions may get you the same results.
I'm sorry, I can't think of any simpler solution for this problem at the moment.
There are couple of ways to do it,
1. If you know how the Title of the page is dynamically generated,
create a static variable/class and generate the title at run time and use your code.
If you are aware of the possible Title's, create a static class and hardcode the values there.