Wednesday, 15 July 2015

objective c - iOS Sprite Kit Platform Jumper Issue -



objective c - iOS Sprite Kit Platform Jumper Issue -

i working on platform jumper app total douche-noob. anyway, found tutorial online , started adjusting code.

my problem now: created spritekitnode static image. want override running (jumping/ attacking) animation. figured set atlastexture coordinates spritenode coordinates. works (for without animation). when start move mapchildnode (the static image), own texture moves out of screen, because map starts center static node. tried set textures same coordinates node every frame , console displays coordinates same. nevertheless texture moves away node.

now said, total noob. please bear me, if displaying wrong lines of code now..

@implementation gamelevelscene -(id)initwithsize:(cgsize)size { if (self = [super initwithsize:size]) { [[sktaudio sharedinstance] playbackgroundmusic:@"sim.mp3"]; self.backgroundcolor = [skcolor colorwithred:.4 green:.4 blue:.95 alpha:1.0]; self.map = [jstilemap mapnamed:@"nun.tmx"]; [self addchild:self.map]; self.walls = [self.map layernamed:@"walls"]; self.hazards = [self.map layernamed:@"hazards"]; self.player = [[player alloc] initwithimagenamed:@"koalio_stand"]; self.player.position = cgpointmake(100, 80); self.player.zposition = 15; [self.map addchild:self.player]; // animation sktextureatlas *atlas = [sktextureatlas atlasnamed:@"noel"]; sktexture *f1 = [atlas texturenamed:@"noel1.png"]; sktexture *f2 = [atlas texturenamed:@"noel2.png"]; sktexture *f3 = [atlas texturenamed:@"noel3.png"]; sktexture *f4 = [atlas texturenamed:@"noel4.png"]; sktexture *f5 = [atlas texturenamed:@"noel5.png"]; sktexture *f6 = [atlas texturenamed:@"noel6.png"]; sktexture *f7 = [atlas texturenamed:@"noel7.png"]; self.noel = [skspritenode spritenodewithtexture:f1]; [self addchild:self.noel]; nsarray *noelrunning = @[f1, f2, f3, f4, f5, f6, f7, f6, f5, f4, f3, f2, f1, f2, f3, f4, f5, f6, f7, f6, f5, f4, f3, f2, f1, f2, f3, f4, f5, f6, f7, f6, f5, f4, f3, f2, f1]; // larn loop!? self.running = [skaction animatewithtextures:noelrunning timeperframe:0.03]; // end of animation self.userinteractionenabled = yes; } homecoming self; }

the static image beingness "koalio-stand.png"

so there update method:

- (void)update:(nstimeinterval)currenttime { if (self.gameover) return; nstimeinterval delta = currenttime - self.previousupdatetime; if (delta > 0.02) { delta = 0.02; } self.previousupdatetime = currenttime; [self.player update:delta]; //[self.noel runaction:self.running]; [self checkforandresolvecollisionsforplayer:self.player forlayer:self.walls]; [self handlehazardcollisions:self.player]; [self checkforwin]; [self setviewpointcenter:self.player.position]; }

and there big troublemaker..? method centers view , when view centered, both static image , texture moving apart (the static 1 staying in middle, texture moving out of screen). console displays both having same coordinates. used >> self.player.position = self.noel.position <<

- (void)setviewpointcenter:(cgpoint)position { nsinteger x = max(position.x, self.size.width / 2); nsinteger y = max(position.y, self.size.height / 2); x = min(x, (self.map.mapsize.width * self.map.tilesize.width) - self.size.width / 2); y = min(y, (self.map.mapsize.height * self.map.tilesize.height) - self.size.height / 2); cgpoint actualposition = cgpointmake(x, y); cgpoint centerofview = cgpointmake(self.size.width/2, self.size.height/2); cgpoint viewpoint = cgpointsubtract(centerofview, actualposition); self.map.position = viewpoint; self.noel.position = self.player.position;

}

i begging help =((

i don't understand trying acomplish, if question why player , noel objects moving different places when assign them same positions? reply variables player , noel children of different parents, player children of self.map , noel children of self.

and positions of nodes relative parents frames.

ios objective-c sprite-kit game-engine

No comments:

Post a Comment