How do I detect which direction a UIImageview is animating? - iphone

What is the best way to detect the direction of a uiimageview?
I want to detect when a uiimageview is 'falling' - this is because it follows an arc animation for jumping purposes, i only want to detect when it is 'falling' and intersecting a floor, rather than when it jumps and intersects the floor.
I'm guessing there is no built in method to do this.
Thanks in advance!

The best thing to do, I found, was to draw a path and test it for collision with any above 'floors' or platforms. Then if it does collide, draw another path with an end point matching the y position of the collided platform.

Related

Unity 2D: Alter sprite anchor point

I've got a plain 2D Capsule Sprite. I want it to rotate around a specific point instead of its very centre. In other programs, this point is called the anchor point. For context, I'm making a paddle for my 2D pinball game so obviously the paddle needs to move when you press a button, but I can't have it moving around its very centre... Well, I could but I don't want to.
So my questions are:
Is anchor point the correct term for Unity?
Can this be altered/moved and how?
So, I ended up getting an idea from a friend who does this stuff too.
I made an empty game object. Made it the parent of my paddle. Moved the paddle to the point of the game object where I want the paddle to rotate around, and now when I rotate the game object, it rotates the paddle around the pivot point that I want it to have.
Image of paddle, arrow pointing to the empty game object
Edit: Just works using UI components within a canvas
You can use the Anchor presets of the Rect Transform. Or define the Min/Max values for x/y coordinates in Anchors Property.

What would be the logic to make a ball move within concentric circle using accelerometer in cocos2d

I want to know the best approach to make a sprite ball move within concentric circle using accelerometer in cocos2d. Ive used the equation of the circle to see if the sprite lies within the circle or not.
Find next position of your sprite according to accelerometer input, check if it lies within your area, if yes, update sprite's position.

Creating a Body - Cocos2d/Box2d

I have a ball and another sprite. When the ball collides with the sprite it simulates falling.
My only problem is the other sprite is just on big image and the ball is on top of it, but there are spaces on the sprite and a lot of corners. I need to determine if the sprite has touch one of the corners. I know this is hard to understand.
So, my question is, is it possible to make a body without
b2PolygonShape blockShape;
and
blockShapeDef.shape = &blockShape;
OR
is there an alternative I can use? I cannot set the image as a box and it would take way to long to set edges because there are so many corners.
I have already set up the collision detection.
I really need help with this.
Thanks!
If you want it to react properly, you have to make a polygon using every single corner coordinate.
But don't be lazy about it. You can use SpriteHelper for creating *b2PolygonShape*s out of your sprites.
Or another alternative: VertexHelper

Draw a straight line on the screen in Cocos2d?

I am making a game in which you shoot a ball. I want there to be a line that follows your finger when you touch the screen (showing you the path the ball will travel). It needs to be straight, and also a little side question:
Once the line is drawn, is there a way to detect if it collides with a sprite? So, if the line hits a wall, it won't go through it? Any help is appreciated, Thanks!
for drawing only a line you can use ccDrawLine function and you can change line color using glcolor4f you can also change line width using glLineWidth but iprefer to use these functions for debug purpose. it's better if you try some sprites drawing for accual game.
for collision testing I suggest you use box2D and create body(and fixture) for both line and moving sprites. you can edit fixtures you created when ball changes position.

How to fix an imageView to another and move both together?

I'm developing a game in which I have a bow and arrow. I have to move both bow and arrow imageViews on touch through different angles for which I'm applying CGAffineTransform.
The problem is this that after rotation, bow and arrow change their positions, so the arrow does not stay at the center of the bow. I want to fix this arrow at the center point of bow and move along with the bow.
I'm applying the same angles to both bow and arrow, but it seems that the bow is changing its center after transform. While detecting touch, I'm needed to provide the touch position to arrow throgh its center, so I even cant use the center property of arrow to fix it at a certain point.
Can anybody please help me? It's really urgent.
I would place both UIImageViews in a container UIView and rotate that instead. This will keep the bow and arrow together. I hope I'm understanding your requirements correctly. You can also look into the CALayer anchorPoint property which will affect which point the view is rotated around. Changing it will move the view though, so you do need to compensate for this.