I am facing some problem with converting the loadPhysicsSprite into native Xcode language. I have converted it like this way:
void levels::loadPhysicsSprite(float width, float height, float xpos, float ypos, NSString *imageName, int phyType, int imagenum, NSString *shapeFileName) {
//rem load the image
if (imagenum<=0)
imagenum = agk::LoadImage([[NSString stringWithFormat:@"%@", imageName] cStringUsingEncoding:NSUTF8StringEncoding]);
else
agk::LoadImage(imagenum,[[NSString stringWithFormat:@"%@", imageName] cStringUsingEncoding:NSUTF8StringEncoding]);
//rem create the sprite
float scaleX = width / agk::GetImageWidth(imagenum);
float scaleY = height / agk::GetImageHeight(imagenum);
agk::CreateSprite(imagenum, imagenum);
agk::SetSpriteSize(imagenum,width,height);
agk::SetSpriteOffset(imagenum,width*0.5,height*0.5);
agk::SetSpritePositionByOffset(imagenum,xpos,ypos);
agk::SetSpritePhysicsOn(imagenum,phyType);
agk::SetSpriteShape(imagenum,0);
//rem read the contents and create the shape
int filenum = agk::OpenToRead([[NSString stringWithFormat:@"%@", shapeFileName] cStringUsingEncoding:NSUTF8StringEncoding]);
NSString *nul;
nul = [NSString stringWithUTF8String:agk::ReadLine(filenum)];
float shapes = atof(agk::ReadLine(filenum));
for (int i=0; i<shapes; ++i) {
nul = [NSString stringWithUTF8String:agk::ReadLine(filenum)];
nul = [NSString stringWithUTF8String:agk::ReadLine(filenum)];
int totalnum = atof(agk::ReadLine(filenum));
for (int x=1; x<totalnum; ++x) {
nul = [NSString stringWithUTF8String:agk::ReadLine(filenum)];
float pntx = FloatVal([NSString stringWithUTF8String:agk::ReadLine(filenum)]);
float pnty = FloatVal([NSString stringWithUTF8String:agk::ReadLine(filenum)]);
agk::AddSpriteShapePolygon(imagenum,totalnum,x-1,pntx*scaleX,pnty*scaleY);
}
}
agk::CloseFile(filenum);
}
float levels::FloatVal(NSString *s) {
NSString *s1=@"";
NSString *s2=@"";
int l = s.length;
NSRange range;
for (int c=1; c<l; ++c) {
//NSString *letter = mid(s,c,1);
range.location = c;
range.length = 1;
NSString *letter = [s substringWithRange:range];
if (letter==@".") {
range.location = c+1;
range.length = l - c;
//s2 = mid(s,c+1,l-c);
s2 = [s substringWithRange:range];
break;
}
else
s1 = [s1 stringByAppendingString:letter];
}
int v1 = [s1 intValue];
float v2 = [s2 floatValue];
int n = s2.length;
if (n>6) {
n=6;
//s2$=mid(s2$,1,6);
range.location = 1;
range.length = 6;
NSString *temp = [s2 substringWithRange:range];
v2 = [temp floatValue];
}
for (int i=1; i<=n; ++i)
v2=v2*0.1;
float v=(float)v1+v2;
return v;
}
But the app is Not drawing the shapes. I have the background and all other images, but the static shapes r not in there. So what I have is the image only. Can you help me out of this problem? It works fine in AppGameKit, but creating problem in Xcode
@@@@baxslash
Subbir Rahman