So I'm coming from a bit of a processing background (albiet not much) where I'm used to working with a draw loop that runs over and over when the app is running.
I can't seem to find something similar in xcode and C4. Is there anything like that anyone can suggest?
What I'm basically doing is just creating a bouncing ball app using C4 vectors as properties in a custom class
Here is my custom class Header/Implementation file:
@interface splitSquare : C4Shape
@property C4Vector *accel;
@property C4Vector *velocity;
@property C4Vector *location;
-(id)initWithPoint:(CGPoint)point;
@end
-(id)initWithPoint:(CGPoint)point{
self = [super init];
if (self){
CGRect frame = CGRectMake(0, 0, 50, 50);
[self ellipse:frame];
self.lineWidth = 0.0f;
self.fillColor = [UIColor colorWithRed:[C4Math randomInt:100]/100.0f
green:[C4Math randomInt:100]/100.0f
blue:0.5f
alpha:1.0f];
_location = [C4Vector vectorWithX:point.x Y:point.y Z:0.0f];
self.origin = _location.CGPoint;
_accel = [C4Vector vectorWithX:0.04f Y:0.05f Z:0.0f];
_velocity = [C4Vector vectorWithX:0.004f Y:0.0005f Z:0.0f];
C4Log(@"The current value of velocity x is %f and y is %f", _velocity.x, _velocity.y);
}
I'm doing something pretty simple (adding accel to velocity and velocity to location, then assign location to the shapes origin). In the main C4WorkSpace I have this code:
@interface C4WorkSpace()
-(void)updateVectors;
@end
@implementation C4WorkSpace
{
splitSquare *testShape;
C4Timer *timer;
}
-(void)setup {
testShape = [[splitSquare alloc] initWithPoint:point2];
[self.canvas addShape:testShape];
testShape.animationDuration = 0.25f;
timer = [C4Timer automaticTimerWithInterval:0.25f target:self method:@"updateVectors" repeats:YES];
}
-(void)updateVectors{
//accel add to vel, vel added to location
[testShape.velocity add:testShape.accel];
[testShape.location add:testShape.velocity];
testShape.origin = testShape.location.CGPoint;
testShape.fillColor = [UIColor colorWithRed:[C4Math randomInt:100]/100.0f
green:[C4Math randomInt:100]/100.0f
blue:0.5f
alpha:1.0f];
}
@end
So this is what I'm doing now with a C4 timer getting called, but I feel like there has to be a more elegant way to do this. Right now the animation is jumpy and although it doesn't throw an error it doesn't seem to work properly (every time I run the iOS simulator it runs for a second then jumps back into xcode and shows me the current thread).
Any/all suggestions would be awesome thanks!