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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-18-2009, 05:40 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 8
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
Old 11-19-2009, 09:22 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 8
Default Still Struggling With This

Hi there,

Sorry to send this back to the top. I know it's not good form, and I appreciate if anyone had an answer by now they would have posted it, but I'm really struggling still and the post has slipped off the first page so quickly I was hoping someone who hasn't seen it yet may have an answer. I really have looked everywhere and can't figure this out. Any help would be really appreciated.

It must be a simple thing to do because it's so easy in other languages (ie: Actionscript).

I essentially want to end up with each ball having a series of properties as in:

ball.vx = 10;
ball.vy = 10;
ball.ballAngle = 72;

which I can then access, change etc. and only have them apply to their individual ball.

Am I right in thinking there's a way to achieve this? In AS it's so simple, but whatever I try here just kicks back errors or crashes my app.

Thanks.

Ian
iamstuck is offline   Reply With Quote
Old 11-19-2009, 05:35 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,558
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

what is "ball"? A UIImageView?
smithdale87 is offline   Reply With Quote
Old 11-20-2009, 03:54 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 8
Default Yes...

Quote:
Originally Posted by smithdale87 View Post
what is "ball"? A UIImageView?
Yes - it is a UIImageView.

Thanks.

Ian
iamstuck is offline   Reply With Quote
Old 11-20-2009, 04:14 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,558
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

So a UIImageView doesnt' know what vx, vy are. You have to tell it first ( unlike in ActionScript I'm assuming ).

One solution would be to subclass UIImageView and give it the properties you want. You can call this new class BallImageView or something. If you don't know what I mean by subclass, i recommend you look for some tutorials.
smithdale87 is offline   Reply With Quote
Reply

Bookmarks

Tags
ball, nstimer, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 244
15 members and 229 guests
ADY, AragornSG, Dani77, Dattee, Duncan C, fkmtc, HDshot, HemiMG, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:17 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0