1 decade ago
by Alex
Hello,
Did anyone built an inventory? I'm planning on doing one, want to hear some suggestions/ideas from people who did/tried. Thanks!
I will also do this. Is it best to put global variables (that will be used throughout the game like inventory) in main.js or game.js?
i would put it in main.js
1 decade ago
by MikeL
I have been creating a custom class, which I call "PlayerController", that handles player-specific items, i.e. lives, points. This could also handle inventory. Keeps things a bit more organized. My PlayerController keeps in contact with the actual EntityPlayer.
The PlayerController is created in my main.js and tracked there. Here is an example of the
PlayerController code. Here is the
main.js so you can see how it's handled.
That PlayerController code is excellent. Thanks for sharing all your plug-ins.
1 decade ago
by Alex
Thanks MikeL!
However, I was more concerned about how to make it mobile/pc friendly with dragging. And how would you draw the inventory itself? Entities? I have no idea, suggestions welcomed :)
1 decade ago
by MikeH
I have an 'Inventory' entity which sits off screen and when the game switches into inventory mode, is brought on screen. All the items in the inventory are spawned and placed over the entity so it looks like it's holding them.
Dragging is easy, when your mouse input is pressed, you check to see if the x,y is over an inventory item (I made all my inventory items subclass InventoryItem to make it easy to check them all) and check which item satisfies item.pos.x < x < item.pos.x+item.size.x and item.pos.y < y < item.pos.y+item.size.y. Then you know which one you're dragging, you can move all the inventory stuff off screen and switch into placing_item mode, or whatever yuo want to do with the item you selected.
1 decade ago
by Colin
Thanks for posting the PlayerController code, it is super useful!
Yeah that PlayerController kicks ass! I see now how to handle multiple game states and draw the backgrounds separately for transitions. Feel like I've been using a sledgehammer instead of a Swiss Army knife.
Page 1 of 1
« first
« previous
next ›
last »