हाय है, मैं इस बग को स्प्राइटकिट के भौतिकी आकार के साथ उल्टा दिखाई देने की कोशिश कर रहा हूं।स्प्राइटकिट एसकेफिजिक्स बॉडी बॉडीविथटेक्चर
[SKPhysicsBody bodyWithTexture:monsterTexture size:monsterTexture.size]
पहली बार राक्षस प्रकट होता है कि फ़ैसिक्स बॉडी ओरिएंटेशन सही है। लेकिन दूसरी बार और उसके बाद राक्षस प्रकट होता है कि यह भौतिकी शरीर वाई अक्ष के साथ उलटा हुआ है। चित्र देखें जहां skView.showsPhysics = true;
तो भौतिकी आकार प्रदर्शित होते हैं। तथ्य यह है कि यह पहली बार सही ढंग से काम करता है मुझे लगता है कि शायद कुछ संपत्ति मुझे पता नहीं है कि संशोधित किया जा रहा है या कुछ।
मैंने बूट के किसी न किसी आकार में 2 भौतिकी ब्लॉक को एक साथ रखने का विचार किया लेकिन यह आदर्श नहीं है क्योंकि कुछ अन्य जटिल आकार हैं जिन्हें मैं शरीर का उपयोग करना चाहता हूं, उस पर एक ही बग का अनुभव कर रहे हैं।
मैंने bodyWithTexture:monsterTexture
, bodyWithTexture:monster.texture
, राक्षस ऑब्जेक्ट के बनावट के बजाय मूल SKTexture ऑब्जेक्ट का भी प्रयास किया है।
यहाँ मेरी ऐड राक्षस कोड है। अगर आपको और चाहिए तो मुझे बताएं।
- (Monster *)monster:(NSDictionary *)settings
{
NSDictionary * monsterDefaults = [self monsterDefaults];
NSDictionary * monsterConfig = [self monsterConfig:settings[TYPE]];
SKTexture * monsterTexture = monsterConfig[TEXTURE] ? monsterConfig[TEXTURE] : monsterDefaults[TEXTURE];
Monster * monster = [Monster spriteNodeWithTexture:monsterTexture];
// Animation
if (monsterConfig[ANIMATION]) {
[monster runAction:monsterConfig[ANIMATION]];
}
// Moster Stats
monster.name = MONSTER_SPRITE;
monster.type = settings[TYPE];
monster.points = monsterConfig[POINTS] ? [monsterConfig[POINTS] intValue] : [monsterDefaults[POINTS] intValue];
monster.damage = monsterConfig[DAMAGE] ? [monsterConfig[DAMAGE] intValue] : [monsterDefaults[DAMAGE] intValue];
monster.hp = monsterConfig[HP] ? [monsterConfig[HP] intValue] : [monsterDefaults[HP] intValue];
monster.lethal = monsterConfig[LETHAL] ? [monsterConfig[LETHAL] boolValue] : [monsterDefaults[LETHAL] boolValue];
// Monster Physics
float physicsResize = monsterConfig[RESIZE] ? [monsterConfig[RESIZE] floatValue] : [monsterDefaults[RESIZE] floatValue];
switch ([monsterConfig[SHAPE] intValue]) {
case COMPLEX:
NSLog(@"%@", monster.texture);
NSLog(@"rotation: %f", monster.zRotation);
NSLog(@"x scale: %f", monster.xScale);
NSLog(@"y scale: %f", monster.yScale);
monster.physicsBody = [SKPhysicsBody bodyWithTexture:monster.texture size:monster.texture.size];
break;
case RECTANGLE:
monster.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(monster.size.width * physicsResize, monster.size.height * physicsResize)];
break;
default:
monster.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:(monster.size.height * physicsResize)/2];
break;
}
monster.physicsBody.dynamic = false;
monster.physicsBody.affectedByGravity = false;
monster.physicsBody.categoryBitMask = monsterCategory;
monster.physicsBody.contactTestBitMask = weaponCategory | heroCategory;
monster.physicsBody.collisionBitMask = defaultCategory;
// Monster Flight Pattern
SKAction * flightPattern = [self monsterFlightPattern:monster settings:settings];
// Monster Rotation
// Rotation disabled for physics text
// [self monsterRotation:monster rotationConfig:monsterConfig[ROTATION]];
// Move & Remove
SKAction * remove = [Config removeAction:monster];
[monster runAction:[SKAction sequence:@[flightPattern, remove]]];
return monster;
}
मैं बनावट कैशिंग कर रहा हूँ जब वर्ग भार
@property (nonatomic) SKTexture * monsterBootTexture;
...
- (id)initWithFrameSize:(CGSize)frameSize
{
...
SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:monsterAtlas];
self.monsterBootTexture = [atlas textureNamed:MONSTER_BOOT];
...
}
NSLog के रूप में पढ़ता:
2015-01-02 12:03:20.619 Gadget Blaster[3301:665394] <SKTexture> 'boot.png' (97 x 100)
2015-01-02 12:03:20.623 Gadget Blaster[3301:665394] <SKTexture> 'boot.png' (97 x 100)
मैं LearnCocos2D की टिप्पणी प्रति निम्नलिखित लॉग जोड़ लिया है:
2015-01-03 12:00:06.131 Gadget Blaster[3987:772046] rotation: 0.000000
2015-01-03 12:00:06.133 Gadget Blaster[3987:772046] x scale: 1.000000
2015-01-03 12:00:06.134 Gadget Blaster[3987:772046] y scale: 1.000000
2015-01-03 12:00:08.131 Gadget Blaster[3987:772046] rotation: 0.000000
2015-01-03 12:00:08.131 Gadget Blaster[3987:772046] x scale: 1.000000
2015-01-03 12:00:08.132 Gadget Blaster[3987:772046] y scale: 1.000000
2015-01-03 12:00:10.156 Gadget Blaster[3987:772046] rotation: 0.000000
2015-01-03 12:00:10.156 Gadget Blaster[3987:772046] x scale: 1.000000
2015-01-03 12:00:10.159 Gadget Blaster[3987:772046] y scale: 1.000000
इसके अतिरिक्त जटिल भौतिकी निकायों का उपयोग करते समय मुझे टकराव के साथ कुछ अप्रत्याशित समस्याएं आ रही हैं। SKPhysicsBody bodyWithCircleOfRadius
बहुत बेहतर प्रदर्शन करता प्रतीत होता है और मैं बस सभी राक्षस सर्कल भौतिकी आकार बनाने पर विचार कर रहा हूं।
जांचें कि क्या स्प्राइट या उसके माता-पिता या तो स्केल किए गए हैं या घुमाए गए – LearnCocos2D
@ LearnCocos2D सही दिखते हैं। मैंने उपर्युक्त विधि में 3 एनएसएलॉग जोड़े हैं और नीचे दिए गए पहले 3 राक्षसों के लॉग आउटपुट को जोड़ा है। –
मुझे एक ही समस्या है, केवल तभी जब दृश्य पुनः लोड हो। –