Sprite Question


so found online video tutorial beginning create "games" in ios. i've been doing tutorial, have run road block. wanted make background image (which works fine). placed image @ bottom of ios screen in center of screen (also works fine). i'm trying image placed on screen (one brick,the other little plane) both not work.... i've tried changing ( [_bglayer addchild:sprite1];) _bglayer other variables , self, node not add screen........ can point me in right direction? i'm not sure happened...

following in game scene.m working fine until tried add 3rd node (the plane shadow below or player plane).

code:
          #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 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 = 0; <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 = 0; <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 touch begins */            (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];      }  }    
 

whenever i've had happen, it's due sprite getting drawn offscreen. try messing around position , anchor point see if can show up.
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

Snow Angels: Men Dig Out Moose Buried By Avalanche

Error installing Key Agent drivers in Windows 7

IOH Heatsink & CPU B Core 0 Relative to ProcHot