0

I’m building a game which have forever scrolling ground. Ground have some holes,and game over when player fall into a hole. I can scrolling background. But I can't scrolling "Ground" which have PhysicsBody (and player can stand).

I tried 2 ways,like this.

1) Scrolling TileMap using JSTilemap It's made game running so slowly, and it not scrolling forever.

2) Scroll SpritNode from ground image file. There an error "PhysicsBody: Could not create physics body" when I use [SKPhysicsBody bodyWithTexture].

Which way is better? and , Isn't there any other way?

Thanks,

  • you can create physics bodies at run time easily so my suggestion is this create a endless running background which contains all holes and platform but attach physics body only to hole and platform when they are inside display area and remove them when they are out of display area this would give you a smooth feel even on lower memory device because you are created only few physics bodies. – dragoneye Nov 05 '14 at 05:39
  • Thank you VERY much for your reply,dragoneye!! How do I create physics bodies only visible area? – mmmmmadoka Nov 05 '14 at 05:45
  • create a new class hole by extending SKSpriteNode or SKnode (which is a subclass of SKSpriteNode or SKnode) now create a boolean property of that class suppose isPhysics so when ever you create a new instance of that hole class isPhysics is false now inside -(void)update:(CFTimeInterval)currentTime { function check the position of hole class if its inside display area attach a physics body with it and make isPhysics to true so your code not going to attach physics body again and remove that physics body when your node outside the visible area. – dragoneye Nov 05 '14 at 06:20
  • I get it!!I'll try that. Thanks a lot!!! – mmmmmadoka Nov 05 '14 at 06:58
  • Which is better to create "Endless running background" in either way?(simple SKNode or JSTileMap) And How do I know Each of the coodinate? ex. hole or ground or ... – mmmmmadoka Nov 05 '14 at 09:43

2 Answers2

0

use simple SKNode class extends it my adding all holes and platform for e.g. SKNodebase addChild:hole and SKNodebase addChild:platform give each hole and platform a name for example hole.name="h1" now inside -(void)update:(CFTimeInterval)currentTime

[remember that your SKScene function would update -(void)update:(CFTimeInterval)currentTime function which you would have to write inside SKNodebase class]

 [[self children] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        SKNode *node = (SKNode *)obj;
        if ([node.name  isEqual: @“hole”]) {
            CGPoint position;
            //node.position get position of node on each update
        }
        if([node.name  isEqual: @“platform”])
        {
            CGPoint position;
           //node.position get position of node on each update

        }
    }];
dragoneye
  • 703
  • 6
  • 14
0

You may want to try this:

update():
ground0.position.x -= closeSpeed
ground1.position.x -= closeSpeed

if ground0.position.x <= -ground0.size.width{
   ground0.position.x = ground0.size.width - closeSpeed
}if ground1.position.x <= -ground1.size.width{
   ground1.position.x = ground1.size.width - closeSpeed
}

My code works in my game which doesn't have holes on the ground. Yu can create several sections of ground and scroll them randomly

Edit: This will be very useful too for scrolling background.

ParallaxBackground

Alfred
  • 161
  • 10