Is it possible to test intersections with 2 sprites in XNA using the sprites' alpha channels to determine if alpha > 0 with an intersection there is a collision but if alpha is 0 even if there is an intersection there's no collision.
I know j2me supports it at least...
Try the 2D Per-Pixel Collision sample.
Related
Example of goal:
I see three.js has this example.
It's simply a 3D Cube with many Spheres on its surface.
How can I do something like this using SceneKit?
You could use an array of points, on planes, and place spheres at those locations.
Each plane divide by 10 in both directions (X and Y) and then make six of these planes and rotate them into the cube face positions.
I think performance is probably going to suck, though. This is a lot of polygons, for each of these spheres. Let's imagine each sphere has 200 tris. That's 100x 6x 200 = 1.2 million triangles.
Probably better to use circular textures on quads, placed facing the camera, at each of these 600 points. Then it's only 1200 triangles.
Cheats way to do this:
Create a SCNBox with the number of vertices desired in x, y & z axis.
Then use it as a particle emitter shape, and assign emittance to each vertex at a rate that makes them always appear at these locations, using a small circle texture, and the "look at camera" mode of placard presentation.
here is that cheat, done with particles:
i have a question about achieving an effect like on a lunar eclipse. The effect should look like in the first seconds of this gif. So just like a black shadow which goes over the circle. The ideal situation would be a function where i can passed a parameter in percentage to get this amount as a shadow on the circle:
The problem which i am facing is that my background is an gradient. So it's not possible to have a black circle which moves over the moon to get the effect.
I tried something with CCClippingNode but it looks not nice. Furthermore the clip on the edges was always a bit pixelated.
I thought about using something like a GLSL Shader to achieve the effect but i am not so familiar with GLSL and i can't find an example.
The effect is for an app game developed for an iphone. I use the cocos2d framework in version 3 (the current one).
Has somebody an idea how to get this effect? An idea where i can start to search?
Thank you in advance
The physics behind is simple you change the light shining on the moon. So
I would create a 1D gradient texture representing the lighting conditions
compute each rendered pixel of moon
you obviously have the 2D texture of moon. So you now need to obtain the position of each pixel inside the 1D lighting texture. So if moon is fully visible you are in sunlight. When partially eclipsed then you are in the umbra region. And finaly while total eclipse you are in penumbra region. so just compute the middle point's of the moon position. And for the rest use relative position in the moons motion direction.
So now just multiply the Moon surface with the lighting texture and render the output.
when working you can add the curvature correction
Now you got linerly cutted Moon phases but the real phases are curved as the lighting conditions differs also with radial distance from motion direction and moons center. To fix this you can do
convert the lighting to 2D texture
or shift the texture coordinate by some curvature dependent on the radial distance
I've been making progress in a fan-replicated game I'm coding, but I'm stuck with this problem.
Right now I'm drawing a texture pixel by pixel on the curve path, but this cuts down frames per second from 4000 to 50 on curves with long lengths.
I need to store pixel by pixel Vector2 + length data anyway, so I can produce static speed movement along it, looping through it to draw the curve as well.
Curves I need to be able to draw are Bezier, Circular and Catmull.
Any ideas of how to make it more efficient?
Maybe I have misunderstood the question but I did this once:
Create the curve and sample x points on it. (Red dots)
Create a mesh from it by calculating the cross vector of each point. (Green lines)
Build a quad between all of these. So basically 5 of them in my picture.
Set the U coordinate to be on the perpendicular plane and V coordinate follows the curve length. So 0 at the start an 1 at the end of it.
You can of course scale V if you want you texture to repeat.
Any ideas of how to make it more efficient?
Assuming the texture needs to be dynamic, draw the texture on the GPU-side using a shader. Drawing it on the CPU-side is not only slow, but bogs down both the CPU and GPU when you need to send it back to the GPU every frame. Much better to draw it GPU-side.
I need to store pixel by pixel Vector2 + length data anyway
The shader can store additional information into the texture. e.g. even though you may allocate a RGBA texture, it doesn't mean that it needs to store color information when it is your shaders that will interpret the data.
My character is represented by an UIImageView with that is 30 by 30 points. The enemy is another image view that is 240 points wide and 45 points tall. It appease that CGRectIntersectsRect only determines a collision between the two rectangular boxes. But I'm looking for something with more detail.
I'm not using SpriteKit or Cocos2d or Box2d or chipmunk. Is there anything better than CGRectIntersectsRect for corner collision detection and collision detection from the left and right sides and how do I program it?
I can't seem to tell if I should be factoring in the Origin of the drawn texture when making a rectangle to do collision (intersects) detection. Most of the examples I have seen make the Origin X/2, Y/2 when drawing but then they do not do anything special when creating a rectangle of the location for detecting collision. I am experimenting with it but have not come to any concrete conclusion especially for small objects. Thanks for looking!
From my own experience, the origin of the quad factors in when considering linear transformations such as scaling and rotation. This can have a direct implication on the bounding square that you generate from the quad as it will effect the bounding square transformations also.
It is important to ensure that they both align so that one transformation maps correctly from one square to the other. So what I would do is ensure that the origin of the bounding square maps to the quad.
Personally, I just use the quads bounding space calculated from the center of the quad and test for AABB collision within those confines. Obviously you need to devise the confines based on how large the object is from the center.