I'm using SpriteKit and working on a system of moving SKSpriteNodes around the screen. I have two global variables that are set before the moving method is called: positionAndMovementX and positionAndMovementY which I have tried as both integers and floats. Before the method that moves my SKSpriteNode is called, both of these variables will be set to either 0, 80, or -80. Then I run:
if (emptySpace.position.x == yellowBug.position.x + positionAndMovementX &&
emptySpace.position.y == yellowBug.position.y + positionAndMovementY)
{
SKAction *moveLeft = [SKAction moveByX:positionAndMovementX y:positionAndMovementY duration:.1];
[yellowBug runAction: moveLeft];
}
Unfortunately, this will work for several movements, but after 5 or so, either the x or the y value will become inexact and decrease or increase by .000015 or something, so now instead of being 200, 180, its 200, 179.999985, and my equation wont evaluate anymore. I tried changing the position to an integer and back, but 179.999985 was changed to 179 instead of 180 for some reason, so i tried rounding as follows:
int posX = lroundf(yellowBug.position.x);
int posY = lroundf(yellowBug.position.y);
[yellowBug setPosition:CGPointMake(posX, posY)];
but this just seems to leave the variable at 179.999985 again... Help? (sorry if this is a noob question, im still a beginner)