In my SpriteKit game i move several sprites using [sprite.physicsBody applyImpulse:vector]; but at a specific point i the game i want them to stop.
I already tried to apply the exact opposite impulse.. but that did not worked very well.
Thanks
You can directly set a physicsBody's velocity via the velocity property. Stop a body by setting it's velocity to (0,0):
sprite.physicsBody.velocity = CGVectorMake(0,0);
Related
I am using SpriteBuilder with Cocos2d v3.4
I need to detect touch on sprite ignoring touch in transparent place of CCSprite's bounding box.
I found few solutions (Physics Body, CGPath), but actually detecting transparent pixel seems the best solution.
I tried to use THIS but it is very old solution and not working anymore.
Could someone help me how to achieve this?
Try to create 2 CGRect on the sprite and detect touch only on these rects
I want to be able to move a node from Point A to Point B by following through a custom bezier path by using applyImpulse method of SKPhysicsBody. The reason I want to use the applyImpulse is because it simulates a nice natural movement (starting fast and slowing down) depending on the initial impulse. It seems that when an object is applied impulse via applyImpulse, it only stops when the friction with environment causes its speed to reduce to zero. I want it to follow my path and stop at the end. How could I go about it?
like LearnCocos2D said, an object following a path isn't currently interacting with applied physics until it's done following said path.
Every SKAction has a property that can be set called timingMode.
so if you instantiate your SKAction on one line, on the next line you can say:
action.timingMode = SKActionTimingEaseOut;
which will start fast and slow down over the course of the action, scaling such that it still completes the movement over the specified duration.
As the posters indicated below, it was not possible to make my object move on custom bezier path after applyImpulse. I used the customActionWithDuration method of SKAction and a custom easing function from https://github.com/warrenm/AHEasing
The effect I wanted is not same or similar to applyImpulse but being able to define my own custom easing function helped a lot.
I have a queston about movment of object in app (game) I am creating. I tried move ImageView with timer. So every 0.01 second object move for 1px. But movement is not smooth. So i also tried with animations. But there is problem, that if I close app and run it again (app was stil opened in background), there are problems, that picture of View stays on the end of animation. And also I want to check every 0.01 second if moving object and my character did colide, so animation is not the best option. Is there a way to move my object smooth with local time on phone? Or there is some other way to move object?
It sounds like you're not using SpriteKit or any game engine for that matter. Any game engine will come with an update loop that does all of this.
You can learn about SpriteKit here... http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners
I have a spritenode with a physics body that is affected by gravity and dynamic, however, when it hits things it rotates.
I am only using the physicsbody for the Y axis gravity, and nothing else. When it hits something horizontally, I don't want it to be affected by that thing..
How can I accomplish this?
Straight from the Sprite kit programming guide:
The allowsRotation property determines whether forces can impart angular velocity on the body.
Am using three.js
How can I control the rendering order? Let's say I have three plane geometries, and want to render them in a specific order regardless of their spatial position.
thanks
You can set
renderer.sortObjects = false;
and the objects will be rendered in the order they were added to the scene.
Alternatively, you can leave sortObjects as true, the default, and specify for each object a value for object.renderOrder.
For more detail, see Transparent objects in Threejs
Another thing you can do is use the approach described here: How to change the zOrder of object with Threejs?
three.js r.71
for threejs r70 and higher is renderDepth removed.
Using object.renderDepth worked in my case. I had a glass case and bubbles inside that were transparent. The bubbles were getting lost at certain angles.
So, setting their renderDepth to a high number and playing with other elements depths in the scene fixed the issue. Hooking up a dat.gui control to the renderDepth property made it very easy to tweak what needed to be at what depth to make the scene work.
So, in my fishScene, I have gravel, tank and bubbles. I hooked up the gravel mesh with a dat.gui control and with in a few seconds, I had the depth I needed.
this.gui.add(this.fishScene.gravel, "renderDepth", 0, 200);
i had a bunch of objects which was cloned from a for loop in random position x and y... and obj.z ++, so they would line up in line.. including obj.renderOrder ++; in the loop solved my issue.