Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 03-27-2009, 05:24 PM   #21 (permalink)
LeopardDevX
iPhone Developer
 
Join Date: Mar 2009
Posts: 220
Arrow but...

Quote:
Originally Posted by smasher View Post
I can't see your code, so I don't know what variables you have If you have a speedY variable, then you can use that to get the new position of the enemy.

So, this code will loop through every enemy in the array, and move them all down the screen by "speedY" :
Code:
for (UIView *anEnemy in enemies){
float newX = anEnemy.center.x;
float newY = anEnemy.center.y +speedY;
anEnemy.center = CGMakePoint(newX, newY);
}
"anEnemy" is just a pointer I use when looking through the array of enemies. It's not a new object or anything, it's just used to point to the existing enemies in the array. We need a pointer so we can give everyone in the array a new position.


Code:
 warning: local deceleration of "newEnemy"    hides instance variable.
This means that you already have a variable (instance variable) called "newEnemy."
The compiler is complaining that I declared a new variable (local variable) with the same name. There are two ways to fix it -
(1) remove "UIImageView *" from the front of that line, so it doesn't declare a new variable. It will just use the existing variable instead.
or (2) change the name of the local variable (the new one declared on that line.) That will leave the

The correct step to take depends on what your code is doing. Are you trying to affect the instance variable, or just a local one? In my examples, changing the name of the local variable should do the trick (option 2).

but how does that make the newEnemy move.... because currently it doesnt....

__________________
Thank You.
LeopardDevX is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,357
Threads: 39,155
Posts: 171,639
Top Poster: smasher (2,577)
Welcome to our newest member, davidm
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.