Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsscore and life tracking
my enemies come pas the cat from the right side. now what i want to do is let the player lose point when the enemies past the cat. this is a a bit tricky for me as they are not hitting the ground but instead are going past the user or hitting the the machine for an explosion to occur. please any ideas and suggestions would be greatly appreciated thanks Amit Bijlani Ben Jakuben Ash Furrow
4 Answers
Stone Preston
42,016 Pointshmm maybe you could try place an invisible "wall" sprite at the spot where they pass the cat and check when they collide with that. you would have to add another collision category and update your code for that additional category but it seems pretty easy to do
Michael Blazek
162 PointsCould you post a screenshot of your layout in the game now?
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsi have just created a page on workspace and placed the file there the url is image in center. please let me know if you have any problems viewing it. l am working on the skphysics to present a proper annotation so that you can give me hand. thank you very much.
Michael Blazek
162 PointsGreat.. I think I see what your going for now. If you change the dimensions of the ground container so that the height is as big as the screen and the width can be like 10px, then change its position so that it lines up with the machine I think you will get what your looking for.
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointswas also thinking is alright if i push the project into github for you have a look at it for me please? you can view all the files then
Michael Blazek
162 PointsI could take a look tonight if you'd like.
Just so I understand though, you are trying to make it so when the ships get in line with the ships then the ships blow up... or at least half way aligned correct?
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsat the start, that was the idea because i couldn't let the enemies pass in front of the machine. managed ago code for them crash into it and explode. but used z-position now so they pass in front of the machine without hitting it. so that makes the SKPhysics question i asked you earlier irrelevant to this game but i would still love to know how to do that (i.e. at point of contact they enemies explode and not when they are halfway.).
With the game on github. l want the player to lose points when the enemies ship pass the cat without getting hit to be blown-up as they require to be hit twice before they explode. Would be brilliant if you can have a look at it for me tonight,thank you very much
Michael Blazek
162 PointsKelvin did you post a link to the github repo?
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointshi Micheal i have the project pushed to github here is the link
thanks mate
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointssorry was making sure had the right commands. still bait new to all this but enjoying it tho.
David Collins
6,643 PointsHi, I've had a quick look at your code.
You need to set the Category and contact bitmask on the grounds Physics properties. Also change the location of where the ground is (the green box).
This should do what you're looking for. When the dogs reach the left hand side of the screen before you shoot them you'll lose a life and they explode.
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsi came up with this code
+ (instancetype) groundWithSize: (CGSize)size {
RLGroundNode *ground = [self spriteNodeWithColor:[SKColor greenColor] size:size];
ground.name = @"Ground";
ground.position = CGPointMake(size.width,size.height);
return ground;
}
- (void) setupPhysicsBody {
self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size];
self.physicsBody.affectedByGravity = NO;
self.physicsBody.categoryBitMask = 0;
self.physicsBody.collisionBitMask = 0;
self.physicsBody.contactTestBitMask = 0;
}
@end
but don't seem to be working :(
David Collins
6,643 PointsNo, That code won't work. You need to assign the bit masks to the correct categories.
self.physicsBody.dynamic = NO;
self.physicsBody.categoryBitMask = CollisionCategoryGround;
self.physicsBody.collisionBitMask = CollisionCategoryDebris;
self.physicsBody.contactTestBitMask = CollisionCategoryEnemy
You change the grounds location in the Gameplay scene.
It might help to rewatch the Physics and Collision module.
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 PointsKelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointshow would i implement that code into the scene plea, Stone Preston can i know create not track that from using my anchor points. say if they pass the point (0,0) then lose point.