Is it possible to make a laserbeam in ios spritekit that will change length depending on the angle and if there is any objects in the way? its hard to explain but check the image.
This is possible. 'Line Of Sight' type of techniques are very well explained in Sprite Kit Programming Guide: Simulating Physics chapter.
Listing 8-10 Casting a ray from the center of the scene is a code snippet that is on the right track.
Provided the objects that the laser will hit all have physics bodies then you should be able to use enumerateBodiesAlongRayStart:end:usingBlock: from SKPhysicsWorld class. Think of this method as firing an invisible ray first, so you can get the end point for the laser beam you wish to draw.
Related
So.
After many years of iOS development I said it's time to try to do a little game for myself. Now I chose to do it using Apple's SceneKit since it looks like it provides everything I need.
My problem is that I've stumbled upon a huge problem (for me) and searching on Google doesn't yeld any results.
Any idea how do I go about having an object (a sphere for that matter) that deforms itself, say, because of a gravitational force. So basically it should squash on impact with the ground.
Or, how do I go about deforming it when it collides with other spheres, like a soft beach ball would?
Any starting point along those lines would be helpful.
I can post my code here, but I'm afraid it has nothing to do with my problem since I really don't know where to start.
Thanks!
Update
After doing a bit more reading I think that what I want could be doable with Vertex Shaders. Is that a right path to follow?
For complicated animations, you'll generally be better off using a 3D modeling tool like Blender, Maya, or Cheetah3D to build the body and construct the animation. Those tools let you think at a higher level of abstraction. Then you can export that model to Collada (DAE) format and then import it into SceneKit.
https://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Basic_Animation/Bounce has a tutorial on building a deforming, bouncing ball using Blender.
SceneKit only does physics using rigid bodies. If you want something to deform, you would have to do it yourself.
It is probably because SceneKit has no way of knowing how an object should be deformed. Should it just compress, should it compress in one direction and expand in all others to preserve it's volume, should only part of the model compress and the rest stay rigid (like the tires on a car).
What you could try is wait for a collision to occur and do the following
calculate and store the velocity after the bounce
disable collision checking on the object
run an animation for the "squash"
enable collision checking on the object
apply the calculated velocity
It will be entirely up to you how real or cartoony you want to make the bounce look.
I've been trying to find the most efficient way to get per pixel collision in SpriteKit for iOS 7 (SpriteKit for iOS 8 has support for this, however). Of course I would like to use a box or circle to represent the sprites' physics bodies, but unfortunately the nature of the game demands per pixel collision.
I know I could manually draw the CGPaths around the sprites, but I'm trying to save myself some time / create a method for long term use / learn something new. Since the images for the sprites are drawn on an alpha background (png file), I was wondering if using edge detection or some other method would work to trace the non-alpha edges with a CGPath. This would happen during game initialization, and the CGPaths would be turned into physics bodies and be saved. I couldn't find much help online, though I did read that this could potentially be very tricky.
Any help is much appreciated. Thanks!
As far as I'm aware you can't trace the non alpha edges automatically, I use a tool where you drag and drop a sprite into a box and click points to represent the physics body. The tool then returns the code for the path you just defined, it makes things a little easier until iOS 8 is out.
I am a long time user of Stackoverflow but first post.
My question is seemingly simple, is there a way to make particles from an emitter interact with the physics sprites in the scene? (For example, if I am using a particle for rain, and I want it to bounce or bumpy off a sprite of a man with an umbrella. There must be a way, but I don't see a lot of documentation on adding physics to individual particles. Any ideas?
Thanks!
No. There is no way to make SpriteKit's built in particles interact with physics bodies. Every particle property you can control is a property of SKEmitterNode, and it has no properties for setting physics behavior for particles.
The fact is that particles are designed to be very light-weight so that you can have thousands of them on any hardware supported by SpriteKit. Physics simulation is not light-weight.
There is LiquidFun, which is a Box2D extension that simulate the physics of a particle system. This engine is the basis for Apple Spritekit physics engine and you can use it in your game but you have to tweek it a little bit to make it run. There are a lot of tutorials of how to use it in an ios project. I am confident that Apple will have more features added to Spritekit in the future that make the particle system respond to physics.
You could use a SKField to simulate gravity and then another field on your umbrella to repulse it.
Hi i am trying to write simple game where there is one player and some simple world like trees or some buildings, player can walk having muchine gun and shoot to world object like trees and finally destroy it, game is top-down so i don't need any gravity. Player can hit a lot of bullets and some monster in world can shoot to. SO there can be a lof of bullets in one time on the screen so i need some good tool to make colision detection. Also important is that player can't now walk on other object, like there is a monster and player and they can't exist in the same place (one shouldn't go on another). Can you recoment me some collision detection engine, mayby should I use Farser or better I should write it my self?
simillar to this http://www.youtube.com/watch?v=u8rWomjyTWI
I have one more question, i am still reading about xna since few days, and i know now that if it goes about colision detection we have pixel or square and circle, now: is there any toll or engine which can pare a texture
mappe it into a polygon and check colision?
Farseer is for physics. Use it if you need complex collision reaction. If you simply need if colission then kill player, you don't need such an engine or library.
Did you read the collision example in the App Hub right?
Link: http://create.msdn.com/en-US/education/catalog/tutorial/collision_2d_perpixel_transformed
Thats probably just enough for your purposes.
I have started my first game in corona SDK and have covered a lot but now I'm stuck to a laser functionality for the weapons , have not much idea how can I implement this . any guidance please ? I want to throw laser on fire function which have collision effect other particles.Thanks in advance.
Well that is a fairly broad question so I can only answer that on a high level. First off, look at my sample OOP framework for one way to do object oriented programming in Lua:
http://developer.anscamobile.com/code/object-oriented-sample-game-framework
Now whether you use this approach or some other technique to achieve OOP, what you want to do is create a Laser object and every time the player fires instantiate a Laser object at the weapon's position. Then in the Laser's constructor set an enterFrame listener that will move it forward a little bit every frame. By moving a little bit every frame, the laser will smoothly animate forward.
As for collision, if you are using physics in your game then you could make your lasers into physics objects to handle collisions that way. Alternatively, you can do a simple distance check with the laser against every enemy on screen; when the laser is close to an enemy that means the laser hit that enemy.