Hello Everyone!
It is my first week developing with Sparrow and I have ran into a couple of little problems.
I can't seem to understand the onEnterFrame event
Here is what I have so far..
in the Super init I have
[self addEventListener:@selector(onEnterFrame:) atObject:self
forType:SP_EVENT_TYPE_ENTER_FRAME];
Then the button is here:
SPTexture *rightButtonTexture = [SPTexture textureWithContentsOfFile:@"goright.png"];
rightButton = [[SPButton alloc] initWithUpState:rightButtonTexture text:@""];
rightButton.x = 15;
rightButton.y = 30;
[rightButton addEventListener:@selector(onRightButtonTriggered:) atObject:self
forType:SP_EVENT_TYPE_TOUCH];
[self addChild:rightButton];
then after return self:
- (void)initBackground {
backgroundTexture = [SPTexture textureWithContentsOfFile:@"levelbackground.png"];
background1 = [SPImage imageWithTexture:backgroundTexture];
background2 = [SPImage imageWithTexture:backgroundTexture];
background2.y = background1.height;
[self addChild:background1];
[self addChild:background2];
}
- (void)runLoop {
if(background1 && background2) {
int backgroundScrollSpeed = 1;
background1.y = background1.y + backgroundScrollSpeed;
background2.y = background2.y + backgroundScrollSpeed;
if(background1.y <= background1.height * -1)
background1.y = background2.height - backgroundScrollSpeed;
if(background2.y <= background2.height * -1)
background2.y = background1.height - backgroundScrollSpeed;
int house1ScrollSpeed = 1;
house1Image.y = house1Image.y + house1ScrollSpeed;
}
}
- (void)onRightButtonTriggered:(SPTouchEvent*)event
{
SPTouch *touch = [[event touchesWithTarget:self
andPhase:SPTouchPhaseBegan] anyObject];
SPTouch *touch2 = [[event touchesWithTarget:self
andPhase:SPTouchPhaseEnded] anyObject];
if (touch) {
rightPressed = YES;
}
else if (touch2) {
rightPressed = NO;
}
}
What I am trying to do is make the background scroll in the opposite direction while I am pressing the right button, and when it is released then the background stops scrolling.
It compiles fine, but when I run it, the background starts scrolling by itself and it dosen't stop.
Thankyou for your help!
Will