Im using Chipmunk with Cocos2d to make a gravity based puzzle game, however I have reached a part of my project whereby I need a sprite that once drawn does not move and cannot be moved by the other sprites within the environment.
In essence...
Can I create a static (non moving) sprite that is not affected by in game gravity or other objects in the game.
Thanks in advance I've only been doing this project a week....
Yes, this is possible.
1) Create a body with infinite mass and moment.
2) Do not add the body to the space.
3) Create the desired shape.
Use cpSpaceAddStaticShape to add the shape to the space.
Related
The gear joint in Box2d is great, but I don't know how to implement that in Sprite Kit. Is there any solutions to implement the gear joint in Sprite Kit?
Thanks.
Here are the available Sprite-Kit joints :https://developer.apple.com/reference/spritekit/skphysicsjoint
As far as I can understand, there does not appear to be a direct correlation to Box2D's gear joint, which seems to make one body rotate when another body is rotated.
In that case, you might want to investigate overriding the didSimulatePhysics or didFinishUpdate methods to manually set the rotation of one object based upon the rotation of another object:
https://developer.apple.com/reference/spritekit/skscene/1519965-didsimulatephysics
https://developer.apple.com/reference/spritekit/skscene/1520269-didfinishupdate
It might be as simple as:
wheel2.zRotation = wheel1.zRotation
but if the gears have different numbers of teeth (thus different ratios), you'll have to do some calculations.
I would like to create a textured terrain in SpriteKit similar to the one in the game Tiny Wings. Using cocos2d, I was able to follow Ray W's tutorial and get the look I wanted...
http://www.raywenderlich.com/32954/how-to-create-a-game-like-tiny-wings-with-cocos2d-2-x-part-1
Is plotting points to make triangles to fill with a repeating texture (or something similar) possible using SpriteKit?
Thanks in advance.
yeah you can create a game like tiny wing with sprite kit
step create serval CGMutablePath using http://dazchong.com/spritekit/ tool its a online SKPhysicsBody Path Generator and save them in a NSMutableArray array suppose you have only one level in your game for multiple level create multiple NSMutableArray array with multiple random saved CGMutablePath items
be sure all CGMutablePath have static physics body don't make it dynamic now
inside your init function add all paths one by one in a order that first path ends start of second path and so on make by this you can make a huge loop of serval path which are connecting with each other.
don't make more paths because too many physics body makes your game slow
now inside update function move all item of your array from right to left be sure
when you reach last item of your NSMutableArray array add it again at the begging of your looping algo.
-(void)update:(CFTimeInterval)currentTime {
}
make a tiny bird and give it a dynamic physics body
set collision and contact category of tiny bird as well as your loop paths
now inside didBeginContact function you can get contact between your tiny bird and path .now you can apply a little Impulse or you can get contact.collisionImpulse between your bird and path apply apply that value to the bird acc to your game
-(void)didBeginContact:(SKPhysicsContact *)contact
{
//contact
CGPoint contactPoint=CGPointMake(0, 0);
}
So it seems what I need to use (or at least I had in mind) are vertex shaders, but those are not currently supported in Spritekit. Right now, only fragment shaders are allowed from what I could find.
I did however see that you can create an SKShapeNode and set its texture property. The only problem with this is there is no option to "tile" that image throughout the SKShapeNode.
I did find this which seems to solve that issue (although I have not tried it out).
https://gist.github.com/man1/413642637ebd0b00fe2b
Seems like quite a work around!
In the end, I decided to use Cocos2d for this project as it supports both vertex and fragment shaders. With a bit of trial and error, I got it to work wonderfully.
I want to write a simple top down racing game for iOS. I want to use Sprite Kit instead Cocos2D , I'm new to game development and I have a question:
How can I create the race tracks? What I think is: One single big background image for each track and a car that moves over it and remains inside the track by interaction with a path. The path is inserted by a coordinate system in the level code and represents the "borders" of the road.
Is this a good way to start a top down racing game? Or are there better ways? How can I "draw" the path over my background image?
You can use "Tiled Map Editor" http://www.mapeditor.org/ to create your maps. I'm thinking you'll only need a few unique tiles, one for straight track, one for grass, one for curved track, maybe some trees, etc.
As for the path, you can try to use an polygonal edge physics body? And then move the car to where the user touches on the screen. if the user tries to move the car outside, the car will bump against the physics body of the edge.
I'm working on a game in which the user should be able to trigger 'rods' that come out from the edge of the screen to displace elements on screen (balls). These projectiles roughly resemble pool-cues. Or perhaps pinball plungers, except that they start from the 'loaded' position (mostly offscreen), and when triggered, they eject out, then quickly retreat.
I'm unclear how I should build these with Sprite Kit.
The game uses the PhysicsEngine, and the onscreen balls should be effected both by gravity AND they should be displaced when they collide with the rods. However the rods should neither be effected by gravity, not displaced when they collide with the balls -- they should simply retreat regardless of whether they've made contact with the balls.
I realize I can set the affectedByGravity property for the rods. However because they will still displace slightly when they collide with the balls. How can I 'fix' or 'peg' them in place? Do I need to use an SKPhysicsSlidingJoint? If so, has anyone encountered any examples online? Is there a simpler way to do this?
A related physics engine, Box2D distinguishes static, kinematic, and dynamic bodies.
Kinematic bodies can move and will collide with other objects, but they are themselves not affected by dynamic bodies or forces like gravity. Thus, consider setting rod.dynamic = NO; but animate it with actions. See also here in the reference for SKPhysicsBody.
In my game, I am using Cocos2D for the Game part. I am now trying to implement gravity but I am hearing that I have to use Box2D or Chipmunk. I could use those but is there any way to do this in Cocos2D, can anyone share any ideas/code just so I can add some simple gravity using Cocos2D if possible?
Thanks!
Its very easy using Box 2d and Chipmunk. Its inbuilt in cocos2d framework. Just when you start with the cocos2d application template(for iOS) select the Box2D/Chipmunk template. Its very easy.
Inorder to start with some gravity you have to create a world and add gravity vectors to it. You have a very simple and detailed tutorial in
http://www.raywenderlich.com/457/intro-to-box2d-with-cocos2d-tutorial-bouncing-balls
Its a tutorial that teaches you to create a bouncing ball app in Cocos2d Box2d Framework.
First create a CGPoint variable called gravity and set it's x value to 0 and it's y value to some negative number.
CGPoint *grav = ccp(0.0f,-9.8f);
Then, in your game loop, just use ccSub on each of your sprites positions.
sprite.position = ccSub(sprite.position,grav);