Hundreds of features to explore
Games made in Construct
Your questions answered
Trusted by schools and universities worldwide
Free education resources to use in the classroom
Students do not need accounts with us
What we believe
We are in this together
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
Hey all, I was reading through the manual and came across "clamp" where x is returned if under a value, above a value - or else return x....
I just don't understand why something would require this. It seems like x is chosen every time from the 3 values. Am I misunderstanding the way this is written? Can someone help me with a practical application of clamp?
Suppose you want a sprite to only move horizontally in a set range of x coordinates, a line if you will.
Always sprite set x to clamp(self.x, 10, 100)
That event will make it stay within 10 to 100 x.
Develop games in your browser. Powerful, performant & highly capable.
If x is less than the lower bound it returns the lower bound, if it's higher than the upper bound then it returns the upper bound and if x is between lower and upper it returns x.
Say you wanted to keep the player health between 0 and 100. You could set
playerHealth = clamp(playerHealth + x, 0, 100)[/code:32whohz9]
where x is could be +50 for a health kit or -25 for an enemy attack and the result will always be between 0 and 100. If playerHealth + x goes above 100 then playerHealth gets set to 100. If it goes below 0 then playerHealth gets set to 0.
Oh, that's pretty neat! Thanks for explaining that newt and ramones !