Touches in Cocos2d + Box2d - Iphone Game Development - iphone

I have a problem with touches on the iPhone5.
The problem lies within the method below:
- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Here I do something
}
Here is the image - http://postimg.org/image/qrokz07g1/
Touches work only in green area. In the red area, it doesn't work.
Does anyone have a solution?

Yes, you should add Default-568h#2x.png image (along with the default launcher images) to your project in order to enable the iphone 5 resolution support. Otherwise your screen will be treated by cocos2d like standard iphone 4 screen centered on your iphone 5 screen (and the red sections of course will be ignored).

Related

iOS 9, Xcode 7, Multitouch with SpriteKit

Hello I've made an iOS game named 'Racing Horses' and published it to App Store. It was fine with playing on iOS 8.x.x, but after I installed iOS 9 Beta 3, in the same game (same codes), iPhone cannot recognize multiple touches. I have to leave my finger to make the next touch. But it was not like this, I could make a new tap even if I still hold my previous tap. What is the problem, what should I do?
I had the same problem on a game launched this summer.
I had to explicitly enable multiple touch in the SKScene:
-(void)didMoveToView:(SKView *)view {
self.view.multipleTouchEnabled = YES;
}
Here's more detail -
The game uses sub-classes of SKSpriteNode.
They test for number of touches depending on the the sprite.
In the sub-class:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(#"TapCount = %lu", (unsigned long)touches.count);
if (touches.count == 2) {
// do something
}
}
It looks like as of ios 9 multitouch has to be explicitly enabled. I don't think this used to be the case. I now have this issue on all my spritekit apps. Just adding self.view.multipleTouchEnabled = YES; in viewDidLoad, fixes it for me.
Just a simple mistake, I've enabled multitouch at interface builder, problem solved. But I don't know how it turned off by itself :)

How to make certain part of image clickable in ios?

In one of my app i am using image for the whole screen. Which can be zoomed to some extent. That image has eight different shapes(includes person,shapes,etc).What i am trying to do is i need to make certain each shape of the image is clickable. Touching each part takes to different screens.I didn't have any idea about how to achieve this. I googled it but no solution.
1.) Is this possible by using co-ordinates(will normal image and zoomed image differ in co-ordinates? How to achieve this by using co-ordinates?
2.) If not what will be the best approach to achieve my goal?
Any ideas/samples is much appreciated.
I would add a UITapGestureRecognizer to the imageView holding your image. And the locationOfTouch:inView: method to determine the coordinates of your touch.
Correct me if i don't understand your question. For me, that should be very simple? Just have couple of buttons which background is clear? And They are all on top of the image.
Check UIResponder and the touches methods in there. You'll probably want to hook in to something like -touchesEnded:withEvent: for detecting when a finger lifts off the screen.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGRect touchLocationInView = [touch locationInView:imageView];
// Do something to check that the rect is valid
// If valid, react to it
}
}
Also, a link to UITouch.

how to get touch coordinates in an image then draw a markup icon and its content in a popover view

I would like to built an iPhone/iPad application to show large images (in a scrollView or something else which support dragging and zooming) that allow user to:
Touch some where in the image to markup and leave comment
User can tap on that markup icon/button to view comment in a popOverView
Edit comment or remove that markup
So I want to ask that:
How can I get the touch coordinates in image (not screen)?
How can I draw a markup icon/button at touch point in the image and it would follow image even when dragging, zooming since the image is really large, maybe up to 8000x6000 pixels?
How can I display comment/note when user touch on markup icon/button in a view like popOverview in iPad?
Save and load these information.
It is nearly similar to tagging functionality of Facebook App in iPhone.
Any help is appreciated, thank in advance!
1 . You subclass the UIImageView and override the touch methods:
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
2 . You add and UIButton to the UIImageView [yourImageView addSubview:yourButton]; then set the center of your button to touch coordinates.
3 . Just present an popover when user taps on an button. (You can set tag property for buttons to know which button is tapped)
4 . Save data to an plist to documents directory if is not to complex ore use core data.
Good Luck. Just post comments if you need more help.
Edit:
you need to set the user userInteractionEnabled to YES for the UIImageView.
userInteractionEnabled A Boolean value that determines whether user
events are ignored and removed from
the event queue.
#property(nonatomic,
getter=isUserInteractionEnabled) BOOL
userInteractionEnabled Discussion This
property is inherited from the UIView
parent class. This class changes the
default value of this property to NO.
Availability Available in iOS 2.0 and
later. Declared In UIImageView.h
From UIImageView Class Reference

reliable way to get iPhone touch input?

I started using the MoveMe sample to get touch input working.
basically, I define these two callback functions to get my touch input:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for ( UITouch* touch in touches )
{
printf("touch down");
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for ( UITouch* touch in touches )
{
printf("touch up");
}
}
This works fine, until you have more than 5 touches on the screen at once. then it stops working properly, you won't get the "touch down" message if there are more than 5 touches on the screen. what is even worse is that you won't reliably get all of the "touch up" messages until you have removed ALL your fingers from the screen.
If you touch with 6 fingers, then release 3, then touch again with the other 3 still down, you will get the "touch down" but if you release it, some times you get the "touch up" sometimes you don't.
This pretty much makes it impossible to track touches, and usually results in a touch getting 'stuck' permanently down, when passed to my Touch Manager.
Are there some better apis to use to get touch input? is there at very least a function you can call to reliably get whether the screen is currently touched or not? that way I could reset my manager when all fingers are released.
EDIT:
right, there must be something I'm missing. because currently the calculator does something I cannot do with those callbacks.
it only accepts one touch at a time, if there is more than one touch on the screen it "cancels" all touches, but it must keep track of them to know that there is "more than one" touch on the screen.
if I touch the screen the button goes down, now if I add another touch to the screen, the button releases, cool, not allowed more than one touch. now, if I add 4 more fingers to the screen, for a total of 6, the screen should break, and when I release those 6 fingers, the app shouldn't get any of the "up" callbacks. yet when I release all of them and touch again, the button depresses, so it knows I released all those fingers!! how??
The problem you have is that the iPhone and iPod touch only support up to five touches at the same time (being fingers still touching the screen). This is probably a hardware limit.
(As St3fan told you already.)
The system will cancel all touches if there are more than 5 at the same time:
touchesCancelled:withEvent:
(This is probably what causes the odd behavior with only some touches calling touchesEnded:withEvent:)
If you want to know if a touch ended and it ended because it was lifted then make sure to check the UITouch's phase property.
It stops working because 5 is the max amount of touches that the iPhone and iPod currently support. No way around that I'm afraid.

How to code zooming and panning for a UIImageView?

I have a UIImageView object, attached to a controller. It displays fine. What is a easy way to get zooming and panning with the least amount of code? Perhaps some library out there that does this? Hard to believe the SDK does not provide anything.
Add your UIImageView as a subview of a UIScrollView and make sure you change the minimumZoomScale or maximumZoomScale.
Also take a look at the documentation for UIScrollView there might be other settings you want to tweak.
UIScrollView is the SDK class you're looking for
The Three20 project has a photo viewer you may want to look into, that I believe supports zooming and panning in a larger image.
try using
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
Here is some code
http://www.redcodelabs.com/2009/09/objective-c-zoom-image/