小编Dra*_*lex的帖子

不同的字符串如何具有相同的地址

我知道为了比较C中的两个字符串,您需要使用该strcmp()函数.但我试图将两个字符串与==运算符进行比较,并且它有效.我不知道如何,因为它只是比较两个字符串的地址.如果字符串不同,它应该不起作用.但后来我打印了字符串的地址:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char* str1 = "First";
    char* str2 = "Second";
    char* str3 = "First";

    printf("%p %p %p", str1, str2, str3);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出是:

00403024 0040302A 00403024
Process returned 0 (0x0)   execution time : 0.109 s
Press any key to continue.
Run Code Online (Sandbox Code Playgroud)

怎么可能str1str3具有相同的地址?它们可能包含相同的字符串,但它们不是同一个变量.

c memory string pointers

19
推荐指数
3
解决办法
2981
查看次数

类初始化中的可选参数

我正在使用Swift,Sprite-Kit和Xcode 6,

我有一个类声明如下:

class Obstacles: SKSpriteNode
{
    init(initTime: Int, speed: CGFloat, positionX: CGFloat, rotationSpeed: CGFloat)
    {
        self.initTime = initTime
        self.rotationSpeed = rotationSpeed
        self.positionX = positionX

        super.init(texture: SKTexture(imageNamed: "Rectangle"), color: SKColor.redColor(), size: CGSize(width: 20, height: 20))
        self.speed = speed
    }

    var initTime: Int
    var positionX: CGFloat
    var rotationSpeed: CGFloat = 0
}
Run Code Online (Sandbox Code Playgroud)

所以我可以像这样给这个类赋一个变量:

var myVariable = Obstacles(initTime: 100, speed: 3.0, positionX: 10.0, rotationSpeed: 0.0)
Run Code Online (Sandbox Code Playgroud)

但是,例如,如果我不想初始化rotationSpeed值并将其默认为0.0,我该如何设法这样做?我无法删除参数,这导致我错误...

initialization class init sprite-kit swift

16
推荐指数
1
解决办法
1万
查看次数

使用SpriteKit节点的路径粒子效果

我正在使用Swift,Sprite Kit和Xcode 6,

我想在SpriteKit中创建一个粒子效果,有点像iOS游戏中名为"Duet"的球的粒子效果,但我不知道如何继续,我设法创建一个粒子效果,但不是像这个游戏中的粒子跟随节点并绘制节点的路径......

这是我的代码:

let firstCircle = SKSpriteNode(imageNamed: "Circle")
let particle = SKEmitterNode(fileNamed: "FirstParticle.sks")

override func didMoveToView(view: SKView)
{
    firstCircle.physicsBody = SKPhysicsBody(circleOfRadius: 7)
    firstCircle.physicsBody?.affectedByGravity = false

    particle.targetNode = firstCircle

    addChild(firstCircle)
    addChild(particle)
}

override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
{        
    for touch: AnyObject in touches
    {
        firstCircle.position = touch.locationInNode(self)
    }
}

override func touchesMoved(touches: NSSet, withEvent event: UIEvent)
{
    for touch: AnyObject in touches
    {
        firstCircle.position = touch.locationInNode(self)
    }
}
Run Code Online (Sandbox Code Playgroud)

path particles sprite-kit skemitternode swift

13
推荐指数
1
解决办法
1675
查看次数

如何更改spritenode不透明度

我正在使用XCode 6,Sprite Kit和Swift,我有一个带有此声明的节点:

var red = SKSpriteNode(imageNamed: "Rectangle")
Run Code Online (Sandbox Code Playgroud)

我想改变节点的不透明度,但我没有找到,除了使用像FadeIn,FadeOut等SKAction ...

我尝试更改red.colorBlendFactor,但它只更改节点上新颜色的不透明度,而不是节点的不透明度...

opacity sprite-kit skspritenode swift

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

在Swift中混合使用UIColors

我有两个SKSpriteNode,它们的颜色定义如下:

colorNode[0].color = UIColor(red: 255, green: 0, blue: 0, alpha: 1)
colorNode[1].color = UIColor(red: 0, green: 255, blue: 0, alpha: 1)
Run Code Online (Sandbox Code Playgroud)

我想让第三个SKSpriteNode用前两个的混合着色,结果应该是这样的:

colorNode[2].color = UIColor(red: 255, green: 255, blue: 0, alpha: 1)
Run Code Online (Sandbox Code Playgroud)

但有没有办法添加两个UIColors?像这样 :

colorNode[2].color = colorNode[0].color + colorNode[1].color
Run Code Online (Sandbox Code Playgroud)

colors color-blending sprite-kit skspritenode swift

6
推荐指数
3
解决办法
6131
查看次数

在swift中使用哪个声明

我真的不知道如何在Swift中声明我的变量,我有四个选项:

var value = 0.0 // I know this one declares value as a Double with the number 0.0
var value: Float = 0.0 // This one declares value as a Float with the number 0.0
var value: Float? // I really don't get the difference between this
var value: Float! // and this, I just know that both of them are used to declare a variable without a value, am I right ?
Run Code Online (Sandbox Code Playgroud)

我只是想声明一个不归因于值的浮点数,最好的方法是什么?

variables declaration swift

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

Stack 中 ListView 顶部的 GestureDetector 会阻止滚动 - Flutter Web

我有一个堆栈,首先包含一个 ListView,然后是一个带有 GestureDetector 的透明小部件,可以单击它。一切正常,但是当我将鼠标放入 GestureDetector 内时,即使将behaviorGestureDetector 的属性设置为,我也无法再滚动 ListView HitTestBehavior.translucent

我理解这是因为 GestureDetector 正在吸收它,可能作为拖动事件,但我希望它只检测点击事件并让滚动事件“通过”。我怎样才能在 Flutter 中实现这种行为?

请注意,只有在使用触控板(我猜是滚轮)滚动时才会发生这种情况,但是如果您使用拖放手势滚动列表,那么即使鼠标悬停在顶部小部件上,滚动也不会停止。

我制作了一个 DartPad,因此您可以通过此链接自行测试:https://dartpad.dev/8d68891da69d661a8129d5adc7727e4c

代码也粘贴在下面:

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: StackOverflowExample()
    ));
}

class StackOverflowExample extends StatelessWidget {
  Widget _buildListItem() {
    return Container(
      margin: const EdgeInsets.symmetric(vertical: 10),
      height: 100,
      color: Colors.blue[100],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          ListView.builder(
            itemCount: 20,
            itemBuilder: (_, __) => _buildListItem(),
          ),
          Center(
            child: GestureDetector(
              behavior: HitTestBehavior.translucent,
              onTap: () …
Run Code Online (Sandbox Code Playgroud)

stack listview gesturedetector flutter flutter-web

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

Sprite Kit中的多点触控手势

我正在使用XCode 6使用Sprite-Kit在Swift中工作,我有许多不同的节点,但目前我只设法检测一个手指并同时移动一个节点.我想知道如何能够检测多个手指以便同时移动多个节点.我的实际代码是:

var location = CGFloat() // finger position
var actualNode = -1 // node touched by the finger, -1 means no node touched

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) // when a finger touch the screen
{
    for touch: AnyObject in touches
    {
        location = touch.locationInNode(self) // we detect the finger position
    } 

    for var index = 0; index < colorNode.count; index++
    {
        if nodeAtPoint(location) == colorNode[index].node
        {
            actualNode = index // the number of the node touched …
Run Code Online (Sandbox Code Playgroud)

multi-touch gesture touches sprite-kit swift

5
推荐指数
1
解决办法
5334
查看次数

SpriteKit中的摩擦力

我正在使用Swift,SpriteKit和Xcode 6,我的屏幕上有一个圆形节点,我可以用手指改变节点的位置,但我想对这个节点实施摩擦效果,但我现在不行怎么做,这是我的代码:

class PlayScene: SKScene
{    
let firstCircle = SKSpriteNode(imageNamed: "Circle")

// theses 3 variables allows me to move the node according to my finger, but my finger don't have to touch the node
var departCircleLocation = CGPoint()
var departTouchLocation = CGPoint()
var currentTouchLocation = CGPoint()

override func didMoveToView(view: SKView)
{
    addChild(firstCircle)
}

override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
{
    for touch: AnyObject in touches
    {
        departTouchLocation = touch.locationInNode(self) 
    }

    departCircleLocation = firstCircle.position
}

override func touchesMoved(touches: NSSet, withEvent …
Run Code Online (Sandbox Code Playgroud)

game-physics sprite-kit skphysicsbody swift

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

知道数组是否包含一种元素

我正在使用Swift 3和Xcode.

我有一节课:

class H: SKSpriteNode {...}
Run Code Online (Sandbox Code Playgroud)

还有一个数组:

var array = [H]()
Run Code Online (Sandbox Code Playgroud)

我想检查nodes(at:)函数是否在给定点,有一个类型为H的元素.我试过:

if nodes(at: myPoint).contains(H)
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我理解这一点.有没有办法能够知道nodes(at)函数返回的数组是否包含H类的元素?

另一个问题是,如果数组包含具有特定名称的节点,我如何检入函数返回的所有节点?

arrays contains nodes skspritenode swift

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

无法理解楼层功能的行为

我正在使用Python 2.7.13

我有这个简单的代码:

import math

a = [1,3,9,10,11,56,99,100,101,106,555,998,999,1000,1001,1102,9999,10000,10001,10002]

for i in a:
    print "%d : log : %f / floor : %f / int : %d" %(i, math.log(i,10), math.floor(math.log(i,10)), int(math.log(i,10)))
Run Code Online (Sandbox Code Playgroud)

我想尝试不同数字的日志函数,看看当我在结果上使用floor函数或将其转换为整数时会发生什么

输出是:

1 : log : 0.000000 / floor : 0.000000 / int : 0
3 : log : 0.477121 / floor : 0.000000 / int : 0
9 : log : 0.954243 / floor : 0.000000 / int : 0
10 : log : 1.000000 / floor : 1.000000 …
Run Code Online (Sandbox Code Playgroud)

python math casting floor python-2.7

0
推荐指数
1
解决办法
68
查看次数