How do I create an outline for my SKSpriteNode around the png texture in swift? - swift

I am making a game in Swift(SpriteKit) and when the character in the game picks up a power-up, I want him to get an outline in purple so the player can see that his power-up is ready to use. I want the outline to hug all the curves of the player exactly. Is there any way to draw an outline around a sprite node that isn't a basic shape(like circle or square) but to outline a complex shape?
Here is an example of a shape similar to my sprite node:
And here is another example of the player with the visual outline that I want to add in SpriteKit(I just sketched it but I want it to be exact obviously):
They player also has his legs animating by flipping through an atlas of the animation, and preferably the outline would stay around the legs when the walking animation is happening. Is this possible?
To be clear, I just want an outline for visual purposes, so the player knows their "power up" shield is active so if they get hit it won't damage them.

I haven't dabbled with SpriteKit for a few years, and if memory serves me correctly perfect collision detection while animating is not available out of the box.
After checking the documentation I see that SKPhysicsBody has a init(texture:size:) initializer. This should at least get you a bit closer.
This guide from Apple is probably worth a read. (Pixel perfect collision detection is expensive).

Related

unity3d: Adding half-transparent video with shadows

I'm struggling with an issue that might seem a little bit awkward.
I have some black & white 2d animation (1440x1080px) that I'd like to be played in in a 3d environment in unity3d. Therefor I added a video player to a plane. Now comes the tricky part: I want to make the black areas of the video transparent while the white areas remain visible AND the white areas shall cast shadows on the surrounding. Using the particles shader "additive" does half of the job. But I just can't manage to let the video cast a shadow.
If it worked you would get some 2d "antagonist" (you can't interact with) that looks kind of 3d. Alternatively you could interprete it as some half materialzed holograph that casts shadows.
Is there any (simple) solution I just don't know?
Here some schematic drawing of what I would like to achieve, for better understanding.
The problem right now is: In contrast to my drawing, the desired shadow on the wall doesn't appear... :-/
So, I did never try this but you can maybe add a light in the scene just in front of the video player, that way the light will cast shadows.

swift physicsbody is not matching up to image size

I have two nodes, player and platfrom. Both have a physicsBody around them. My player is still and the platform scroll by an SkAction. when the player reaches about half-way on top of the platform it falls threw it.
player.physicsBody=SKPhysicsBody(rectangleOf:player.frame.size)
player.physicsBody?.isDynamic=true
player.physicsBody?.allowsRotation=false
player.physicsBody?.affectedByGravity=true
platform.physicsBody=SKPhysicsBody(rectangleOf:platfrom.frame.size)
platform.physicsBody?.isDynamic=false
the platfrom set up is.
plat.size=CGSize(width:(self.frame.width)*2,height:(self.frame.height)/3)
plat.anchorPoint=CGPoint(x:0,y:0)
plat.position=CGPoint(x:0,y:0)
plat.zPosition = 2
addChild(platform)
I tried using this instead but player still falls down
plat.physicsBody=SKPhysicsBody(rectangleOf:CGSize(width:platform.width,
height: platform.frame.height))
I want the nodes to act like a solid object, in that they don't overlap each other when the player moves. Also it there an alternative method I can use. I don't really like working with physics.
An alternate to working with physics is to use the recently added to iOS 10 SKTilemapNode to create the background. Each tile can be tagged with data to indicate if the tile is ground or not. You then focus on how the player moves relative to the tiles. There are currently not a lot of examples to show this working, the WWDC 2016: What's new in SpriteKit shows this briefly. Other resources include a top down example which shows at least how to build the background tilemap and some background info on why physics engines don't provide the best experience for platformers. Kenney's is a good source of tiles for platformer artwork.

Unity 3d - Explosion Area Damage

I've developed an airplane 3D shooter game. In this game, I want to make my plane shot a bomb. When the bomb gets to the enemies it will explode and give damage in the area of explosion.
I have already searched for a tutorial to make this code and the animation of explosion. But I couldn't find it. Please tell me about something that could solve this problem. I'm developing my game using C#.
For the explosion animation, you could use a particle system. There are many pre-made ones in the Asset Store, such as this one: https://www.assetstore.unity3d.com/en/#!/content/42285
For detecting what is affected in the explosion's area of effect, do a SphereCast (https://docs.unity3d.com/ScriptReference/Physics.SphereCast.html) from the point of impact and then do whatever you want with any of the objects touched by the sphere.

Side scroller style scene with gravity

I've started learning sprite kit and I think I've got the basics but now I'm struggling with something.
I want to create a game that has a 'Streets of rage' type feel to it whereby the user can move up and down, but isn't jumping, they're still on a 2D plane. But I also want them to be effected by gravity e.g stairs etc. like the following picture.
Am I right in assuming that I should have my background image with colliders around the blue and brown edges, and then create a physicsbody collider located at the feet of my player/players so that it looks like they can move against the background, but when their feet reach the top it would stop?
Could I then place other obstacles like rocks etc on that path that they would be able to collide into, but that could also sit over the path and the sky? How would I handle the fact that these could be constantly colliding depending on the position?
I appreciate there isn't any code here, but I'm trying to understand the concept around this before I jump in coding a solution.
Thanks
I would use a categoryBitMask to separate the different planes of objects.
And I would play with collisionBitMask/contactTestBitMask depending from the plane the player is in, in addition to the z-order.
Thus you can have a rock that collides your player if they are both in the same line else the player would walk behind/front.

Cocos2d - Creating collidable Sprites?

Hello everyone I an very new to cocos2d, so I apologize if this is a simple question. I would like to create to sprites that collide when they hit each other.
For instance, one sprite, spriteA, is in a fixed position on the screen. And another sprite, spriteB, is moving around the screen. SpriteB will collide with spriteA. If that doesn't make sense or you don't understand it, tell me and I will elaborate further. Any help is appreciated. Thank YOU!
Try using Chipmunk or Box2d physics systems. These are included with Cocos2d and work by having a physics simulation that updates with every time the graphics change on screen.
The physics simulation will tell you if two objects are overlapping, and will provide physical attributes like weight, slipperiness (friction), speed and direction, which creates reactions like bouncing, sliding, realistic loss of speed and changes of direction on impact.
If you are new to physics simulation, here's a 30 second run down:
Create "bodies" in the physics simulation that represent each graphical sprite
Bodies are usually defined more simply than their graphical counterparts, like a circle, square or simple polygon shape
In order to update the graphics on the screen accurately, first you establish a pixels to meters ratio. Meters are notional (i.e. made up) measurement that is used in the physics sim
Each time the physics simulation "ticks", you update the graphics on screen accordingly
So if a body in the physics sim moves 1 meter, you might transform the pixel sprite 32 pixels
Here's a good tute on collision detection using Box2d.
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
enjoy
Its actually very simple:
Just schedule a timer: [self schedule:#selector(checkForCollision:)];
Specify the method: - (void)checkForCollision:(ccTime)dt {}
In the curly braces, make CGRects for each sprite using CGRectMake.
Then in the same method, just call: if (CGRectIntersectsRect) {}
That easy!
Well technically speaking when the 2 sprites interact, or share at least one common point, then they are colliding. I'm a little confused by your question. Are you asking for direction on how to make the sprite move on screen, or are you asking how to handle the actual collision(such as calling a method if they collide)?