Swift SKCropNode can someone explain this behavior? - swift

I have a grid of 16 SKCropNode objects. Each contains a SKShapeNode used as a mask, and a SKSpriteNoe. In this image with the mask not set you can see all 16 object appear in a grid.
https://github.com/soggybag/Grid
Interaction is strange also. Tapping makes the image sprite move down and disappear moving out of the mask. You can tap the area below the orange, where a sprite would be hidden, and it recognizes the tap event.
Even stranger you not tap the sprite in the upper right?

Related

How do I make my UI text centered to my 2d object when changing resolutions in Unity?

I have a 2d circle in the scene, and a text inside it that I want to always be in the middle of the circle when I am changing resolutions.
For better understanding, it's just like a replica game.
You can create a circle including a text box. Make the text box child object of your circle and add HorizontalLayoutGroup to your circle
Tick all of its properties.

How to have different functions execute when tapped at different parts of the View?

I have a view (Circles) that displays a group of circles at different coordinates. I have loaded the coordinates of the circles through a single parse query. I am able to add a tap gesture recognizer that executes a function when the view (Circles) is tapped.
(E.g. If i tap on one of the circles, all the circles change from color blue to red)
However, I am having trouble figuring out how to have different functions execute depending on the circle (different coordinates) I tap on, rather than having a function execute in unison whenever any circle is tapped.
(E.g. If I tap on the circle at the top-left corner, it turns blue to green, while if I tap on the circle at the bottom-left corner it turns from blue to red)
I am thinking of having a system that does a function if the tapped coordinate is x and y and so on. However, I do not know how to go about it as of yet and would appreciate any help I can get.
The easy (and elegant) way to do this is to make each circle its own view, and give each one its own tap gesture handler. However, if you want to keep your current approach, draw each circle as a UIBezierPath, which has a containsPoint() method that you can use for hit testing.

Transformation Sprite with finger move

I am making an Drawing App in someway like Paint in Windows
I have a toolbar with many shapes button such as Rectangle, Circle, Triangle, etc. When tap a button i add a sprite with shape with button's name.
I want to add functions like this
- When tap on shape it show four 4 points each corner of shape that i can touch and drag to skew or scale.
Same as we do with an image in photoshop or MSWord
anyone have sample code or tutorial ?
Use this code for your app.
Paint
Drawing
Drawing2

ios game make a mask layer effect

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 to handle exact UITouch of image?

I have an image for example triangle and place it inside UIImageView, and I have a touch and drag application, I can already drag the triangle but my problem is I can still drag the triangle even if I'm not actually touching the triangle, (Im touching the upper left of the triangle image) I think this is because the UIImageView itself is a square so although I have not touch the triangle image but I have touch the square UIImageView that's why I can still drag it w/o touching the triangle,
So the question would be how can I make this accurate, like I can only drag it if I have touch the triangle image and not really the square ImageView?
Hopeful for all your help.
Instead of using UIButton, try using CGPath and testing for CGPathContainsPoint.
Also, try LaMarche's Improved Irregular UIButton.
Otherwise, you could use some trigonometry to determine where the touch occurred and whether or not it is within your internal shape.