I have a sprite hanging from a rope in SpriteKit. I have the rope pinned to an object I'd like to slide back and fourth (to simulate the rope being attached to a track or conveyor belt). Imagine clothes hanging on the revolving rack of a dry cleaners store. Similar to that!
Anyway, I can't figure out the proper way to move my rope as if it its connected to the track.
Pinning the rope to another (track) object and moving that track object doesn't seem to work. I can't apply move actions to a sprite that has physics (without the simulation getting all messed up).
I've also tried adjusting the track objects velocity directly to (2,0) in the update method (Including all the other update callbacks SpriteKit surfaces). The only problem is the weight of the rope and attached object eventually pull the track object down. I think this happens because didSimulatePhysics happens no matter what.
Any suggestions on how to move my sprite on a rope along a track?
Thanks in advance!
Related
i'm new in the development of swift ios game using spirtekit and i need help. I want to develop a vertical 2d endless run, where with a swipe you are able to move the player in direction and if there is an obstacle, it is created in a position calculate with the position of the player. Once create the obstacle i would like to make it falling down but alway with the same relation with the player (this means that it has to move only on y axis).
Can you suggest me some ideas on how to manage this?
This book teaches you exactly how to make what you are looking for:
https://www.amazon.com/Getting-Started-SpriteKit-Jorge-Jordan-ebook/dp/B01891X7TM
This is the end product:
https://itunes.apple.com/lr/app/inside-the-hat/id1076967804?mt=8
You can get it for free here (with trial):
https://www.packtpub.com/application-development/getting-started-spritekit
The source code for this is around somewhere on the web, but I forgot where :( I bought the book a year ago and can't find it now.
Basically, you have a long background that is .moveTo .. in .update you check the position of the background, then reset it based on its XY position (it basically just goes all the way down, warps to the top position, then falls)
Also in .update you check for score, or a timer, or just a random check, then spawn an enemy, obstacle, etc. You give the enemy / obstacle SKActions to move towards the player, and let .didBegin(contact:) handle scoring, sound effects, death, etc.
I am making a Sprite Kit game where the player (basically a stickman) has a running animation and a parallax scrolling background.
Now I have enemies that come near my player. To destroy these enemies sometimes I have to touch the enemies node to launch a rocket or attack them with an attack button or just jump over them.
Everything is working fine, but I want to add some extra moves to destroy them. I want some enemies that you can just destroy if you have drawn a whole circle around them. So imagine they come and you make a circle and then my player launch a laser or something. The problem is I have no idea where to start.
I haven't found anything on the internet. If it's too complicated or almost impossible how about touching my player node and dragging to the enemy?
EDIT: I think I have to create a custom GestureRecognizer that recognizes if a circle is drawn around a sprite and then runs the code. I don't know how this works ?
Yes, it's too complex. Not just from a coding point of view, but also from that of the player's experience.
Anything that requires complex gestures over a large amount of glass is annoying for the player because they're never going to have the same experience. Their finger's moisture and oil content always changes, as does the ambient temperature and cleanliness of their screen.
So big gestures required to be performed quickly (a gaming input like this) will sometimes be fun and smooth, and other times degrade as an experience based on the nature of the above properties.
Best to avoid them for a game's best possible experience.
If you must do it, there's two ways to research how.
Seek out "custom gesture" creation and utilisation through documentation and google, etc.
Think about using some kind of array to store all the points where the player's finger moves through during that circle gesture and attempt to discern if an enemy is within that space and then act accordingly.
--- probably other ways, too. But these jump to mind.
I am trying to make a game with SpriteKit where the main character shoots a 'rope' and swings through the level (Think spiderman-ish). I have no problem making the rope and having it attached to the player and different sprites but I don't really know how to go about the 'shooting' part.
My current rope is built similar to this (https://www.youtube.com/watch?v=7jWdcbmnmKQ&hd=1) where I have several separate parts connected using SKPhysicsJointPin. I have tried several different approaches to shoot the rope, both with applyImpulse/Force and SKActions, but none works smoothly.
To sum it up:
- What is best practice for creating a rope that can extend in a specific direction?
I'm fine with just general pointers in the right direction since this is all to learn and I don't think I really need completed code for it.
General pointer:
Shoot a physics body in the way you need it to "fly" (the bullet)
In didSimulatePhysics assign the bullet's position to the rope's first node
In theory this should extend the rope while shooting, without affecting the trajectory of the bullet.
You may need to add more rope segments as the distance between the bullet and the weapon/player increases, otherwise the rope may be huddled too tightly together at the start of the bullet's flight path, causing physics to behave unexpectedly. Though adding rope segments in-flight may cause issues in its own right.
One solution could be to disable physics for the rope until a certain distance has been reached or the bullet "hit" something. Until then the rope could be considered a straight line and rope segment nodes positioned accordingly along a straight line between bullet and weapon.
Instead of using the physics engine to move your extending rope (applyImpulse), try moving the rope's end in a straight line at a fixed speed until it hits a target. Just a thought!
I'm designing a game and in my game, rockets are launched. I've created an emitter, gotten it configured, and when my rocket is launched, it adds the emitter to the rocket. Problem is, the rocket is moving pretty fast and it appears that the particles follow the motion of the rocket - what I mean by that is, instead of the rocket leaving a "trail" of smoke behind it, the "smoke" looks the same as if the rocket weren't moving, I guess because it is a child of the rocket.
The only workaround I've thought to my problem is to:
-Create an ivar or property to hold the current position of the rocket and update this every frame
-When rocket is launched, add child of emitter to the scene, not to the rocket
-place it's position at the position of the rocket
-on update, follow the rocket
However, this seems extremely computationally expensive, to be checking to see if a rocket exists, getting it's position if it does, creating a new CGPoint for this position, and set the emitter position to this new point on every single frame. Also, it leaves very few options for having more than one rocket on the screen at the same time.
Any other, more elegant solutions?
You need to set the targetNode property of your emitter to the SKNode or SKScene that you want the smoke to stay on. That property sets the node that the emitter particles will be children of, that way when the rocket moves, the emitted particles stay in the same place.
NOTE: The emitter itself should still be a child of the rocket.
SKEmitterNode.targetNode docs
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.