swift - Changing collisionBitMask according to y value ascending or descending -


swift - spritekit

i making first game , have var player = skspritenode() , var platform = sknode()

i want detect when player increasing in y direction can turn off collisionbitmask. therefore making possible jump through platforms when jumping , when falling land on platforms.

so can have like:

if player.position.y = increasing {  player.physicsbody?.collisionbitmask = nil }else{  player.physicsbody?.collisionbitmask = physicscategory.platform } 

i have looked around , cannot find after, unless i'm looking wrong thing.

many thanks.

edit: solved check emiliopelaez answer, showing how i changed here.

declared var lasty: cgfloat? outside functions other variables.

override func update(currenttime: cftimeinterval) {         /* called before each frame rendered */         // checking y direction             if player.position.y > lasty {                 // player increasing in y direction                 player.physicsbody?.collisionbitmask = physicscategory.ground             } else {                 // player decreasing in y direction                 player.physicsbody?.collisionbitmask = physicscategory.ground | physicscategory.platform             }          lasty = player.position.y } 

basically, want compare current value value in previous frame.

the easiest way make variable can store previous value, , use comparison. once have done comparison store current value in variable used next frame.

something this:

var lasty: cgfloat?  // in function if let lasty = lasty {   if player.y > lasty {     // player.y increasing   } else {     // player.y decreasing   } } lasty = player.y 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -