Changing CCSpriteSheet to CCSpriteBatchNode - cocos2d-iphone

I have tried to change CCSpriteSheet to CCSpriteBatchNode as it is deprecated.
Before:
ss = [[CCSpriteSheet alloc] initWithFile:spriteFile capacity:frameCount];
After:
ss = [[CCSpriteBatchNode alloc] initWithFile:spriteFile capacity:frameCount];
I get the following warning:
Incompatible pointer types assigning to 'CCSpriteSheetInternalOnly *' from 'CCSpriteBatchNode *'
I'm quite new to this, and have a feeling I'm missing something obvious.

Related

How to use Animated GIF with TImage component?

In Delphi, the Timage component can play an animated GIF image:
(Image1.Picture.Graphic as TGIFImage).Animate := True;
I convert this code to C++ equivalent:
((TGIFImage)Image1->Picture->Graphic)->Animate = true;
But I get an error:
[bcc32c Error] Unit1.cpp(60): no matching conversion for C-style cast from 'Vcl::Graphics::TGraphic *' to 'Vcl::Imaging::Gifimg::TGIFImage'
Vcl.Imaging.GIFImg.hpp(937): candidate constructor not viable: requires 0 arguments, but 1 was provided
What's the problem?
You are missing a * in your type-cast:
((TGIFImage*)Image1->Picture->Graphic)->Animate = true;
^
And then, consider using a C++-style cast instead of a C-style cast:
static_cast<TGIFImage*>(Image1->Picture->Graphic)->Animate = true;

C++ make::shared wrapping on existing raw pointer

I am working on a small wrapper for an FMOD library. Below is a snippet of the code that I have, and there are other libraries that manage the SoundData class:
class SoundData
{
public:
...
std::string mSoundName;
std::shared_ptr<FMOD::Sound> mFmodSoundHandle;
...
}
void SoundLib::CreateSound(SoundData& data)
{
FMOD::Sound *sound = nullptr;
system->createSound(data.mSoundName.data(), FMOD_DEFAULT, nullptr, &sound);
data.mFmodSoundHandle = std::make_shared<FMOD::Sound>(sound);
}
Trying to compile this snippet of the code, I get this error:
Error C2664 'FMOD::Sound::Sound(const FMOD::Sound &)': cannot convert argument 1 from 'FMOD::Sound *' to 'const FMOD::Sound &' SoundLib ...\MSVC\14.29.30133\include\xutility 158
I cannot quite understand if I am using std::make_shared() in the wrong way here? The goal here is to save the output from createSound() that is passed as a sound variable into the structure SoundData. Variable data will be managed afterwards.
You're passing a pointer where you should pass a reference. Try *sound.
Notice that you're not wrapping a pointer, you're creating a new instance of Sound and copying the value of *sound into it.
To wrap it consider:
data.mFmodSoundHandle.reset(sound);

Swift3 changes to UnsafeMutablePointer

I am porting one of my iOS Apps to Swift3 / Xcode8.
I have embedded a C library, which expects a function parameter of type:
char ***
In Swift2.3 this was translated into a:
UnsafeMutablePointer<UnsafeMutablePointer<UnsafeMutablePointer<Int8>>>
So i could declare that pointer in my swift code like that:
let myPointer = UnsafeMutablePointer<UnsafeMutablePointer<UnsafeMutablePointer<Int8>>>.alloc(1)
This worked well until i updated to Xcode8 with Swift3, now i am getting a compiler error:
Cannot convert value of type 'UnsafeMutablePointer<UnsafeMutablePointer<UnsafeMutablePointer<Int8>>>' to expected argument type 'UnsafeMutablePointer<UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>?>!'
Can i anybody help me to understand the changes in swift3? What does this Optional, Optional, Implicit Unwrapped Optional (?) mean in this context and how i can i declare a pointer with this type?
Try
let myPointer = UnsafeMutablePointer<
UnsafeMutablePointer<
UnsafeMutablePointer<Int8>?>?>.allocate(capacity: 1)
Alternatively you could also use the _Nonnull annotation to keep the pointer as non-optional. Suppose the C function is void setPtr(char ***). You could write its declaration available to Swift via a bridging header as follows:
void setPtr(char * _Nonnull * _Nonnull * _Nonnull);
Then in your Swift code you can do something like this:
let myPointer = UnsafeMutablePointer<
UnsafeMutablePointer<
UnsafeMutablePointer<Int8>>>.allocate(capacity: 1)
setPtr(myPointer)
let myInt = myPointer.pointee.pointee.pointee
But what if setPtr(char *** ptr) in C code, where _Nonnull is not usable, does something like
*ptr = NULL;
? Then the Swift code will crash at runtime. However, using optionals you don't need the _Nonnull annotation in the declaration of setPtr(), your Swift code becomes
let myPointer = UnsafeMutablePointer<
UnsafeMutablePointer<
UnsafeMutablePointer<Int8>?>?>.allocate(capacity: 1)
setPtr(myPointer)
let myInt = myPointer.pointee?.pointee?.pointee
and it won't crash at runtime.
Thus the approach with optionals, enforced by Swift3 when you don't use _Nonnull, is safer.

COM : convert 'const GUID*' to const wchar_t*

I am porting some code from VS to mingw C++ . One of the statements in my code is
CFactoryTemplate g_Templates[1] = {
{&CLSID_SystemClock, CSystemClock::CreateInstance}
};
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
I am getting the following error on the first statement
error: cannot convert 'const GUID* {aka const _GUID*}' to 'const
WCHAR* {aka const wchar_t*}' in initialization
I am completely puzzled by this. I did a little investigation and noticed that
CFactoryTemplate is a class in combase.h . Also my project is UNICODE enabled if that matters. Any suggestions on how to resolve this issue ?
Your code - you say you are porting is wrong, you need to provide different parameters to CFactoryTemplate, the compiler error proves that. Here you will find some sample code to init such array of instances of this class (you dont need to fill all fields):
// list of class ids and creator functions for class factory
CFactoryTemplate g_Templates[2]=
{ { L"Gargle filter" // CFactoryTemplate.m_name
, &CLSID_Gargle // CFactoryTemplate.m_ClsID
, CGargle::CreateInstance // CFactoryTemplate.m_lpfnNew
, NULL // CFactoryTemplate.m_lpfnInit
, &sudGargle // CFactoryTemplate.m_pAMovieSetup_Filter
}
, { L"Gargle filter property page"
, &CLSID_GargProp
, CGargleProperties::CreateInstance
}
};
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
from https://msdn.microsoft.com/en-us/library/aa451506.aspx
also Hans Passant has given you other example

Error C2440 '=' : cannot convert from 'cli::array<Type> ^' to 'wchar_t'

I got a little problem with my C++/CLI progamm.
I got a few Char arrays wo work without problems.
Header1:
ref class _CGuid{
static const int CIDGR=37;
public:
array<Char>^ cGuid;
array<Char>^ cUuid;
}
Cpp1 -> contruktor:
cGuid = gcnew array<Char>(CIDGR);
some function:
_CGuid::Type(String^ tmpname,String^ tmpid)
{
pcName=tmpname;
cUuid=tmpid->ToCharArray();
}
So this Works Perfectly fine for me without errors.
How ever This doesn’t work:
Other Header:
ref class CStorage{
public:
array<String^>^ names;
array<Char>^ mac;
Other contruktor
names = gcnew array<String^>(100);
mac = gcnew array<Char>(100);
some function 2:
names[k]=tname;
mac[k]=tmac->ToCharArray(); <-------- Error Line
k++;
This line gets the error:
error C2440: '=' : cannot convert from cli::array<Type> ^ to wchar_t
with
[
Type=wchar_t
]
There is no context in which this conversion is possible
So I really don´t know whats the problem here.
The error says it all, actually. ToCharArray returns an array<Char>, which you try to assign to a single Char (= wchar_t) when accessing mac[k].
Did you maybe mean to assign to mac instead?
mac = tmac->ToCharArray();
If so, then this line is redundant:
mac = gcnew array<Char>(100);
Here you allocate memory for mac which you later throw away when you re-assign mac.
here you copy a CLI array coming from the "ToCharArray" in 1 wchar_t of the Mac array!
mac[k]=tmac->ToCharArray(); <-------- Error Line
as you want an array of Mac Address you must allocate it with
mac = gcnew array<array<Char> >(100);
so now you can affect mac[k]