Я пытаюсь создать боковой скроллер, и у меня возникли проблемы с установкой координат моих объектов на случайные значения Y
.Координата Y не обновляется должным образом
Я называю свои объекты платформ. Я хочу, чтобы каждая из платформ отображалась в разных координатах Y
и считала, что мой подход был правильным способом. Но он работает не так хорошо.
Все координаты Y
выходят на тот же номер, и я не совсем уверен, почему? Я имею в виду, что я четко добавляю интервал, когда я их создаю.
Также одна вещь, которую я заметил, была, если я не добавляю таймер и не вызываю метод перемещения, который они показывают в нужном месте. так что это может быть нечто среднее между вызовом функции.
Еще одна проблема, которую я обнаружил, - это когда я снова звоню на платформах, только одна из платформ следует тому, что функции слайда требуют от нее, другой 2 следует за точками, однако не реагирует ни на что другое.
Любая помощь очень ценится!
//
// C4WorkSpace.m
// TheGame
//
//
#import "C4Workspace.h"
@implementation C4WorkSpace {
C4Shape *player ; // player
CGPoint p, move; // CG point for moving platforms && Players
int speed; // Speed of the platforms
C4Timer *timer; // Timer
NSMutableArray *platforms; // Platform Array
}
-(void)setup {
speed = 5; // Speed Limit
p = CGPointMake(self.canvas.width, 400); // Making 2 coordinates for the platform shape to follow
move = CGPointMake(0, 0); // Making 2 coordinates for the user shape to follow
platforms = [NSMutableArray array]; // Pointer of Array for platforms
// Generating shapes
for (int i = 0; i < 3; i++)
{
C4Shape * s = [C4Shape rect:CGRectMake(0, 400, 50, [C4Math randomInt:50])]; // Making the platform
p.x = self.canvas.width; // x - coordinate for the platforms
p.y += 100; // y - coordinate of the platforms
s.center = p; // The Center of the Circle is P
[platforms addObject:s]; // Adding platforms to the platforms array
[self.canvas addShape:platforms[i]]; // Adding an instance of it
timer = [C4Timer automaticTimerWithInterval:1.0f/30 target:self method:@"slide" repeats:YES]; // Timer to shoot it off ever frame
}
player = [C4Shape ellipse:CGRectMake(0, 0, 50, 50)]; // The shape of the player
[self.canvas addSubview:player]; // Adding an instance of the player
}
//Moving the platform
-(void) slide {
//Calling the platforms again to add movement
for (C4Shape *s in platforms){
// Adding boundries
if (p.x <= 0) {
p.x = self.canvas.width; // if it's smaller than the width of the cavas auto transport
p.y = [C4Math randomInt:self.canvas.height]; // choose a different y coordinate for each
}
p.x-= speed; // Adding accelaration
C4Log(@"The Y is .%2f", p.y); // Logging the problem
s.center = p; // making the shape follow the point
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *place = [[event allTouches] anyObject]; // Get touches
move = [place locationInView:place.view]; // Gets the location of the current mouse point
player.center = move; // folllowing the move point
[self collisionCheck]; // collision check
}
-(void) collisionCheck {
//currently empty!
}
@end
Эй, Трэвис, спасибо за замечательный сложный ответ. Я согласен с тем, что добавить его в свой класс будет лучше, но я не понимаю его на 100%, как это сделать. Я отправлю код, который я сделал для него в ближайшее время! В основном это просто использование @synthesis '@property', которое меня замарает. – tailedmouse
его простые в использовании свойства, но для того, чтобы действительно понять их, требуется некоторое чтение, поэтому взгляните на: http://www.c4ios.com/tutorials/properties .. p.s. вам не нужно @synthesize в большинстве случаев –
У меня возникли проблемы с пониманием этого полностью. Адам немного нас научил, поэтому я разобрал его код и попытался сохранить то, что мне было нужно, и немного изменил его. Я загрузил вопрос: D – tailedmouse