मैंने इसे ऐसा किया, और यह पूरी तरह से काम करता है।
baseBar = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:CGSizeMake(CGRectGetMidX(self.frame)-40, self.frame.size.height/10)];
//The following will make the health bar to reduce from right to left
//Change it to (1,0.5) if you want to have it the other way
//But you'd have to play with the positioning as well
[baseBar setAnchorPoint:CGPointMake(0, 0.5)];
CGFloat goodWidth, goodHeight;
goodHeight =self.frame.size.height-(baseBar.frame.size.height*2/3);
goodWidth =self.frame.size.width-(10 +baseBar.frame.size.width);
[baseBar setPosition:CGPointMake(goodWidth, goodHeight)];
[self addChild:baseBar];
मैं तो एक एक SKShapeNode साथ बार, के लिए 'फ्रेम' कहा, भरण रंग (clearcolour) के बिना, और एक स्ट्रोक का रंग::
//The following was so useful
SKShapeNode *edges = [SKShapeNode shapeNodeWithRect:baseBar.frame];
edges.fillColor = [UIColor clearColor];
edges.strokeColor = [UIColor blackColor];
[self addChild:edges];
तो सबसे पहले, मैं एक SKSpriteNode घोषित
जब मैं स्वास्थ्य को कम करना चाहता था, मैंने किया था निम्नलिखित:
if (playerHealthRatio>0) {
playerHealthRatio -= 1;
CGFloat ratio = playerHealthRatio/OriginalPlayerHealth;
CGFloat newWidth =baseBar.frame.size.width*ratio;
NSLog(@"Ratio: %f newwidth: %f",ratio,newWidth);
[baseBar runAction:[SKAction resizeToWidth:newWidth duration:0.5]];
}else{
// NSLog(@"Game over");
}
, सरल, स्वच्छ और नहीं ग बिल्कुल कम
आपको '+ (SKTexture *) बनावट द्वारा कॉल नोड के बनावट (पूरे रंग पट्टी माना जाता है) का सबसेट प्राप्त करने में सक्षम होना चाहिए: प्रदर्शन: ' – Aky