+ 1
How do you code for objects in javascript
Im makeing a game and i need objects like knifes and phones. Any tips or ideas?
2 Answers
+ 6
If you are talking about objective programming then,
It depends on the programming language you're using. For game development, you need to create object setting their properties to be shown in game and the methods of object should be according what they have role in the game.
For example:(JavaScript)
var knife= {
length:100,
sharpness: 1,
color:"red",
cut: function(obj) {
return "Knife is cutting "+obj
}
}
In above 'knife' object defination, we have set properties like length, color which are visible properties of knife in game.
Likewise, the method 'cut' if is executed with "apple" as parameter, returns "Knife is cutting apple".
lets see an example:
console.log(knife.color)//outputs red
console.log(knife.cut("mangoes"))//outputs knife is cutting mangoes
If you have any other confusion then please reply me. I do follow this post.
0
while (You are a developer) {
Google is your friend
}