小编Hil*_*404的帖子

如何使用关卡游戏场景的屏幕截图替换关卡按钮图像?

我知道如何拍摄并将截图保存到照片库.我使用下面的代码执行此操作.我想用我的gameScene的屏幕截图替换我的关卡场景按钮图像.说我的图像按钮是150x150.我怎样才能做到这一点?

    func takeScreenShot(scene:SKScene)  {
    let bounds = self.scene!.view?.bounds
    UIGraphicsBeginImageContextWithOptions(/*CGRect(x: 0, y: 0, width: 100, height: 100).size*/bounds!.size, true, UIScreen.main.scale)
    self.scene?.view?.drawHierarchy(in: bounds!, afterScreenUpdates: true)
    let screenshot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(screenshot!, nil, nil, nil)

}


class LevelSelectScene: SKScene {

let button1: SKSpriteNode = SKSpriteNode(imageNamed: "image1")
let button2: SKSpriteNode = SKSpriteNode(imageNamed: "image2")
let button3: SKSpriteNode = SKSpriteNode(imageNamed: "image3")

                    ...

override init(size: CGSize){
super.init(size: size)

button1.position = CGPoint(x: self.frame.width/4, y:  self.frame.height/2)
self.addChild(button1)

button2.position = CGPoint(x: self.frame.width/2, y:  self.frame.height/2)
self.addChild(button2)

button3.position = CGPoint(x: 3*self.frame.width/4, y:  self.frame.height/2) …
Run Code Online (Sandbox Code Playgroud)

screenshot uiview sprite-kit swift3

7
推荐指数
1
解决办法
226
查看次数

随着利润增加,如何在止损和当前价格之间保持10点的利润差距

我想另一个条件添加到该解决方案在这个岗位。我希望当交易获利10点时,止损将增加10点。更具体地说,假设我已经设置了一个待处理的买单,止损位比开盘价低10点,止盈位为50点。如果交易获利10个点,那么止损将向上移动10个点,如果交易获利为20个点,则止损将向上移动另一个10个点,而当交易获利30和40个点时,同样会发生直到达到50点止盈为止。这里的想法是,止损会增加10个点,而利润会增加10个点,但是止损不会下降。因此,如果止损为获利10个点,而价格为获利23个点并且突然下降,它将以10个止损获利退出交易。

设置以上条件对我来说似乎很复杂。我还没完成。

以下是我要解决的代码的相关部分(请注意,其余代码与上述链接的问题解决方案相同)。

//=========================================================
    //CLOSE EXPIRED STOP/EXECUTED ORDERS
    //---------------------------------------------------------
    for( int i=OrdersTotal()-1; i>=0; i-- ) {
        if(OrderSelect( i, SELECT_BY_POS, MODE_TRADES ))
            if( OrderSymbol() == Symbol() )
                if( OrderMagicNumber() == viMagicId) {
                    if( (OrderType() == OP_BUYSTOP) || (OrderType() == OP_SELLSTOP) )
                        if((TimeCurrent()-OrderOpenTime()) >= viDeleteStopOrderAfterInSec)
                            OrderDelete(OrderTicket());

                    if( (OrderType() == OP_BUY) || (OrderType() == OP_SELL) )
                        if((TimeCurrent()-OrderOpenTime()) >= viDeleteOpenOrderAfterInSec) {
                            // For executed orders, need to close them
                            double closePrice = 0;
                            RefreshRates();
                            if(OrderType() == OP_BUY)
                                closePrice  = Bid;
                            if(OrderType() == …
Run Code Online (Sandbox Code Playgroud)

trading algorithmic-trading metatrader4 mql4

7
推荐指数
1
解决办法
267
查看次数

如何按照最常见的点排列CGPoint阵列

我看到这篇帖子 展示了如何通过以下方式获得数组的最常值:

let myArray = [4, 4, 4, 3, 3, 3, 4, 6, 6, 5, 5, 2]

// Create dictionary to map value to count   
var counts = [Int: Int]()

// Count the values with using forEach    
myArray.forEach { counts[$0] = (counts[$0] ?? 0) + 1 }

// Find the most frequent value and its count with max(isOrderedBefore:)    
if let (value, count) = counts.max(isOrderedBefore: {$0.1 < $1.1}) {
    print("\(value) occurs \(count) times")
}
Run Code Online (Sandbox Code Playgroud)

我想为一个数组实现相同的结果CGPoints,这有点不同.我尝试使用相同的代码并得到一个错误:

Type 'CGPoint' does …
Run Code Online (Sandbox Code Playgroud)

arrays sorting mapping swift3

6
推荐指数
1
解决办法
157
查看次数

如何为每个象限创建一个圆形末端的圆

我创建了一个分为象限的圆圈.我试图让每个象限的末端四舍五入,每个象限之间有一个给定的间隙,但我得到了一些奇怪的行为.我想我错过了一些东西.下面是我得到的图像和相关代码.我希望结局类似于Apple Watch活动环.

在此输入图像描述

class GameScene: SKScene {

let radius = CGFloat(100)
var topRightPathNode : SKShapeNode!
var bottomRightPathNode : SKShapeNode!
var bottomLeftPathNode : SKShapeNode!
var topLeftPathNode : SKShapeNode!

override func didMove(to view: SKView) {

}


override init(size: CGSize) {
    super.init(size: size)
    let topRightPath = arcSegment(center: CGPoint.zero, radius: radius, strokeWidth: 18, gapWidth: 6)

    // TOP RIGHT


    topRightPathNode = SKShapeNode(path: topRightPath)
    topRightPathNode.fillColor = SKColor.white
    topRightPathNode.lineWidth = 0
    topRightPathNode.position = CGPoint(x: 320, y: 240)
    addChild(topRightPathNode)


    // BOTTOM RIGHT

    var reflectOnY = CGAffineTransform(scaleX: 1.0, y: -1.0) …
Run Code Online (Sandbox Code Playgroud)

sprite-kit skshapenode swift swift3

6
推荐指数
1
解决办法
590
查看次数