ios - Is there an easy way to use decimals in calculation with SpriteKit? -


I'm new to Kit Kit and programming a program as a program to learn this.

My goal here is to get my phantom to go to the screen at random speed. This phantom is produced regularly, and it can possibly be done with maximum speed, to make the game more difficult. Should increase over time.

To do this, I am using the score, which is an integer based on time, affects the minimum duration of the movement of the phantom. The way I am trying to do this, as seen in the code below, still only produces an integer value. I would love to have more granularity than just integers.

  int rando = (arc4random ()% 150) + 50; Int denom = _scores + 50; Float Actual Duration = Rand / Dino + 1; NSLog (@ "% F", actual component); SKAction * actionMove = [SKAction moveTo: CGPointMake (-_blimp.size.width / 2, actualY) Duration: Real Component];   

I started using floating variables in response to Nielsbot's comments, and changed the structure of my code to show my changes, but I still get the integer value And for the decimals I was looking for. Does anyone know why this is the case?

Solution: Before changing them into the calculations, I changed the integer variable to float the variable. Thanks nielsbot for help!

  float actual derivation = rand / non-nominal + 1; NSLog (@ "% F", actual component);   

I'm not 100% confident in casting rules, but as far as I have experienced, what is this rando and denom integer and integer division is used, which results in an integer value.

So you have to put at least every code on float , but using the standard float notation for constants, both of them Value would be better ( 1.0f ):

  float actual quote = (float) rando / (float) denom + 1.0f; NSLog (@ "% F", actual component); Personally, I try to put all integer values ​​in float / double / CG float when used in calculation so that any of the issues of casting rule are crawled. Could   

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -