Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Moving object after creating it

objective-c game development xcode

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 Rodka99

Rodka99

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 26 June 2014 - 10:04 AM

I am fairly new to objective-c, being 15 I have only had about half a year of experience, and recently came across a problem when making a simple app where I create an object at a random location and then need to move the created object downwards. I have been able to create the objects, but have not been able to get that object to move with a timer. This is the code that I have so far:


//SPAWNING RANDOM OBJECTS
 
 
 
 
 
    -(IBAction)spawn{
 
 
 
    spawn = [NSTimer scheduledTimerWithTimeInterval:1.0f
 
                                                        target:self
 
                                                      selector:@selector(spawnMechanism)
 
                                                      userInfo:nil
 
                                                       repeats:YES];
 
}
 
-(IBAction)spawnMove{
 
 
 
    spawnMove = [NSTimer scheduledTimerWithTimeInterval:1.0f
 
                                             target:self
 
                                           selector:@selector(spawnMoveMechanism)
 
                                           userInfo:nil
 
                                            repeats:YES];
 
}
 
 
 
 
 
 
 
 
 
-(UIImageView *)spawnMoveMechanism:(UIImageView *)spawnGood{
 
 
 
    spawnGood.center =CGPointMake(spawnGood.center.x, spawnGood.center.y+100);
 
    NSLog(@"spawnMoveMechanism accomplished");
 
    return spawnGood;
 
}
 
 
 
-(void)spawnMechanism{
 
    timeSinceLastSpawn++;
 
 
 
    if(timeSinceLastSpawn >= 3)
 
    {
 
        if( arc4random() % 10 < 7 ){
 
 
 
 
            UIImageView *spawnGood;
 
 
 
            spawnGood=[[UIImageView alloc]initWithFrame:CGRectMake(arc4random() % 700, 50, 70,70)];
 
            UIImage *image;
 
            image=[UIImage imageNamed:@"friendly-01"];
 
            [spawnGood setImage:image];
 
            [self.view addSubview:spawnGood];
 
             NSLog(@"spawnGood spawned");
 
            [self spawnMoveMechanism];
 
 
 
 
 
 
 
 
 
 
 
        }
 
    }
 
}

 

Is anyone able to find any problems with the code above?


Edited by Rodka99, 26 June 2014 - 10:06 AM.


#2 JonElias

JonElias

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 201 posts

Posted 28 June 2014 - 01:37 PM

I have no idea what objective-c even is but
Could you make a white square covering the hole screen, overlapping the last frame and then ypu could make a new object moved little bit forwards. And so on
Overlapping frame, make changes in variables, create object
I have used this method once, you could remove the objects instead of overlapping it
Hope this helps
John
"computers are useless they only give you answers" Pablo Picasso
And yes he was alive when the first programmable computer was made

#3 JonElias

JonElias

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 201 posts

Posted 24 July 2014 - 10:04 AM

Amd bye the way i am fiftheen too

If it still is a problem:
http://stackoverflow...ally-on-the-mac
"computers are useless they only give you answers" Pablo Picasso
And yes he was alive when the first programmable computer was made

#4 Rodka99

Rodka99

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 24 July 2014 - 10:29 AM

thanks bro I already have the problem solved :)