Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sprite question

manmanon1manmanon1 Chicago, ILPosts: 3New Users Noob
So I found this online video tutorial about basically beginning to create "games" in iOS. I've been doing well with the tutorial, but I have run into a road block. Basically I wanted to make the background from an image (which works fine). Then I placed an image at the bottom of the iOS screen in the center of the screen (also works fine). Now i'm trying to get another image placed on the screen (one is a brick,the other is a little plane) but they both do not work.... I've tried changing the ( [_bgLayer addChild:sprite1] _bgLayer to my other variables and even to self, but the node will not add to the screen........ Anyone can point me in the right direction? I'm really not sure what happened...

The following is all in my game scene.m It was working fine until i tried to add the 3rd node (the plane shadow below or the player plane).
#import "GameScene.h"
#import "stdint.h"

@implementation GameScene{
    SKSpriteNode *planeShadow;
    
    SKNode *_bgLayer;
    SKNode *_gameLayer;
    SKNode *_HUDLayer;
    
    NSTimeInterval *_dt;
    NSTimeInterval *_lastUpdateTime;
    
    SKSpriteNode *_playerPlane;
    
}

//static const uint32_t planeCategory = 1 << 0;
//static const uint32_t worldCategory = 1 << 1;
//static const uint32_t skyCategory = 1 << 4;
//static const uint32_t pipeCategory = 1 << 2;
//static const uint32_t scoreCategory = 1 << 3;



-(void)didMoveToView:(SKView *)view {
   
  //  self.physicsWorld.gravity = CGVectorMake(0.0, -5.0);
    //self.physicsWorld.contactDelegate = self;
    
    
    /* Setup your scene here */
   
    self.backgroundColor = [SKColor whiteColor];
    
    _bgLayer = [SKNode node];
    [self addChild:_bgLayer];
    _gameLayer = [SKNode node];
    [self addChild:_gameLayer];
    _HUDLayer = [SKNode node];
    [self addChild:_HUDLayer];
    
    
    //planeShadow = [SKSpriteNode spriteNodeWithImageNamed:@bric];
    //planeShadow.zPosition = 11;
    //planeShadow.position = CGPointMake(60,500);
    //[_gameLayer addChild:planeShadow];
    
    
    SKTexture *backgroundTexture = [SKTexture textureWithImageNamed:@secondcloud1];
    //SKAction *moveBg = [SKAction moveByX:-backgroundTexture.size.width*2 y:0 duration:0.1*backgroundTexture.size.width];
    //SKAction *resetBg = [SKAction moveByX:backgroundTexture.size.width*2 y:0 duration:0];
    //SKAction *moveBackgroundForver = [SKAction repeatActionForever:[SKAction sequence:@[moveBg, resetBg]]];
    //for( int i = 0; i <2 + self.frame.size.width / ( backgroundTexture.size.width * 2); ++i){
     
        SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithTexture:backgroundTexture];
        [sprite setScale:1.0];
        sprite.zPosition = -20;
    sprite.anchorPoint = CGPointMake(0.5, 0.0);
        sprite.position = CGPointMake(CGRectGetMidX(self.frame), 0);
       // [sprite runAction:moveBackgroundForver];
        [_bgLayer addChild:sprite];
       // }
    

    
    
    SKTexture *groundTexture = [SKTexture textureWithImageNamed:@ground];
    //SKAction *moveBg = [SKAction moveByX:-backgroundTexture.size.width*2 y:0 duration:0.1*backgroundTexture.size.width];
    //SKAction *resetBg = [SKAction moveByX:backgroundTexture.size.width*2 y:0 duration:0];
    //SKAction *moveBackgroundForver = [SKAction repeatActionForever:[SKAction sequence:@[moveBg, resetBg]]];
    //for( int i = 0; i <2 + self.frame.size.width / ( backgroundTexture.size.width * 2); ++i){
    
    SKSpriteNode* sprite1 = [SKSpriteNode spriteNodeWithTexture:groundTexture];
    [sprite1 setScale:1.0];
    sprite1.zPosition = 10;
    sprite1.anchorPoint = CGPointMake(0.5, 0.0);
    sprite1.position = CGPointMake(CGRectGetMidX(self.frame), 0);
    // [sprite runAction:moveBackgroundForver];
    [_bgLayer addChild:sprite1];



    
    _playerPlane = [SKSpriteNode spriteNodeWithImageNamed:@pixelPlane];
    _playerPlane.position = CGPointMake(60,400);
    _playerPlane.zPosition = 50;
   // _playerPlane.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(46,18)];
   // _playerPlane.physicsBody.dynamic = YES;
   // _playerPlane.physicsBody.allowsRotation = NO;
  //  _playerPlane.physicsBody.categoryBitMask = planeCategory;
  //  _playerPlane.physicsBody.collisionBitMask = worldCategory | skyCategory | pipeCategory;
  //  _playerPlane.physicsBody.contactTestBitMask = worldCategory | skyCategory | pipeCategory;
    [_gameLayer addChild:_playerPlane];

}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */
    
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];
        
        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@Spaceship];
        
        sprite.xScale = 0.5;
        sprite.yScale = 0.5;
        sprite.position = location;
        
        SKAction *action = [SKAction rotateByAngle:M_PI duration:1];
        
        [sprite runAction:[SKAction repeatActionForever:action]];
        
        [self addChild:sprite];
    }
}
Tagged:

Replies

  • manmanon1manmanon1 Chicago, ILPosts: 3New Users Noob


    is the video link.

    I'll continue to mess with the anchor point/position

    I was just moving things around, and still no luck... It appears that the node is not being put into either layer (bg/game/hud/self). It still states I have 2 nodes in the project when I start (the secondclounds.png and ground.png)...... Any other thoughts?
Sign In or Register to comment.