swift language i wanna change the color of an object when it passes through a small 5154732

(SWIFT Language)

I wanna change the color of an object when it passes through a small vertical line, lets say a rectangle that is moving to the right from the middle left of the screen (its Xcode) and the line lies in the centre of the screen. My aim is only make the part that has collided with the vertical line change the color progressively, and the block only changes its color entirely when it has passed through the line.

I made it in a Xcode game project, created two SKShapeNode objects to test, one is the rectangular shape moving horizontally to the right and the other is a line lying in the middle of its way.9 import Spritekit 10 import Gameplay Kit class GameScene: SKScene, SKPhysicsContactDelegate { let object = SKShapeNode() let

I was expecting it to change colour of only the part that has collided with the line but as soon as the object touched the line x coordinate (at x:350, y:0) it will change the color of entire block. Does this project need to involve using BitmaskCollision? I have thought about it but it doesn't seem like that.

9 import Spritekit 10 import Gameplay Kit class GameScene: SKScene, SKPhysicsContactDelegate { let object = SKShapeNode() let stand = SKShapeNode) override func didMove (to view: SKView) { self.physicsWorld.contactDelegate = self object.path = CGPath(roundedRect: CGRect(x: 0, y: 150, width: 100, height: 60), cornerWidth: 0, cornerHeight: 0, transform: nil) object.position = CGPoint(x: 0 ,y: 640) object.fillcolor = SKColor.blue stand.path = CGPath(roundedRect: CGRect(x: 350, y: 0, width: 10, height: self.size.height*2), cornerWidth: 0, cornerHeight: 0, transform: nil) stand.fillcolor = SKColor.red let moveAction = SKAction.move(to: CGPoint(x:640, y:640), duration: 6) object.run(moveAction) self.addChild(stand) self.addChild(object) override func update current Time: Time Interval) { if object.position.x > 350{ object.fillcolor = SKColor.red

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now