Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 11-18-2009, 04:40 PM   #1 (permalink)
iamstuck
Registered Member
 
Join Date: Aug 2009
Posts: 8
iamstuck is on a distinguished road
Default How to pass multiple bits of information via NSTimer

Hi there,

Thanks in advance for any help anyone can offer. I'm pretty new to all this.

I come from a background of coding in Actionscript, so maybe I'm approaching this in the wrong way...

Basically, I'm moving a series of balls on the iphone screen. Every time the user taps the screen a new ball is created.

I want to pass each ball an X and Y velocity (let's call them vx and vy) and then move the ball based on these vx and vy values, using a timer.

I can get all of it working fine, except...

How do I pass a newly created ball it's X and Y velocity (vx and vy values).

Like I say, I'm used to Actionscript where I could give an object properties like ball.vx = 10 and ball.vy = 20 and then access those.

I want to be able to do the same thing here but I can't figure it out at all.

I'm passing the ball itself to the function called by the timer using "userInfo" as follows:

Code:
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(moveBall:) userInfo:ballImageView repeats:YES];
But how do I get the initial vx and vy values into each newly created ball? They'll be different each time so I can't use a global variable to store these, and as soon as each ball starts moving I apply gravity to the vy, thereby changing it.

I tried ballImageView.vx = 10 etc. but that didn't work.

Any help would be much appreciated. I know it will be a very simple answer as this is very basic in other programming languages but I've searched everywhere and can't find what I need.

Many thanks.

Ian
iamstuck is offline   Reply With Quote
 

» Advertisements
» Online Users: 546
14 members and 532 guests
akacaj, alphy, baramuse, bignoggins, Domele, glennmd, Gudus, ilmman, jaunsmith71, MartinB, ngaikwad, Paul Slocum, rky, Son of a Beach
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,323
Threads: 93,989
Posts: 402,413
Top Poster: BrianSlick (7,978)
Welcome to our newest member, jaunsmith71
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.