+ 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?

6th Apr 2019, 1:48 AM
Ryoba
Ryoba - avatar
2 Antworten
+ 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.
6th Apr 2019, 4:24 AM
Sarthak Pokhrel
Sarthak Pokhrel - avatar
0
while (You are a developer) { Google is your friend }
3rd Nov 2020, 7:34 PM
Anis
Anis - avatar