Tutorial details

Image collisions with actions | App Code for Sale | Preview

Image collisions with actions | iOS Tutorial

How to set actions when 2 images colide

Overview PAGE TOP

Reference: http://www.geekylemon.com/WEBPROTECT-xcodetutorialimageco.htm

In this tutorial i will be showing you how to set actions when 2 images colide


  • 2 UIImageView
  • 1 Button
  • 1 Label

How this is work simply creating two images making one of them draggable and when they collide or touch it performs an action in which this tutorial switches views its a great base for a simple game in which you have to dodge images to get to the next level

ViewController.h PAGE TOP

@interface ViewController :UIViewController {
IBOutlet UIImageView *image1;
     IBOutlet UIImageView *image2;
@property (nonatomic, retain) UIImageView*image1;
@property (nonatomic, retain) UIImageView*image2;

ViewController.m PAGE TOP

#import "newview.h"
@implementation ViewController
@synthesize image1, image2;
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *mytouch = [[event allTouches] anyObject];
image1.center = [mytouch locationInView:self.view];  
    [self collision];
-(void)collision {
if (CGRectIntersectsRect(image1.frame, image2.frame)) {
newview *second = [[newview alloc] initWithNibName:nil bundle:nil];
        [self presentModalViewController:second animated:YES];

newview.h PAGE TOP

@interface newview :UIViewController {

newview.m PAGE TOP

#import "ViewController.h"
@implementation newview
 -(IBAction)goback:(id)sender {
ViewController *second = [[ViewController alloc]initWithNibName:nil bundle:nil];
    [self presentModalViewController:second animated:YES];

Reference PAGE TOP


0 Comments Leave a comment

Please login in order to leave a comment.

Newest first

to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.