If a SKSpriteNode has a texture with alpha that's not rectangular, and no outline/border, does the touch area of the SPSpriteNode reduce to the area of only opaque pixels and ignore the completely transparent pixels?
Or is the SKSpriteNode's rectangular size, regardless of texture transparency, the touch area?
Yes and no believe it or not, touch area is based on the frame property of your node, This is the minimal visible boxed area of your sprite. So if you have a Sprite that is 32x32, but inside you have a visible circle of diameter 16, then your touch area is a 16x16 square that surrounds the circle
Related
I am able to detect images in Vuforia images and overlay 3d objects on them. But I want to draw borders around the ImageTarget.
The problem is that I can only get the center of it such as,
productTarget.transform.position
How can I get the corners of the image ? It is simply a 2D image but Vuforia doesn't have anything to help with this.
There is no way to detect coordinates of the corners, but you can manually calculate it.
This will help you to get the height and width of the image
for example: coordinates of upper left corner will be center - (width/2) - (height/2)
I recommend you just make flat border which you want, and then just resize it on tracking image, because its scale is always the same and vuforia only moves the camera.
image
border
after tracking just child border to image
after parenting
The scene background color is white.
In the scene there are two sprite nodes (SKSpriteNode) sprite 1 and sprite 2 with black borders and transparent backgrounds.
sprite 2 moves.
sprite 2 reaches sprite 1 and contacts it.
What I'm trying to do is merging the two sprite contact borders when they contact each other. With other words: I want to change the color of the contact points of both sprites into the scene background color. I tried to do this with the blendMode property. But it seems that the blendMode property works only with a node and his parent.
Does the blendMode property work only with a node and his parent? If yes, is there any way to change the colors of the contact points of two "normal sprite nodes"?
Thanks for any ideas.
EDIT:
the background color is white.
each sprite is transparent and has a border with black color.
when a sprite contacts OR is moving along the border of another sprite, the black color of all contact points of both sprite borders changes to white (that is the background color). The color of all other border points of both sprites stays black.
I put another picture with more details.
Thanks in advance.
Blend mode will only blend textures together, it will not remove that black border unless you are applying something like Xor Blending. The actual sprite would blend to the destinations frame buffer, not the parent, so whatever is below the sprite at the time of rendering it.
Blending the Sprite into the Framebuffer
The final stage of rendering is to blend the sprite’s texture into its destination framebuffer. The default behavior uses the alpha values of the texture to blend the texture with the destination pixels. However, you can use other blend modes when you want to add other special effects to a scene.
You control the sprite’s blending behavior using the blendMode property. For example, an additive blend mode is useful to combine multiple sprites together, such as for fire or lighting. Listing 2-6 shows how to change the blend mode to use an additive blend.
Source: https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Sprites/Sprites.html
To achieve what you are looking for, I wouldn't even mess with blending, instead have your sprite broken up into 2 sub sprites, the border, and the inside color.
What I mean by this is lets say you have a circle with radius 10 and a 1 pixel thick. We create a node, that has a child that is just the border with a transparent area at radius 10, and another child that has a radius of 9, which will be filled with white.
Set the borders zposition to 0
Set the inside sprites zposition to 10.
When 2 sprites merge together, here is how drawing will be rendered
Sprite 1 border
Sprite 2 border
Sprite 1 inside
Sprite 2 inside
This will give you the effect you are looking for with the sprites merged together.
Of course, if your inside has transparent and not a solid color then we have a
problem. (Right now you are saying your BG is white, so we do not need transarency, your circle cam be white, but if you want to put a texture on the BG, then we have an issue.)
If you indeed want to keep your circle "transparent", then what you need to do is capture the background underneath before the border gets drawn, and make that the texture of your inner circles
I an using GraphicsContext (gc) inside an AnimationTimer. I am scaling gc, drawing some objects, rotating gc and then drawing an image.
The image appears rotated as planned!
I need to be able to get the rotated rectangle that represents the image so I can check for proximity of the 4 (rotated) corners to other, non rotated objects.
I cannot see how to do this.
I have tried creating a rotated Rectangle to 'mirror' the objects rotation but I cannot see how to draw the Rectangle in the gc.
There is no gc.draw(Node), gc.draw(Rectangle) or gc.draw(Polygon). I need to draw it to confirm on screen that the two match.
My only other option is to break out the geometry set and rotate the points myself but it seem odd that javafx cannot do what I need.
Could somebody please help.
I need a 'mask' layer that covers the whole screen, with the center part (a circle) to be transparent. Then I can move the mask layer around using touch. User are only able to see the transparent part in the middle.
I don't think a png file can help because the file need to be very large to cover the whole screen.
So is it possible to do it by coding?
i found this online, but don't know much about openGL. http://www.cocos2d-iphone.org/forum/topic/7921.
it would be great if i can use a CCMaskLayer and input with the radius. i can handle the touch event by my self.
the attached png file is expected result, the center part is transparent. i need this to cover my screen, and only show the middle part. the red part is covered.
I write a CCMaskLayer to do the exactly same thing.
https://github.com/smilingpoplar/CCMaskLayer
You may solve this task with cropped circle texture in two ways:
1) Draw sprite with circle texture in screen center and draw another 4 sprites around (on top, bottom, left and right sides) with small red texture but scaled to cover all screen.
2) (more elegant but harder to implement) Make your mask layer fullscreen but adjust texture coordinates. In details:
set wrap mode to GL_CLAMP_TO_EDGE to your circle texture
adjust texture coordinates of your layer vertices (to do this you need to subclass base CCLayer):
Here v means vertex position and t - texture coordinates. You need to set correct texture coordinates for four corner vertices of layer. For future if you will want to drag circle you will need to add some offset values to texture coordinates.
How can I rotate a sprite around a specific point, instead of the center point?
CCSprite rotation or CCRotateTo action rotate around the center point.
I'm trying to rotate the image of a face. Rotating around the center (nose) does not look as good as rotating around a point slightly below the center (chin).
In Photoshop it's possible to change the anchor point for rotation. Can that be done in cocos2d-iphone?
The most obvious way would be to enlarge the size of your sprite.
If the height is 50px, and the current center rotation point is the middle (25px) and you want it to be at say, 30px, just enlarge the canvas of your sprite in photoshop so that the image gained 10px of transparent space at the bottom.
Hopefully this helps your problem, i've never seen an anchor point reference for rotation in cocos2d.
You should change your anchorPoint accordingly.
AnchorPoint will be the center of your ccsprite rotation, it starts from left bottom (0.0,0.0) to right top (1,1). To calculate it, get the point position relative to ccsprite, and divide by the sprite size:
//anchorPoint position
float x = myRotationPosition.x/ mySprite.width;
float y = myRotationPosition.y/ mySprite.height;
mySprite.anchorPoint = cpp(x,y);
//rotate mySprite based on new anchorPoint
mySprite.rotation = 90;
Hope that helps