2D Horror Game Flashlight - graphic-effects

I'm trying to make a 2D horror game, which some can argue are less scary than 3D horror games. To compensate, I'm trying to make everything around the character dark except for a circle around the player. How can I accomplish this with paint?
I can draw over the background with black, and make the darkness move when the player does, but how can I make the light around him circular?

Take a black image and create a transparent circle in the center. Then you just need to stick the center of the image to your character.

Related

How to make a PhysicsBody based on Alpha Values

Suppose there there is a scene as follows:
There is a scene with the same size as the frame of the device. The scene has a red ball, which is able to move throughout the 'world'. This world is defined by black and white areas, where the ball is ONLY able to move in the area that is white. Here is a picture to help explain:
Parts of the black area can be erased, as if the user is drawing with white color over the scene. This would mean that the area in which the ball can be moved is constantly changing. Now, how would one go about implementing a physicsBody for the an edge between the white and black areas?
I tried redefining the physicsBody every time it is changed, but once the shape becomes complex enough, this isn't a viable solution at all. I tried creating a two-dimensional array of 'boxes' that are invisible and specify whether most of the area within each box is white or black, and if the ball touched a box that was black, it would be pushed back. However, this required heavy rendering and iterating over the array too much. Since my original array contained boxes a little bigger than a pixel, I tried making these boxes bigger to smooth the motion a little, but this eventually caused part of the ball to be stopped by white areas and appear to be inside the black area. This was undesired, since the user could feel invisible barriers that they seemed to be hitting.
I tried searching for other methods to implement this 'destructible terrain' type scene, but the solutions that I found and tried were using other game engines. To further clarify, I am using Objective-C and Apple's SpriteKit framework; and I am not looking for a detailed class full of code, but rather some pseudo-code or implementation ideas that would lead me to a solution.
Thank you.
If your deployment target is iOS 8, this may be what you're looking for...
+ bodyWithTexture:alphaThreshold:size:
Here's a description from Apple's documentation
Creates a physics body from the contents of a texture. Only texels
that exceed a certain transparency value are included in the physics
body.
where a texel is a texture element. You will need to convert an image to the texture before creating the SKPhysicsBody.
I'm not sure if it will allow for a hole in the middle like your drawing. If not, I suspect you can connect two physics bodies, a left half and a right half, to form the hole.

Static circle rotates when I move kinematic rectangle in Box2d

I am writing 2d scroller with Box2D in Xcode. Scrolling is organized by moving kinematic bodies (which all together make ground). Kinematic bodies are moved with setlinearvelocity function.
When dynamic body falls on this ground and stops near the wall it starts to rotate.
Here is an image:
Black circle is dynamic, blue blocks are movable kinematic bodies. When circle falls in such pit it starts to rotate. If I stop moving blue ground it does not.
How can I change this?
Stop moving the ground and move The ball instead. I don't see the reason why you are moving the whole terrain instead of only moving a ball. Making the terrain a static body will make the physics simulation more efficient too.

Cocos2d - Move sprite in curved path

I am creating a Catapult game in Cocos2d in which the catapult is at the bottom center of the screen and we throw stones on the objects falling from the top of the screen. I tried using Bezier curves for this purpose but problem is that I am not able to calculate control points for drawing bezier curve. I need to move sprite of the stone on a curved path when released from the catapult.
Can anyone please guide me how can I achieve it?
Thanks and Best Regards
why you don't use physics for that?
use box2D is integrate with cocos2D, config the world, gravity, and physics budies,so.. the effect of catapult is automatic when you shot a bullet.

how to make a circular line of sight in cocos2d tile map

I have a problem about cocos2d tile maps.
My aim is to make a circular line of sight that when player moves around, it must only see its around in circle but not see the rest. I have tried many things and successed it in rectangular area but I couldn't succeed it in circular area.
I am waiting for your answers.
Thanks for your help.
If you help me immidiately, I will appreciate.
Use rectangular area and add an alpha mask with round gradient as a child of the player to make the visible part round.
E.g.
with fading
without fading
Edit.
The green layer is the fog. Only a square of it is uncovered ("I have tried many things and successed it in rectangular area"). The red layer is the circular vision map. It covers some of the visible squares and so the user sees uncovered circle.

App graphic making (transparent and no extra spaces)

I am a coder but not a graphic maker. I can decently produce graphics that meet the quality standards visually although I cannot produce graphics that will technically "work." This is what I mean:
I am using CGRectIntersectsRect for colliding images. My image has SOME extra space which I have made completely transparent using Adobe PhotoShop but even if this extra transparent space is not visible, when the two images collide, it will look like you will be hitting nothing as this extra invisible transparent space is PART of the image and when CGRectIntersectsRect is called it detects touch between two images. So if the other image touches the transparent space, CGRectIntersectsRect is called and my code is executed. I only want my code to be executed if it hits the actual COLOR space of the image. Here is two things that could help me through that, they follow through with questions.
Learn how to make NO EXTRA SPACE on an image in photoshop. How could I do this, tutorials?
CGRectIntersectsRect only called when touching a color part of an image. A way to do this?
Thank you guys!
Regarding your question #1, it depends. All images are rectangular, all. So, if your sprite is rectangular, you can crop it in Photoshop to just the rectangular area. But if you want to handle, say, a circle ball, then you can't do such thing as "remove extra space". Your circle ball will always be stored in a rectangular image, with transparent space on the corners.
Learn how to make NO EXTRA SPACE on an image in photoshop. How could I do this, tutorials?
You can manually select an area using the Rectangular Marquee Tool and Image > Crop or automatically trim the image based on an edge pixel color using Image > Trim.
CGRectIntersectsRect only called when touching a color part of an image. A way to do this?
You can use pixel-perfect collisions or create better bounding shapes for your game objects. For example, instead of using pixel-perfect collision for a spaceship like this one, you could use a triangle for the wings, a rectangle for the body, and a triangle for the head.
Pixel-perfect collision
One way you could implement it would be to
Have an blank image in memory.
Draw visible pixels from one image in blue (#0000ff).
Draw visible pixels from the other image in red (#ff0000).
If there's any purple pixels in the image (#ff00ff), then there's an intersection.
Alternative collision detection solution
If your game is physics-based, then you can use a physics engine like Box2D. You can use circles, rectangles, and polygons to represent all of your game objects and it'll give you accurate results without unnecessary overhead.
For collision detection for non-rectangular shapes, you should look into one of the many game and/or physics libraries available for iOS. Cocos2d coupled with Box2d or chipmunk are popular choices.
If you want to do it yourself, you'll need to start with something like a custom CGPath tracing the actual shape of each object, then use a function like CGPathContainsPoint (that's from memory, it may be wrong). But it is not a simple job. Angry birds uses box2d, AFAIK.