public override void ccTouchMoved(CCTouch touch, CCEvent parmevent) { CCPoint touchLocation = touch.locationInView(touch.view()); CCPoint prevLocation = touch.previousLocationInView(touch.view()); touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); prevLocation = CCDirector.sharedDirector().convertToGL(prevLocation); CCPoint diff = new CCPoint(touchLocation.x - prevLocation.x, touchLocation.y - prevLocation.y); CCNode node = getChildByTag(1); CCPoint currentPos = node.position; node.position = new CCPoint(currentPos.x + diff.x, currentPos.y + diff.y); }
public override void ccTouchesMoved(List <CCTouch> pTouches, CCEvent pEvent) { CCTouch touch = pTouches.FirstOrDefault(); CCPoint touchLocation = touch.locationInView(touch.view()); touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); float nMoveY = touchLocation.y - m_tBeginPos.y; CCPoint curPos = m_pItmeMenu.position; CCPoint nextPos = new CCPoint(curPos.x, curPos.y + nMoveY); CCSize winSize = CCDirector.sharedDirector().getWinSize(); if (nextPos.y < 0.0f) { m_pItmeMenu.position = new CCPoint(0, 0); return; } if (nextPos.y > ((m_nTestCount + 1) * LINE_SPACE - winSize.height)) { m_pItmeMenu.position = new CCPoint(0, ((m_nTestCount + 1) * LINE_SPACE - winSize.height)); return; } m_pItmeMenu.position = nextPos; m_tBeginPos = touchLocation; }
public override void ccTouchesBegan(List <CCTouch> pTouches, CCEvent pEvent) { CCTouch touch = pTouches.FirstOrDefault(); m_tBeginPos = touch.locationInView(touch.view()); m_tBeginPos = CCDirector.sharedDirector().convertToGL(m_tBeginPos); }
public override void ccTouchesEnded(List <CCTouch> touches, CCEvent event_) { //base.ccTouchesEnded(touches, event_); object it = touches.First(); CCTouch touch = (CCTouch)(it); CCPoint location = touch.locationInView(touch.view()); CCPoint convertedLocation = CCDirector.sharedDirector().convertToGL(location); CCNode s = getChildByTag(ClickAndMoveTest.kTagSprite); s.stopAllActions(); s.runAction(CCMoveTo.actionWithDuration(1, new CCPoint(convertedLocation.x, convertedLocation.y))); float o = convertedLocation.x - s.position.x; float a = convertedLocation.y - s.position.y; float at = (float)(Math.Atan(o / a) * 57.29577951f); if (a < 0) { if (o < 0) { at = 180 + Math.Abs(at); } else { at = 180 - Math.Abs(at); } } s.runAction(CCRotateTo.actionWithDuration(1, at)); }
public override void ccTouchesMoved(List <CCTouch> pTouches, CCEvent pEvent) { foreach (var it in pTouches) { CCTouch touch = it; CCPoint touchLocation = touch.locationInView(touch.view()); touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); float nMoveY = touchLocation.y - m_tBeginPos.y; CCPoint curPos = m_pItmeMenu.position; CCPoint nextPos = new CCPoint(curPos.x, curPos.y + nMoveY); CCSize winSize = CCDirector.sharedDirector().getWinSize(); if (nextPos.y < 0.0f) { m_pItmeMenu.position = new CCPoint(0, 0); return; } if (nextPos.y > ((BugsTestScene.MAX_COUNT + 1) * BugsTestScene.LINE_SPACE - winSize.height)) { m_pItmeMenu.position = new CCPoint(0, ((BugsTestScene.MAX_COUNT + 1) * BugsTestScene.LINE_SPACE - winSize.height)); return; } m_pItmeMenu.position = nextPos; m_tBeginPos = touchLocation; BugsTestScene.s_tCurPos = nextPos; } }
public override void ccTouchesMoved(List <CCTouch> pTouches, CCEvent pEvent) { CCTouch touch = pTouches.FirstOrDefault(); CCPoint touchLocation = touch.locationInView(touch.view()); touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); float nMoveY = touchLocation.y - m_tBeginPos.y; CCPoint curPos = this.position; CCPoint nextPos = new CCPoint(curPos.x, curPos.y + nMoveY); CCSize winSize = CCDirector.sharedDirector().getWinSize(); if (nextPos.y < 0.0f) { this.position = new CCPoint(0, 0); return; } if (nextPos.y >= m_TotalHeight) { this.position = new CCPoint(0, m_TotalHeight); return; } this.position = nextPos; m_tBeginPos = touchLocation; s_tCurPos = nextPos; }
public override void ccTouchesBegan(List <CCTouch> pTouches, CCEvent pEvent) { foreach (var it in pTouches) { CCTouch touch = it; m_tBeginPos = touch.locationInView(touch.view()); m_tBeginPos = CCDirector.sharedDirector().convertToGL(m_tBeginPos); } }
public void ccTouchesMoved(List <CCObject> touches, CCEvent events) { foreach (var it in touches) { CCTouch touch = (CCTouch)it; CCPoint start = touch.locationInView(touch.view()); start = CCDirector.sharedDirector().convertToGL(start); CCPoint end = touch.previousLocationInView(touch.view()); // begin drawing to the render texture //m_pTarget->begin(); // for extra points, we'll draw this smoothly from the last position and vary the sprite's // scale/rotation/offset float distance = CCPointExtension.ccpDistance(start, end); if (distance > 1) { int d = (int)distance; Random rand = new Random(); for (int i = 0; i < d; i++) { float difx = end.x - start.x; float dify = end.y - start.y; float delta = (float)i / distance; m_pBrush.position = new CCPoint(start.x + (difx * delta), start.y + (dify * delta)); m_pBrush.rotation = rand.Next() % 360; float r = (float)(rand.Next() % 50 / 50.0f) + 0.25f; m_pBrush.scale = r; /*m_pBrush->setColor(ccc3(CCRANDOM_0_1() * 127 + 128, 255, 255));*/ // Use CCRANDOM_0_1() will cause error when loading libtests.so on android, I don't know why. m_pBrush.Color = new ccColor3B { r = (byte)(rand.Next() % 127 + 128), g = 255, b = 255 }; // Call visit to draw the brush, don't call draw.. m_pBrush.visit(); } } } // finish drawing and return context back to the screen //m_pTarget->end(); }
public override void ccTouchesMoved(List <CCTouch> touches, CCEvent event_) { var it = touches.FirstOrDefault(); CCTouch touch = (CCTouch)(it); CCPoint touchLocation = touch.locationInView(touch.view()); touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); m_streak.position = touchLocation; }
public void updateSize(CCTouch touch) { CCPoint touchLocation = touch.locationInView(touch.view()); touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); CCSize s = CCDirector.sharedDirector().getWinSize(); CCSize newSize = new CCSize(Math.Abs(touchLocation.x - s.width / 2) * 2, Math.Abs(touchLocation.y - s.height / 2) * 2); CCLayerColor l = (CCLayerColor)getChildByTag(kTagLayer); l.contentSize = newSize; }
public override void ccTouchEnded(CCTouch touch, CCEvent eve) { CCPoint location = touch.locationInView(touch.view()); CCPoint convertedLocation = CCDirector.sharedDirector().convertToGL(location); CCPoint pos = new CCPoint(0, 0); if (m_background != null) { pos = m_background.convertToWorldSpace(new CCPoint(0, 0)); } m_emitter.position = CCPointExtension.ccpSub(convertedLocation, pos); }
public override void ccTouchesMoved(List <CCTouch> touches, CCEvent events) { foreach (var it in touches) { CCTouch touch = it; CCPoint start = touch.locationInView(touch.view()); start = CCDirector.sharedDirector().convertToGL(start); CCPoint end = touch.previousLocationInView(touch.view()); end = CCDirector.sharedDirector().convertToGL(end); // begin drawing to the render texture //m_target->begin(); // for extra points, we'll draw this smoothly from the last position and vary the sprite's // scale/rotation/offset float distance = CCPointExtension.ccpDistance(start, end); if (distance > 1) { int d = (int)distance; Random rand = new Random(); ; for (int i = 0; i < d; i++) { float difx = end.x - start.x; float dify = end.y - start.y; float delta = (float)i / distance; m_brush.position = new CCPoint(start.x + (difx * delta), start.y + (dify * delta)); m_brush.rotation = rand.Next() % 360; float r = ((float)(rand.Next() % 50) / 50.0f) + 0.25f; m_brush.scale = r; // Call visit to draw the brush, don't call draw.. m_brush.visit(); } } // finish drawing and return context back to the screen //m_target->end(false); } }
public virtual void ccTouchMoved(CCTouch touch, CCEvent eventer) { // If it weren't for the TouchDispatcher, you would need to keep a reference // to the touch from touchBegan and check that the current touch is the same // as that one. // Actually, it would be even more complicated since in the Cocos dispatcher // you get CCSets instead of 1 UITouch, so you'd need to loop through the set // in each touchXXX method. Debug.Assert(m_state == PaddleState.kPaddleStateGrabbed, "Paddle - Unexpected state!"); CCPoint touchPoint = touch.locationInView(touch.view()); touchPoint = CCDirector.sharedDirector().convertToGL(touchPoint); base.position = new CCPoint(touchPoint.x, base.position.y); }
public override void ccTouchesMoved(List <cocos2d.CCTouch> touches, cocos2d.CCEvent event_) { CCSize s = CCDirector.sharedDirector().getWinSize(); var it = touches.FirstOrDefault(); CCTouch touch = (CCTouch)(it); CCPoint start = touch.locationInView(touch.view()); start = CCDirector.sharedDirector().convertToGL(start); CCPoint diff = new CCPoint(s.width / 2 - start.x, s.height / 2 - start.y); diff = CCPointExtension.ccpNormalize(diff); CCLayerGradient gradient = (CCLayerGradient)getChildByTag(1); gradient.Vector = diff; }
public override void ccTouchesEnded(List <CCTouch> touches, CCEvent event_) { actor.actack(); base.ccTouchesEnded(touches, event_); CCTouch touch = touches.FirstOrDefault(); CCPoint location = touch.locationInView(touch.view()); location = CCDirector.sharedDirector().convertToGL(location); //set up initial location of projectile CCSize winSize = CCDirector.sharedDirector().getWinSize(); CCSprite projectile = CCSprite.spriteWithFile(@"sprites/hamberger"); projectile.position = new CCPoint(actor.position.x, actor.position.y + 20); this.addChild(projectile); float offX = location.x - projectile.position.x; float offY = location.y - projectile.position.y; offY -= 30; float realX = winSize.width + projectile.contentSize.width / 2; float ratio = offY / offX; float realY = realX * ratio + projectile.position.y; realY -= 30; CCPoint realDest = new CCPoint(realX, realY); //Determine the length of how far we're shooting float offRealX = realX - projectile.position.x; float offRealY = realY - projectile.position.y; offRealY -= 30; float length = (float)Math.Sqrt(offRealX * offRealX + offRealY * offRealY); float velocity = 480 / 1;//480pixls/lsec float realMoveDuration = length / velocity; //Move projectile to actual endpoint projectile.runAction(CCSequence.actions(CCMoveTo.actionWithDuration(realMoveDuration, realDest), CCCallFuncN.actionWithTarget(this, spriteMoveFinished))); }