void SpriteEaseBounceInOut::onEnter() { EaseSpriteDemo::onEnter(); CCActionInterval* move = CCMoveBy::actionWithDuration(3, CGPointMake(350,0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease = CCEaseBounceInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_back = move_ease->reverse(); CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease, move_ease_back, NULL); this->positionForTwo(); m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); }
void mac_warp_mouse() { #ifndef ACTIVEGS Rect port_rect; Point win_origin_pt; CGPoint cgpoint; CGDisplayErr cg_err; GetPortBounds(GetWindowPort(g_main_window), &port_rect); SetPt(&win_origin_pt, port_rect.left, port_rect.top); LocalToGlobal(&win_origin_pt); cgpoint = CGPointMake( (float)(win_origin_pt.h + X_A2_WINDOW_WIDTH/2), (float)(win_origin_pt.v + X_A2_WINDOW_HEIGHT/2)); cg_err = CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint); #endif }
//------------------------------------------------------------------ // // ActionRepeat // //------------------------------------------------------------------ void ActionRepeat::onEnter() { ActionsDemo::onEnter(); alignSpritesLeft(2); CCActionInterval* a1 = CCMoveBy::actionWithDuration(1, CGPointMake(150,0)); CCActionInterval* action1 = CCRepeat::actionWithAction( CCSequence::actions( CCPlace::actionWithPosition(CGPointMake(60,60)), a1, NULL) , 3); CCAction* action2 = CCRepeatForever::actionWithAction( (CCActionInterval*)(CCSequence::actions((CCActionInterval*)(a1->copy()->autorelease()), a1->reverse(), NULL)) ); m_kathia->runAction(action1); m_tamara->runAction(action2); }
//------------------------------------------------------------------ // // ActionBezier // //------------------------------------------------------------------ void ActionBezier::onEnter() { ActionsDemo::onEnter(); CGSize s = CCDirector::sharedDirector()->getWinSize(); // // startPosition can be any coordinate, but since the movement // is relative to the Bezier curve, make it (0,0) // centerSprites(3); // sprite 1 ccBezierConfig bezier; bezier.controlPoint_1 = CGPointMake(0, s.height/2); bezier.controlPoint_2 = CGPointMake(300, -s.height/2); bezier.endPosition = CGPointMake(300,100); CCActionInterval* bezierForward = CCBezierBy::actionWithDuration(3, bezier); CCActionInterval* bezierBack = bezierForward->reverse(); CCAction* rep = CCRepeatForever::actionWithAction((CCActionInterval*)CCSequence::actions( bezierForward, bezierBack, NULL)); // sprite 2 m_tamara->setPosition(CGPointMake(80,160)); ccBezierConfig bezier2; bezier2.controlPoint_1 = CGPointMake(100, s.height/2); bezier2.controlPoint_2 = CGPointMake(200, -s.height/2); bezier2.endPosition = CGPointMake(240,160); CCActionInterval* bezierTo1 = CCBezierTo::actionWithDuration(2, bezier2); // sprite 3 m_kathia->setPosition(CGPointMake(400,160)); CCActionInterval* bezierTo2 = CCBezierTo::actionWithDuration(2, bezier2); m_grossini->runAction( rep); m_tamara->runAction(bezierTo1); m_kathia->runAction(bezierTo2); }
void GraphicsLayerCACF::updateLayerSize() { CGRect rect = CGRectMake(0, 0, m_size.width(), m_size.height()); if (m_transformLayer) { m_transformLayer->setBounds(rect); // The anchor of the contents layer is always at 0.5, 0.5, so the position is center-relative. CGPoint centerPoint = CGPointMake(m_size.width() / 2.0f, m_size.height() / 2.0f); m_layer->setPosition(centerPoint); } m_layer->setBounds(rect); // Note that we don't resize m_contentsLayer. It's up the caller to do that. // if we've changed the bounds, we need to recalculate the position // of the layer, taking anchor point into account. updateLayerPosition(); }
// angle in degrees void TIPGradientFindEndpointsForRotation( CGRect rect, float angle, CGPoint *startPoint, CGPoint *endPoint) { if(angle == 0) { *startPoint = CGPointMake(rect.origin.x, rect.origin.y); //right of rect *endPoint = CGPointMake(rect.origin.x + rect.size.width, rect.origin.y); //left of rect } else if(angle == 90) { *startPoint = CGPointMake(rect.origin.x, rect.origin.y); //bottom of rect *endPoint = CGPointMake(rect.origin.x, rect.origin.y + rect.size.height); //top of rect } else { float x,y; float sina, cosa, tana; float length; float deltax, deltay; float rangle = angle * pi/180; //convert the angle to radians if(fabsf(tanf(rangle))<=1) //for range [-45,45], [135,225] { x = rect.size.width; y = rect.size.height; sina = sin(rangle); cosa = cos(rangle); tana = tan(rangle); length = x/fabsf(cosa)+(y-x*fabsf(tana))*fabsf(sina); deltax = length*cosa/2; deltay = length*sina/2; } else //for range [45,135], [225,315] { x = rect.size.height; y = rect.size.width; sina = sin(rangle - 90*pi/180); cosa = cos(rangle - 90*pi/180); tana = tan(rangle - 90*pi/180); length = x/fabsf(cosa)+(y-x*fabsf(tana))*fabsf(sina); deltax =-length*sina/2; deltay = length*cosa/2; } *startPoint = CGPointMake( (rect.origin.x+rect.size.width/2.0f)-deltax, (rect.origin.y+rect.size.height/2.0f)-deltay); *endPoint = CGPointMake( (rect.origin.x+rect.size.width/2.0f)+deltax, (rect.origin.y+rect.size.height/2.0f)+deltay); } }
static inline void SendMouseMove(int X, int Y) { CGPoint point = GetMouseLoc(); CGRect ssize = CGDisplayBounds(CGMainDisplayID()); int newX = point.x + X, newY = point.y + Y; newX = newX < 0 ? 0 : newX; newY = newY < 0 ? 0 : newY; newX = newX > ssize.size.width - 1 ? ssize.size.width - 1 : newX; newY = newY > ssize.size.height - 2 ? ssize.size.height - 1 : newY; CGEventRef move = CGEventCreateMouseEvent( NULL, kCGEventMouseMoved, CGPointMake(newX, newY), kCGMouseButtonLeft // ignored ); CGEventPost(kCGHIDEventTap, move); CFRelease(move); }
void TilePDFWithCGLayer(CGContextRef context, CFURLRef url) { // Again this should really be computed based on // the area intended to be tiled. float fillwidth = 612., fillheight = 792.; CGSize s; float tileX, tileY, tileOffsetX, tileOffsetY; float w, h; CGLayerRef layer = createLayerWithImageForContext(context, url); if(layer == NULL){ fprintf(stderr, "Couldn't create the layer!\n"); return; } // Compute the tile size and offset. s = CGLayerGetSize(layer); tileX = s.width; tileY = s.height; #if DOSCALING // Space the tiles by the tile width and height // plus an extra 2 units in each dimension. tileOffsetX = 2. + tileX; tileOffsetY = 2. + tileY; #else // Add 6 units to the offset in each direction // if there is no scaling of the source PDF document. tileOffsetX = 6. + tileX; tileOffsetY = 6. + tileY; #endif // Now draw the contents of the layer to the context. // The layer is drawn at its true size (the size of // the tile) with its origin located at the corner // of each tile. for(h = 0; h < fillheight ; h += tileOffsetY) for(w = 0; w < fillwidth ; w += tileOffsetX){ CGContextDrawLayerAtPoint(context, CGPointMake(w, h), layer); } // Release the layer when done drawing with it. CGLayerRelease(layer); }
void GiveFocusToScreen(int ScreenIndex) { screen_info *Screen = GetDisplayFromScreenID(ScreenIndex); if(Screen) { CGPoint CursorPos = CGPointMake(Screen->X + (Screen->Width / 2), Screen->Y + (Screen->Height / 2)); CGEventRef MoveEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, CursorPos, kCGMouseButtonLeft); CGEventSetFlags(MoveEvent, 0); CGEventPost(kCGHIDEventTap, MoveEvent); CFRelease(MoveEvent); DEBUG("GiveFocusToScreen() " << ScreenIndex) UpdateActiveWindowList(Screen); tree_node *NewFocusNode = GetFirstLeafNode(Screen->Space[Screen->ActiveSpace].RootNode); SetWindowFocusByNode(NewFocusNode); } }
//------------------------------------------------------------------ // // TestLayer // //------------------------------------------------------------------ void TestLayer::onEnter() { CCLayer::onEnter(); float x,y; CGSize size = CCDirector::sharedDirector()->getWinSize(); x = size.width; y = size.height; //NSArray *array = [UIFont familyNames]; //for( NSString *s in array ) // NSLog( s ); CCLabel* label = CCLabel::labelWithString("cocos2d", "Tahoma", 64); label->setPosition( CGPointMake(x/2,y/2) ); addChild(label); }
bool GTMouseDriver::moveTo(const QPoint& p) { int x = p.x(); int y = p.y(); if (bp.testFlag(Qt::LeftButton)) { return selectAreaMac(x, y); } DRIVER_CHECK(isPointInsideScreen(x, y), "Invalid coordinates"); CGEventRef event = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, CGPointMake(x, y), 0 /*ignored*/); DRIVER_CHECK(event != NULL, "Can't create event"); CGEventPost(kCGSessionEventTap, event); CFRelease(event); GTGlobals::sleep(100); return true; }
void XInputSimulatorImplMacOs::mouseMoveTo(int x, int y) { //TODO screen check see moveRelative CGEventRef mouseEv = CGEventCreateMouseEvent( NULL, kCGEventMouseMoved, CGPointMake(x, y), kCGMouseButtonLeft); std::cout << "mv: " << mouseEv << std::endl; CGEventPost(kCGHIDEventTap, mouseEv); CFRelease(mouseEv); this->currentX = x; this->currentY = y; }
void ActivateScreen(screen_info *Screen) { CGPoint CursorPos = GetCursorPos(); CGPoint ClickPos = CGPointMake(Screen->X, Screen->Y); CGEventRef MoveEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, ClickPos, kCGMouseButtonLeft); CGEventSetFlags(MoveEvent, 0); CGEventPost(kCGHIDEventTap, MoveEvent); CFRelease(MoveEvent); MoveEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp, ClickPos, kCGMouseButtonLeft); CGEventSetFlags(MoveEvent, 0); CGEventPost(kCGHIDEventTap, MoveEvent); CFRelease(MoveEvent); MoveEvent = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, CursorPos, kCGMouseButtonLeft); CGEventSetFlags(MoveEvent, 0); CGEventPost(kCGHIDEventTap, MoveEvent); CFRelease(MoveEvent); }
void MacOSMouseOStream::doubleClick(pair<uint32_t, uint32_t> mouse, int clickCount) { #if __APPLE__ CGPoint point = CGPointMake(mouse.first, mouse.second); CGEventRef theEvent = CGEventCreateMouseEvent( NULL, kCGEventLeftMouseDown, point, kCGMouseButtonLeft); ProcessSerialNumber psn = { 0, kNoProcess }; GetFrontProcess( &psn ); CGEventSetIntegerValueField(theEvent, kCGMouseEventClickState, clickCount); CGEventPostToPSN(&psn, theEvent); CGEventSetType(theEvent, kCGEventLeftMouseUp); CGEventPostToPSN(&psn, theEvent); CGEventSetType(theEvent, kCGEventLeftMouseDown); CGEventPostToPSN(&psn, theEvent); CGEventSetType(theEvent, kCGEventLeftMouseUp); CGEventPostToPSN(&psn, theEvent); CFRelease(theEvent); #endif }
void SpriteEaseBack::onEnter() { EaseSpriteDemo::onEnter(); CCActionInterval* move = CCMoveBy::actionWithDuration(3, CGPointMake(350,0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease_in = CCEaseBackIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_in_back = move_ease_in->reverse(); CCActionInterval* move_ease_out = CCEaseBackOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_out_back = move_ease_out->reverse(); CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_in, move_ease_in_back, NULL); CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_out, move_ease_out_back, NULL); m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); m_kathia->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq3)); }
WKCACFLayerRenderer::WKCACFLayerRenderer(WKCACFLayerRendererClient* client) : m_client(client) , m_mightBeAbleToCreateDeviceLater(true) , m_rootLayer(WKCACFRootLayer::create(this)) , m_context(AdoptCF, CACFContextCreate(0)) , m_renderContext(static_cast<CARenderContext*>(CACFContextGetRenderContext(m_context.get()))) , m_renderer(0) , m_hostWindow(0) , m_renderTimer(this, &WKCACFLayerRenderer::renderTimerFired) , m_backingStoreDirty(false) , m_mustResetLostDeviceBeforeRendering(false) { windowsForContexts().set(m_context.get(), this); // Under the root layer, we have a clipping layer to clip the content, // that contains a scroll layer that we use for scrolling the content. // The root layer is the size of the client area of the window. // The clipping layer is the size of the WebView client area (window less the scrollbars). // The scroll layer is the size of the root child layer. // Resizing the window will change the bounds of the rootLayer and the clip layer and will not // cause any repositioning. // Scrolling will affect only the position of the scroll layer without affecting the bounds. m_rootLayer->setName("WKCACFLayerRenderer rootLayer"); m_rootLayer->setAnchorPoint(CGPointMake(0, 0)); m_rootLayer->setGeometryFlipped(true); #ifndef NDEBUG CGColorRef debugColor = CGColorCreateGenericRGB(1, 0, 0, 0.8); m_rootLayer->setBackgroundColor(debugColor); CGColorRelease(debugColor); #endif if (m_context) m_rootLayer->becomeRootLayerForContext(m_context.get()); #ifndef NDEBUG char* printTreeFlag = getenv("CA_PRINT_TREE"); m_printTree = printTreeFlag && atoi(printTreeFlag); #endif }
FREObject setCursorPos(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { int tx = 0; int ty = 0; FREGetObjectAsInt32(argv[0], &tx); FREGetObjectAsInt32(argv[1], &ty); //as3Print("Set cursor pos \n");//,tx,ty); CGPoint point; point.x = tx; point.y = ty; CGAssociateMouseAndMouseCursorPosition(true); //CGWarpMouseCursorPosition(point); // printf("Error : %i\n",error); CGDisplayMoveCursorToPoint(CGMainDisplayID(),point); CGAssociateMouseAndMouseCursorPosition(true); CGEventRef mouse = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, CGPointMake(tx, ty),0); CGEventPost(kCGHIDEventTap, mouse); CFRelease(mouse); CGEventRef event = CGEventCreate(NULL); CGPoint cursorGet = CGEventGetLocation(event); CFRelease(event); char msg[256]; sprintf(msg,"After set, check pos %f %f\n",cursorGet.x, cursorGet.y); //as3Print(msg); FREObject result; FRENewObjectFromBool(1, &result); //FRENewObjectFromBool(true,&result); return result; }
void quartzgen_textpara(GVJ_t *job, pointf p, textpara_t *para) { CGContextRef context = (CGContextRef)job->context; /* adjust text position */ switch (para->just) { case 'r': p.x -= para->width; break; case 'l': p.x -= 0.0; break; case 'n': default: p.x -= para->width / 2.0; break; } p.y += para->yoffset_centerline; void* layout; if (para->free_layout == &quartz_free_layout) layout = para->layout; else layout = quartz_new_layout(para->fontname, para->fontsize, para->str); #if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 20000 CGContextSaveGState(context); CGContextScaleCTM(context, 1.0, -1.0); p.y = -p.y - para->yoffset_layout; #endif CGContextSetRGBFillColor(context, job->obj->pencolor.u.RGBA[0], job->obj->pencolor.u.RGBA[1], job->obj->pencolor.u.RGBA[2], job->obj->pencolor.u.RGBA[3]); quartz_draw_layout(layout, context, CGPointMake(p.x, p.y)); #if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 20000 CGContextRestoreGState(context); #endif if (para->free_layout != &quartz_free_layout) quartz_free_layout(layout); }
//------------------------------------------------------------------ // // PongLayer // //------------------------------------------------------------------ PongLayer::PongLayer() { m_ballStartingVelocity = CGPointMake(20.0f, -100.0f); m_ball = Ball::ballWithTexture( CCTextureCache::sharedTextureCache()->addImage(s_Ball) ); m_ball->setPosition( CGPointMake(160.0f, 240.0f) ); m_ball->setVelocity( m_ballStartingVelocity ); addChild( m_ball ); m_ball->retain(); CCTexture2D* paddleTexture = CCTextureCache::sharedTextureCache()->addImage(s_Paddle); NSMutableArray<NSObject *> *paddlesM = new NSMutableArray<NSObject *>(4); Paddle* paddle = Paddle::paddleWithTexture(paddleTexture); paddle->setPosition( CGPointMake(160, 15) ); paddlesM->addObject( paddle ); paddle = Paddle::paddleWithTexture( paddleTexture ); paddle->setPosition( CGPointMake(160, 480 - kStatusBarHeight - 15) ); paddlesM->addObject( paddle ); paddle = Paddle::paddleWithTexture( paddleTexture ); paddle->setPosition( CGPointMake(160, 100) ); paddlesM->addObject( paddle ); paddle = Paddle::paddleWithTexture( paddleTexture ); paddle->setPosition( CGPointMake(160, 480 - kStatusBarHeight - 100) ); paddlesM->addObject( paddle ); m_paddles = paddlesM->copy(); NSMutableArray<NSObject *>::NSMutableArrayIterator it; for(it = m_paddles->begin(); it != m_paddles->end(); it++) { paddle = (Paddle*)(*it); if(!paddle) break; addChild(paddle); } paddlesM->release(); schedule( schedule_selector(PongLayer::doStep) ); }
int main(int argc, char *argv[]) { if (argc > 2) { int x = atoi(argv[1]); int y = atoi(argv[2]); // click settings CGEventRef click = CGEventCreateMouseEvent( NULL, kCGEventLeftMouseDown, CGPointMake(x,y), kCGMouseButtonLeft ); // perform click CGEventPost(kCGHIDEventTap, click); CFRelease(click); } return 0; }
CGPoint NALineIntersection(const CGPoint start1, const CGPoint end1, const CGPoint start2, const CGPoint end2) { /* Setup the system of equations. */ CGFloat a = end1.x - start1.x; CGFloat b = -end2.x + start2.x; CGFloat c = end1.y - start1.y; CGFloat d = -end2.y + start2.y; CGFloat det = a * d - b * c; /* Check if the system is singular. */ if (IS_EPSILON(det)) { return CGPOINT_INVALID; } /* Otherwise, find the intersection point. */ CGFloat aInv = d / det; CGFloat bInv = -b / det; CGFloat cInv = -c / det; CGFloat dInv = a / det; CGFloat x = aInv * (start2.x - start1.x) + bInv * (start2.y - start1.y); CGFloat y = cInv * (start2.x - start1.x) + dInv * (start2.y - start1.y); /* If the intersection point does not lie within the line segments, also return CGPOINT_INVALID. */ if ((x < 0.0) || (x > 1.0) || (y < 0.0) || (y > 1.0)) { return CGPOINT_INVALID; } /* Otherwise return the result. */ return CGPointMake(start1.x + x * (end1.x - start1.x), start1.y + x * (end1.y - start1.y)); }
bool CCFollow::initWithTarget(CCNode *pFollowedNode, CGRect rect) { assert(pFollowedNode != NULL); pFollowedNode->retain(); m_pobFollowedNode = pFollowedNode; m_bBoundarySet = true; m_bBoundaryFullyCovered = false; CGSize winSize = CCDirector::sharedDirector()->getWinSize(); m_obFullScreenSize = CGPointMake(winSize.width, winSize.height); m_obHalfScreenSize = ccpMult(m_obFullScreenSize, 0.5f); m_fLeftBoundary = -((rect.origin.x+rect.size.width) - m_obFullScreenSize.x); m_fRightBoundary = -rect.origin.x ; m_fTopBoundary = -rect.origin.y; m_fBottomBoundary = -((rect.origin.y+rect.size.height) - m_obFullScreenSize.y); if(m_fRightBoundary < m_fLeftBoundary) { // screen width is larger than world's boundary width //set both in the middle of the world m_fRightBoundary = m_fLeftBoundary = (m_fLeftBoundary + m_fRightBoundary) / 2; } if(m_fTopBoundary < m_fBottomBoundary) { // screen width is larger than world's boundary width //set both in the middle of the world m_fTopBoundary = m_fBottomBoundary = (m_fTopBoundary + m_fBottomBoundary) / 2; } if( (m_fTopBoundary == m_fBottomBoundary) && (m_fLeftBoundary == m_fRightBoundary) ) { m_bBoundaryFullyCovered = true; } return true; }
//------------------------------------------------------------------ // // ActionOrbit // //------------------------------------------------------------------ void ActionOrbit::onEnter() { ActionsDemo::onEnter(); centerSprites(3); CCActionInterval* orbit1 = CCOrbitCamera::actionWithDuration(2,1, 0, 0, 180, 0, 0); CCFiniteTimeAction* action1 = CCSequence::actions( orbit1, orbit1->reverse(), NULL); CCActionInterval* orbit2 = CCOrbitCamera::actionWithDuration(2,1, 0, 0, 180, -45, 0); CCFiniteTimeAction* action2 = CCSequence::actions( orbit2, orbit2->reverse(), NULL); CCActionInterval* orbit3 = CCOrbitCamera::actionWithDuration(2,1, 0, 0, 180, 90, 0); CCFiniteTimeAction* action3 = CCSequence::actions( orbit3, orbit3->reverse(), NULL); m_kathia->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)action1)); m_tamara->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)action2)); m_grossini->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)action3)); CCActionInterval* move = CCMoveBy::actionWithDuration(3, CGPointMake(100,-100)); CCActionInterval* move_back = move->reverse(); CCFiniteTimeAction* seq = CCSequence::actions(move, move_back, NULL); CCAction* rfe = CCRepeatForever::actionWithAction((CCActionInterval*)seq); m_kathia->runAction(rfe); m_tamara->runAction((CCAction*)(rfe->copy()->autorelease())); m_grossini->runAction((CCAction*)(rfe->copy()->autorelease())); }
void SpriteEaseElasticInOut::onEnter() { EaseSpriteDemo::onEnter(); CCActionInterval* move = CCMoveBy::actionWithDuration(3, CGPointMake(350,0)); CCActionInterval* move_ease_inout1 = CCEaseElasticInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 0.3f); CCActionInterval* move_ease_inout_back1 = move_ease_inout1->reverse(); CCActionInterval* move_ease_inout2 = CCEaseElasticInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 0.45f); CCActionInterval* move_ease_inout_back2 = move_ease_inout2->reverse(); CCActionInterval* move_ease_inout3 = CCEaseElasticInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 0.6f); CCActionInterval* move_ease_inout_back3 = move_ease_inout3->reverse(); CCFiniteTimeAction* seq1 = CCSequence::actions( move_ease_inout1, move_ease_inout_back1, NULL); CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_inout2, move_ease_inout_back2, NULL); CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_inout3, move_ease_inout_back3, NULL); m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); m_kathia->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq3)); }
TestLayer2::TestLayer2() { float x,y; CGSize size = CCDirector::sharedDirector()->getWinSize(); x = size.width; y = size.height; CCSprite* bg1 = CCSprite::spriteWithFile(s_back2); bg1->setPosition( CGPointMake(size.width/2, size.height/2) ); addChild(bg1, -1); CCLabelTTF* title = CCLabelTTF::labelWithString((transitions[s_nSceneIdx]).c_str(), "Thonburi", 32 ); addChild(title); title->setColor( ccc3(255,32,32) ); title->setPosition( CGPointMake(x/2, y-100) ); CCLabelTTF* label = CCLabelTTF::labelWithString("SCENE 2", "Marker Felt", 38); label->setColor( ccc3(16,16,255)); label->setPosition( CGPointMake(x/2,y/2)); addChild( label); // menu CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TestLayer2::backCallback) ); CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(TestLayer2::restartCallback) ); CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(TestLayer2::nextCallback) ); CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL); menu->setPosition( CGPointZero ); item1->setPosition( CGPointMake( x/2 - 100,30) ); item2->setPosition( CGPointMake( x/2, 30) ); item3->setPosition( CGPointMake( x/2 + 100,30) ); addChild(menu, 1); schedule(schedule_selector(TestLayer2::step), 1.0f); }
void ActionsDemo::alignSpritesLeft(unsigned int numberOfSprites) { CGSize s = CCDirector::sharedDirector()->getWinSize(); if( numberOfSprites == 1 ) { m_tamara->setIsVisible(false); m_kathia->setIsVisible(false); m_grossini->setPosition(CGPointMake(60, s.height/2)); } else if( numberOfSprites == 2 ) { m_kathia->setPosition( CGPointMake(60, s.height/3)); m_tamara->setPosition( CGPointMake(60, 2*s.height/3)); m_grossini->setIsVisible( false ); } else if( numberOfSprites == 3 ) { m_grossini->setPosition( CGPointMake(60, s.height/2)); m_tamara->setPosition( CGPointMake(60, 2*s.height/3)); m_kathia->setPosition( CGPointMake(60, s.height/3)); } }
void ActionsDemo::centerSprites(unsigned int numberOfSprites) { CGSize s = CCDirector::sharedDirector()->getWinSize(); if( numberOfSprites == 1 ) { m_tamara->setIsVisible(false); m_kathia->setIsVisible(false); m_grossini->setPosition(CGPointMake(s.width/2, s.height/2)); } else if( numberOfSprites == 2 ) { m_kathia->setPosition( CGPointMake(s.width/3, s.height/2)); m_tamara->setPosition( CGPointMake(2*s.width/3, s.height/2)); m_grossini->setIsVisible(false); } else if( numberOfSprites == 3 ) { m_grossini->setPosition( CGPointMake(s.width/2, s.height/2)); m_tamara->setPosition( CGPointMake(s.width/4, s.height/2)); m_kathia->setPosition( CGPointMake(3 * s.width/4, s.height/2)); } }
IntPoint::operator CGPoint() const { return CGPointMake(m_x, m_y); }
//------------------------------------------------------------------ // // DemoModernArt // //------------------------------------------------------------------ void DemoModernArt::onEnter() { ParticleDemo::onEnter(); m_emitter = new CCParticleSystemPoint(); m_emitter->initWithTotalParticles(1000); //m_emitter->autorelease(); m_background->addChild(m_emitter, 10); ////m_emitter->release(); CGSize s = CCDirector::sharedDirector()->getWinSize(); // duration m_emitter->setDuration(-1); // gravity m_emitter->setGravity(CGPointMake(0,0)); // angle m_emitter->setAngle(0); m_emitter->setAngleVar(360); // radial m_emitter->setRadialAccel(70); m_emitter->setRadialAccelVar(10); // tagential m_emitter->setTangentialAccel(80); m_emitter->setTangentialAccelVar(0); // speed of particles m_emitter->setSpeed(50); m_emitter->setSpeedVar(10); // emitter position m_emitter->setPosition( CGPointMake( s.width/2, s.height/2) ); m_emitter->setPosVar(CGPointZero); // life of particles m_emitter->setLife(2.0f); m_emitter->setLifeVar(0.3f); // emits per frame m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); // color of particles ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; m_emitter->setStartColor(startColor); ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; m_emitter->setStartColorVar(startColorVar); ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; m_emitter->setEndColor(endColor); ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; m_emitter->setEndColorVar(endColorVar); // size, in pixels m_emitter->setStartSize(1.0f); m_emitter->setStartSizeVar(1.0f); m_emitter->setEndSize(32.0f); m_emitter->setEndSizeVar(8.0f); // texture m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); // additive m_emitter->setIsBlendAdditive(false); setEmitterPosition(); }
//------------------------------------------------------------------ // // DemoRotFlower // //------------------------------------------------------------------ void DemoRotFlower::onEnter() { ParticleDemo::onEnter(); m_emitter = new CCParticleSystemQuad(); m_emitter->initWithTotalParticles(300); //m_emitter->autorelease(); m_background->addChild(m_emitter, 10); ////m_emitter->release(); // win32 : Remove this line m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars2) ); // duration m_emitter->setDuration(-1); // gravity m_emitter->setGravity(CGPointZero); // angle m_emitter->setAngle(90); m_emitter->setAngleVar(360); // speed of particles m_emitter->setSpeed(160); m_emitter->setSpeedVar(20); // radial m_emitter->setRadialAccel(-120); m_emitter->setRadialAccelVar(0); // tagential m_emitter->setTangentialAccel(30); m_emitter->setTangentialAccelVar(0); // emitter position m_emitter->setPosition( CGPointMake(160,240) ); m_emitter->setPosVar(CGPointZero); // life of particles m_emitter->setLife(3); m_emitter->setLifeVar(1); // spin of particles m_emitter->setStartSpin(0); m_emitter->setStartSpinVar(0); m_emitter->setEndSpin(0); m_emitter->setEndSpinVar(2000); // color of particles ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; m_emitter->setStartColor(startColor); ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; m_emitter->setStartColorVar(startColorVar); ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; m_emitter->setEndColor(endColor); ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; m_emitter->setEndColorVar(endColorVar); // size, in pixels m_emitter->setStartSize(30.0f); m_emitter->setStartSizeVar(00.0f); m_emitter->setEndSize(kParticleStartSizeEqualToEndSize); // emits per second m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); // additive m_emitter->setIsBlendAdditive(false); setEmitterPosition(); }