但是,放大2D圖像,從圖像中心點放大。我需要它從一個特定的座標擴大?
[backgroundImage setScale:rifleZoom];
我目前的技術來擴大形象。
我需要從屏幕中心擴展,而不是居中圖像
現在我的方式放置在屏幕上@中心步槍射擊是這樣:
CGPoint positionNow = CGPointMake(backgroundImage.position.x, backgroundImage.position.y);
CGPoint positionPrev = CGPointMake(0.5, 0.5);
float xdiff = positionNow.x - positionPrev.x;
float ydiff = positionNow.y - positionPrev.y;
CGPoint newPositionOne = CGPointMake(0.5- xdiff, 0.5 - ydiff);
newPositionOne = CGPointMake(newPositionOne.x/rifleZoom, newPositionOne.y/rifleZoom);
現在這不完美的作品不管怎樣,圖像縮放多少。我似乎無法實現它將圖像從與圖像中心相對的屏幕中心向上縮放。
縮放來之前我已經試過
我試圖改變圖像的位置。與newPositionOne
相同的點,但是,這不起作用或沒有正確完成。
編輯
這種規模和帶來的中心屏幕中心點,或完全攪亂。這是一個有點太離譜,做出決定到底是做什麼。
CGPoint positionNow = CGPointMake(backgroundImage.position.x, backgroundImage.position.y);
CGPoint positionPrev = CGPointMake(0.5, 0.5);
float xdiff = positionNow.x - positionPrev.x;
float ydiff = positionNow.y - positionPrev.y;
CGPoint newPositionOne = CGPointMake(0.5- xdiff, 0.5 - ydiff);
newPositionOne = CGPointMake(newPositionOne.x/rifleZoom, newPositionOne.y/rifleZoom);
double xPosition = newPositionOne.x/backgroundImage.size.width;
double yPosition = newPositionOne.y/backgroundImage.size.height;
CGPoint prevAnchorPoint = backgroundImage.anchorPoint;
backgroundImage.anchorPoint = CGPointMake(xPosition,yPosition);
double positionX = backgroundImage.position.x + (backgroundImage.anchorPoint.x - prevAnchorPoint.x) * backgroundImage.size.width;
double positionY = backgroundImage.position.y + (backgroundImage.anchorPoint.y - prevAnchorPoint.y) * backgroundImage.size.height;
backgroundImage.position = CGPointMake(positionX,positionY);
[backgroundImage runAction:[SKAction repeatAction:[SKAction scaleTo:rifleZoom duration:1.0] count:1]];
我也嘗試過,現在的定位點,但有錨點必須保持中央的形象,因爲這是節點如何加入。但是在縮放時,我需要將焦點集中在zomming的中心點上,iPhone屏幕居中,而不是圖像的中心。 – user2415313 2015-02-11 14:25:02