Inventory Setup | Farming RPG Tutorial: GMS2 [P14]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys so we're finally starting our inventory today which is really exciting it's a really fun element to program and obviously an extremely important mechanic to the game and now again although this is obviously part of the farming RPG series we won't really be relying on any previous elements from previous episodes to make our inventory system so if you haven't seen any of those and you've just come here wondering how to make an inventory that's totally fine we're gonna be adding totally new objects and data structures to build our inventory over the next few episodes alright so let's get started now our goal for today is to get most of the inventory set up so this is what we should be getting by the end so here is the inventory user interface drawing right which is just this box with the three tabs and this kind of breaks up the inventory into three sections so let's hop here in the first tab is the player information we've got a name where we can share our player's name we've got some gold silver and copper with some numbers showing you how much of each coin that we have so that's one section next and probably the most important part is their actual inventory so you can see here it's got 24 slots with three rows of eight and I've just filled it with a random assortment of items and if I restart the game you can see that randomized all the spots as well as the money actually as an aside I've put links to all of the sprites for this in the description but you should also be able to use your own sprites for all of this and make the inventory any size or number of slots that you want you just have to change a couple calculations that we do but don't worry I'll point all of that out anyway so that's the second part and then finally down here this is where we're going to put the description for the items so we won't actually get to that today we'll be doing that next time but just keep those sections in mind so like I said we're just gonna be concentrating on the first two sections today and if you hadn't guessed it already we're going to be using data structures to store the information for each of these so in the first section with the player information we're going to be making a grid data structure so it's gonna have a width of 2 and a height of 4 and these numbers here they just represent the coordinates of the grid so this cell here is 0 0 the cell here is 1 2 so just like with a lot of our other data structures that we've already made each is going to be representing a different kind of object or information so this first row here this is going to be about gold so the cells e-reserve we're gonna be storing just the string gold and then in 1 0 we're gonna store the amount of gold that we have obviously this could be any number I've just put in 1 and this cell here is gonna be the one that we're most interested in it's gonna be the one we're probably gonna use the most and when we're actually getting to the code so we'll be changing this cell if we acquire or spend gold this one here is sort of less useful but it might come up sometimes and the reason I even want to store this string gold at all is so that we can refer to it in things like conversations or as a notification for when we pick up the gold alright and in the next couple rows the silver and the copper is exactly the same and finally in the next part we just have the name string and player again for the same reasons as all of these and we'll allow the player to change this value themselves eventually and we might add more things to this player information grid a bit later or you might want to do it right now but this is all I'm going to be doing all right now for the inventory so here is basically what our inventory grid is going to look like it's gonna have width of 2 and its height is gonna be however many slots that you want in your inventory I'm just using eight as an example so each row represents a new item and this column the first column is going to store what kind of item that it is so basically each item type is going to be represented as a number so five might be carrot seven might be Persian whatever they're all just going to be represented by numbers and in the second column here this is just going to be how many of each item that we have and this all looks pretty incomprehensible to the human eye right so to help us out a bit we're going to declare all our item indexes using an enumerator so we've done this before and it's gonna be pretty much the same so we're calling this enumerator item and then we're gonna list all of the items that we have here and importantly we have the very first item is actually going to be none and it's going to be equal to zero and this is important because we're gonna set the inventory slot to this item when it has nothing in it so we do need a kind of empty slot and then we just number all of items sequentially after that now this if you recall is just the way that an enumerator will assign entries their values even if you don't put equals something here right it'll just make it equal to zero one two three four five blah so if I written this instead it would be exactly the same but I am actually going to keep it like this in the inventory because if you imagine that we have say a hundred different items you can't really tell at a glance what starfish is gonna be especially for like 50 items sound but this way we can see what age number is equal to so remember this was our inventory and instead of just these numbers we could put this right there exactly equivalent so this is how we access the constants in our enumerator we just put item dot and then whatever the item was right so item duck corn is exactly the same it's just writing to now finally even though we're setting up the inventory in a kind of list fashion right sorry it's just coming straight down with each row being a new item that doesn't mean our actual inventory is necessarily gonna look like this you can do it that way if you want but we're gonna set it up so that you can specify how many rows and columns are in the actual inventory so even though we have eight slots here in RDS inventory grid you could for example make an inventory like this so while the data structure has a height of 8 and a width of 2 we can have our inventory itself being a different width in height so we're actually going to use some variables to set this up so we're going to have inventory slots and that's just gonna be however many slots you have available for your inventory obviously this is going to be the same as the height of the grid and then we're going to declare a width and a height and that will determine the actual inventory that the player sees so hopefully that gives you an idea of what we're going to be doing let's jump into the code and get started all right so the first thing I'm going to do is import those sprites so I'm going to make a new sprite group called inventory so this one is a user interface UI sprite so this is going to have if we just go into it the actual kind of inventory menu thing right and that's basically all of this right here and as you can see these squares here they look a little bit different to what I showed it in the preview right and this is if you wanted to do something like say give the player only eight inventory items at the start the rest are going to appear like this and what we're actually going to do is we're going to manually draw on how many inventories thoughts the player actually has on top of these and as you can see as well I've actually just put the coins directly on top of this sprite as well and actually that's a bit of space here sir in the spy that I'll give to you I'll actually get rid of this all right so that's the UI sprite and we can just leave it there it doesn't really matter where its origin is let's do the rest so let's grab B items now and if I just go into this one so as you can see I haven't put many items in here and I've made these by pretty big just in case you wanted to put lots more in or if we put some more in in the coming tutorials and basically each item is gonna take up 32 pixels so if you turn on the grid and then you type 32 by 32 here you can see each of the items like this now it's important that we leave the first one blank because this is gonna be our no items because remember the item none in our numerator that's kind of like that our first item and then tomorrow then will be equal to one potato will be equal to two and so on the other thing that I've just made sure to do is that I put enough items in the sprite so that it's going down to the second line because I just want to make sure that our maths works out a little bit later all right so that is our items all right last one this is gonna be our coins and we're not actually going to use this one this time we'll use it in the next one but we might as well just import it now and if you just take a note of what it's cold right here so it's SPR all coins and then it says strip hate and see this is just one big picture but if I import it it automatically splits it up for me into eight sort of frames and how I play it for you right here you can see they're just sort of spinning around and we'll use that for the actual coin items that we'll put into the game world so that we can get some money all right again I'm just trying to keep everything as kind of compact as possible because I know we're running kind of low on the amount of sprites you have if you have the demo version of game makers or trying to reduce the number of sprites wherever possible alright so that's it for our sprites now we can go ahead and make our inventory object so it's going to be one of our special sort of meta system objects so we'll put it here create a new object and we'll call it inventory and just like these ones it's also going to be persistent and before we forget let's just add it to our initializing room now one more thing if you recall everything in this instance is layer it has a depth of zero right and if you remember that our de cycle also exists at this depth which means it's going to be drawing the lighting at this depth but we want our inventory to be appearing on top of the day cycle I don't want the light to be drawn on top of the user interface so what I'm actually gonna do and we might change this later when we have a few more things set up like the tech system but it is creative and I'm just gonna immediately just type depth equals to minus 1 just so that it is gonna be on top of the lighting right because if we have a lower depth that means we're closer to the screen so we're not as deep basically all right so now we can get started setting up our inventory now first up but start up simple and just get the UI back of the inventory to draw so we're actually going to be drawing everything in the draw GUI layer just so that we don't have to correct for the view all the time as we would have to win the draw layer but because the draw GUI is unscaled right it doesn't get scaled like the rest of our game does as we've discussed in earlier episodes we're gonna have to scale up the inventory for it to look correct for us and if you remember if we just come into one of our rooms like the farm room and come into the viewports so here this was the size of our viewport and this was the size of our room so the actual room that it's drawing is actually half the size of the actual viewport which means it's scaling it up by a factor of two so we're also going to want to scale the inventory by two and to be honest we are going to change a lot of the camera later we might end up having to change that scaling factor but for now in the create event I'm gonna make a variable called scale and set this to two if you're using a different resolution obviously you're gonna have to correct for that alright next sir because of how I set this sprite up I don't want to be drawing the entire sprite but because that would draw this bit right here I don't want to draw any of that I just want to draw this and this thing right here as you can see it's got a width of 288 and a height of 192 so basically we want to only draw a part of the sprite starting from here and just so love that so in the drug GUI event let's draw let's draw part of the sprite and we could just name the sprite here but what I'm gonna do is I'm actually going to have variables that hold all of my sprites and that's just because I'm going to be referring to them multiple times so whenever I'm drawing for example 24 or Fe's I'm going to keep referring to the sprite here and so I'm actually just going to store this sprite in a variable called SPR hmm UI right and so we'll refer to that so the self-image that we have to give it is just zero there's only one frame in that sprite that we had this left and top is gonna refer to where we're starting to draw if you just middle click on this it'll bring up the documentation on that and you can see right here it's the exposition on the sprite off the top left corner of the area to drop so if you remember that was 32 over this coordinate right here and actually instead of just using 32 so just in case you're using some different sprites I'm going to make another variable called cell size and this is going to be equal to 32 and this will be equal to not only the size of this thing which is just the slots but it's also going to be the size of your items all right so now the top is just gonna be zero it was right at the top and now the actual width and height of that inventory so it's just going to be those numbers I said before so again we're going to set up some more variables so if you eye width right and that is the area that we want to draw so the width and height of that area all right and now we have to give it an X and Y location to draw the inventory so now I'm rooms who draw my inventory so that it's right in the center so we're gonna have to do is get the width and height of the GUI layer and then just have those so again we come into the creative end and we'll make a couple variables and I'll just put it here so if we have these two values that's going to put it right in the center but if we start drawing there that's going to be the corner of the inventory so the corner will be in the center so but to correct for that we're gonna need two minus half of the inventory qy with and minus half of its height as well and then it'll be in the center but actually it's not even as simple as that because we're gonna have to correct for this scale variable so if we're scaling it by two then the entire thing that we're drawing is going to take up twice as much room so we need it to move two times half its width and two times half its height so again we need some more variables so I'm gonna have an in UI x position 3 with x point 5 or do it with over to whatever you want and then half of the inventory width and then again times the scale and that will get us the number we want and we want to do the same for the why just with the height all right and now we can put these values into here and now so for the X scale and the Y scale we're just going to put our scale variable this is turning out to be quite a long line you might want to put it over several lines or something like this if you want to see it all and finally so the color which is like the image blend so if you wanted to blend it green or something for some reason then you would put that in here but we don't want to do any of that so we just put white which is the default and finally the alpha which is just going to be one okay so if we run the game now we should get our inventory to draw there we go good okay one other quick thing we'll do is actually we'll just make it to that if we tap the I key we'll toggle the inventory being drawn or not so whenever I hit I it will make the inventory come up or go away so we will create a variable called show inventory and I'll start it off as true for the purposes of testing right now so it should it be appearing and in the step event we'll say if we press the i key then we're gonna make whatever this is currently equal to so true or false it's going to equal not whatever its equal to so if it's currently true then it's going to make it equal not true and vice versa so it's just going to keep toggling and then in here we'll say at the very top if not sure inventory so if this is false then we're just gonna exit I'm not gonna do any of this so just real quick if we just test that and I yep perfectly okay let's keep doing else I don't know so now let's draw that player information stuff so down here we will start setting up playa infer all right and so we're gonna make our data structure here with our gold silver copper and named variables if you remember and you don't have to put this but just so that you remember remember our first row was going to be the gold the second row was the silver bronze and then the name okay so let's create a grid called dias player info DSS for data structure dear screwed create so a width of 2 and a height of 4 or if you're adding other pieces of information then increase this value accordingly and now let's go ahead and just fill the grid with the values that we want so we use our access it here to access the cell that has whatever coordinates that we put in here so the very top left cell the very first cell which has the coordinates 0 0 we're going to put our gold string in and then the cell right beneath it we put the silver string and we keep going just like that all right and now for this next bit so for our second column so the x-values will now be 1 instead of 0 so we'll just copy this and then change the x-values to 1 so for name we put whatever name you want your character to have I'm just gonna put player and you can put whatever values you want here but I'm actually just gonna randomize it to make it a little bit more interesting so I'm gonna give it a random value and because I put I here this means integer so it's gonna be a whole number and then we give it a range so between two numbers and I'm gonna give it between 0 and 99 and I'm just going to do that for all all of these all right so we have created and filled a grid and actually before we forget because we have created a data structure and game maker does not delete data structures unless we tell it to we have to remember to destroy it in the event that the inventory is destroyed so if the game ends or if this object gets destroyed but we can just use the cleanup event instead of creating those events individually so we go d/s grid destroy player info all right so now we need to actually draw this stuff to the screen so let's just start with the name so let's create an x and y location for the info as well so it's going in for X and in for y and now if we come back to the sprite the place that I want to draw this is about here so about nine pixels across and nine pixels down so I'm gonna say wherever we're drawing the back draw the player infer nine pixels down and across so I'm just gonna say these two values plus nine but it's not actually just nine again because remember because we're scaling everything we need to say nine times scale okay and actually another thing that I wanted to that we haven't done yet is let's make our own sort of custom fonts that we're going to be drawing all this in because otherwise it'll just use the default font so I'm going to create a few so for now let's just make fnt text a font at size 12 and I'm gonna make this font now I actually have this one that I just found online it's just a free font that I quite like I'll leave a link in the description it's really easy to install but you can use any font that you like I'm gonna pick this one and I'm also going to turn off anti-aliasing which kind of smoothes the text because we're doing a pixel art game it tends to look a bit weird if you're smoothing the texture I'm gonna have it turned off I'm also just going to duplicate this and have a bigger size I'm going to use this one to draw the name and actually let's make one more I'm going to use this one for the number of items that we have so the small numbers that are going to appear in each square that's inert the amount of each item I'm going to set this one to [Music] career 10 pitch and I'm gonna make this 114 I've just played around with this and I think this looks quite nice and I'm going to turn off anti-aliasing all right cool so let's come back to here so now when we draw our name we're going to be using one of those fonts now something too which is kind of just going to be a good practice tip for when you're programming with data structures so whenever you refer to a data structure it's actually going to be quicker to access it as a local variable then as an instance variable so if you're accessing a data structure multiple times in an event that's run every step of the game right so like in the seventh which is run sixty times which is going to be the same for the drawer the drawer cooing so if you're doing this sixty times in a second and referring to it eight times it's going to start to add up for example we could go like that and it would make this a little bit faster so it isn't really matter for the create event because we're just doing this once at the side of the game so I'm not even going to bother face but we will do that here because we are going to be referring to it multiple times in the straw gluey event so I'm gonna like that and now we are actually going to draw the text so we're going to use the function vortex Cal and the XY location that we're going to be drawing this text at is just going to be these variables that we set here in for x and y and now the string that I wanted to draw so what I wanted to draw is basically name and then whatever this is so we're going to access this twice to draw a birthday drink so I'm gonna go in for grid so and remember their cell coordinates so this one was 0 3 and this one's 1 3 sir zero three and then what you can do is you can actually add strings together so I'm gonna add firstly a little colon thing just to separate them and then like that so now we have to give it a color and an alpha value so I'm just gonna make a local variable c equal to the color black just so I can set all these a bit quicker and the Alpha is just gonna be one and one more thing that we should do right here is set that font that we set up there we go let's have a look at that all right so now let's draw those coin values because they actually they do exist we've set them here but we just aren't drawing them yet now what I'm gonna do and this is very specific to the sprite that I have set up because of exactly where they're located so I have worked out these numbers if you're using a different sprite you're going to have to set this up yourself but what I'm going to do is I'm actually going to use a repeat statement to draw the three of these just incrementing this variable each time and changing the coordinates a bit slightly so what I'm going to do is firstly change the font and I want to set up a repeat loop just like we've done many times before so I'm repeating it three times because there's three things I want to draw and every time I repeat this loop I'm going to increment this value so we again draw text color now for our X&Y for these I have kind of found the exact pixel locations that I want so it's basically the first one is gonna start 192 pixels across but again I have to times it by the scale because we're scaling everything up by 2 so that will get me to where the gold coin is but then I also have to add some sort of variable number for the times that I repeat and I want to draw the yellow ones so I'm gonna have 15 + 18 + 18 is just the width of the coins so I'm basically going one coin width plus another 15 and then we're gonna times that by the scale of course then I know times that by YY so for the first one this is just gonna be 0 but for when y is 1 we're gonna kind of go one coin across so and the Y value there that's just nice and simple it's going to be exactly the same as all of the other info so we can just put info wipe and finally the actual string because we have to give it a strain who's gonna be these but these are actually numbers right which is a different kind of data type so we're gonna have to do is convert it to a string we just put string in here which is going to convert it to a string for us and then we access its location in the grid so in photo grid and it's in column 1 right so X is 1 oops afraid our access huh so one and then the y-coordinate will just be whatever YY is currently equal to and I might just put this over multiple lines that we can see it there we go and finally for the color so I might actually just keep it as black so it's currently set to black then we'll just you can change it if you want there and the Alpha value alright so if we run the game now it should draw those numbers yep so it's drawing on numbers for us and if we just hit aah which will restart the game there we go so we're randomizing the numbers okay good so now let's move on to the inventory itself and same as before let's come back to the create event because there's a few variables that we're going to need to set up so just like our info grid we're gonna need to set where we want to start drawing the inventory from so let's come back to our UI spine so you can see the inventory is gonna start right here so it's x value is just nine across so it's just like the in first so it's gonna be equal to whatever info X is and then it's just gonna be 40 down from wherever this is so let's go ahead so we'll call this slots because this is the inventory slot so we'll go slots X and so like I said it's going to be equal to this one for you it might be something different if you're putting it in a different location with your different sprites and the y is going to be whatever this is plus 40 of course times by the scale okay now there's a few more things I need so we're going to be referring to our inventory sprite here and I'm going to create a variable called SPR in items like that because gonna be referring to this a lot and for our system to be nice and flexible I'm actually gonna want to get the rows and columns of our sprite here and you'll see why in a second but you can see that it's basically going to be whatever its width is divided by our cell size so the width of this whole thing is 512 so divided by 32 that will get us 16 columns and 8 roots so that's for my sprite so going to create a couple of new variables so the number of columns and the number of rows in the inventory and basically we're gonna need to know this so that we weren't accessing the specific item basically what we're gonna be doing is we're gonna look at this and then be incrementing so if I wanted to get for example the carats which should be number 3 so 0 1 2 3 it's gonna want to find this value here but if we want to get the mushroom we basically we want to know if it's reached the max amount of columns to loop back to the start and look on this row so that's why we're gonna need those values anyway let's come back next we're gonna set some pretty important values for the actual inventory so our slots and this will be the number of slots that you want in your inventory so I am gonna set mine to actually let's just do 16 for now I'll have 24 at the end but I just want to check if everything that we draw is correct so the width is gonna be eight and the height is going to be two actually why don't we just make it a weird odd number and we'll do you like that okay and now let's actually set up the data structure for our inventory so down here will create another little section inventory and remember so the column zero is gonna be the item itself and then column 1 is gonna be the amount of that item that we have all right so let's create our actual data structure so when I have DS inventory is what I'm gonna call it and it's gonna be a grid so a width of 2 and then the height is going to be how in many inventory slots that we have and now a set up the items so we'll set up our enumerator item and we'll name all of them so here I'm just gonna go down my sprite and basically just name all of these and of course we have to start off with the nun item which is gonna be at the index of zero and like I said you don't have to put these but I think it just makes it a bit easier to read especially if we want to know what a specific items index is we can just look at this really quickly intel so we'll do the same for the rest of the items all right so that's all our items and you can fill it with however many items that you want and I'm also just going to add at the very bottom of whatever you've got here height there isn't really a function that we can call to get the total number of entries in an enumerator but you can use this trick because you can see right here that our entries they go from 0 to 16 which means that we have 17 entries so whatever this value equals this is gonna be the number of entries that we have so it's just a neat little trick to get the height of your name right up and now what I'm gonna do is kind of like here when we just filled our goal copper and solar with a random number I'm going to fill our inventory with some random values so for example if you wanted to just add like a bucket to the inventory what you would do is just write Dias inventory and then a cell in your inventory so just zero zero for example for the first one and make that equal to whatever item that you're putting it in and then in the second column you put however many that's gonna be but so feel it randomly what we're gonna do is we're gonna use a repeat statement again so I'm just gonna set up just like we've done many times and the number that we're gonna repeat is just going to be hell of many inventory slots that we have because I want to feel every single slot so we're gonna be looping through the whole inventory and each time we loop we're gonna increment by Y and then we're gonna grab and the RO will just be whatever while I currently is so we start at zero I'm going to look through the whole thing and instead of specifying this I'm gonna say so basically we want a random number between 1 and whenever our height is except we don't want to actually include this one so we go height minus 1 so let's go i random.range so one because I don't want to include the nun item and item not high it - one and for the amounts you can put whatever you want here I'm just gonna put between 1 and 10 so I'm just going to delete this now and before I forget so we've created our data structure we've declared all our numbers and we've filled it in random slots so what we should do actually is remember whenever we create a data structure we have to delete it so let's come into the cleanup and add it to this like that we are and now let's come into the drawer GUI and will actually be drawing the inventory so again we're going to be using a repeat statement for this because basically we want to loop through that entire inventory grid and draw the appropriate sprite from our sprite items and also the amount so let's just set up our P loop so we're repeating having many inventory slots that we have basically the logic of what we're gonna do is so for every single slot we're gonna have to get so we're gonna have to get the X&Y location for the slot we're gonna have to pull out the item from our item grid and I'm gonna have to draw out the slot so if I slot I mean we're gonna draw this thing over here so we're gonna have to draw that for every single one and then we'll draw the item number and then we'll increment our value that we're gonna use to loop through the grid and we're gonna need quite a few variables for this so I'm just gonna declare them all here so let's start off with these ones and basically these III X and I watch this I I is basically gonna be the current item index that we're on so this is the one that were going to be incrementing down here and then the IX and iy this is gonna be kind of the cell of the inventory that we're seeing on the screen so these all start off at 0 and I is gonna go from 0 to sir 17 we said we had 17 slots but depending on what we've put for our inventory slots width so as soon as I X hits 8 what it's gonna do is it's gonna reset back to zero and then iy is gonna increment to the next row so that's how we're gonna be controlling what row the room so actually let's just set out the logic for that so Y is going to be incrementing and then IX is going to equal whatever III is mud and then whatever our width of our inventory slots and what mod does if we just mimic like this is models gonna give us the remainder of the division so if I I is nine and inventory slots is 8 then this is gonna give us one right so it's never gonna go above 8 it's always just gonna be kind of the remainder of whatever III / M slots width and slightly different for the I Y so kind of like the mode but the div is going to give us the amount it can be divided by so again if we have 9 divided by 8 this 8 can only go into 9 once so it's gonna give us 1 so together if I I is 9 this will give us a remainder of 1 and this will give us 4 1 all right so now for xx and YY so these are going to be the location of the current slot so I'm going to set these up here so now XX is gonna be so we set up slots X and that will be fine for our very first one but we're gonna need to add to this for all the rest and actually there's one more thing that we need to set up which is gonna be the distance between the slots so you can see here the X distance we'll call it an X buffer between them is 2 and the y buffer is full so let's just put that in and I'll put it here so we're gonna need that in our calculation so we're gonna say cell size plus the x buffer so it's gonna be kind of how much room one is taking up how much room we want to move over for each slot so then we're going to times that by whatever this is equal to our horizontal coordinate for the slot so x IX and then x scale of course because we need to times all our pixels by the scale all right and then the same for the y but instead of X we put y and I what all right so I've got our positions now for the actual item itself we're gonna need a couple more variables up here so I'm gonna make a variable called a item I can't just use item because that's actually our numerator this is going to be the current item that we're on that we pull out of the grid and I also want to declare our inventory grid as a local variable for the same reason as this up here so we're gonna set in grid equal to our data structure like this and we'll set this one here equal to so we're gonna be in column 1 of course because that's where we store what kind of item it is and then whatever I I currently is we remember our grid is just a big long list so we're just going down at one at a time this will get the item so one of these from a grid so and then with this information we have to go and find what sprite that we have to draw so kind of like this we're actually going to need a sprite X and sprite way so if for example we want to draw this carrot that will be number 0 1 2 3 so we want to get basically the cell size times 3 the carrots X location so a couple more variables so we're gonna have SX and sy for sprite X and sprite why SX is gonna be so whatever I item in so this is gonna be a number remember so I item mod the number of columns that we have so exactly the same as this what this will do is it's gonna get whatever the number is divided by the total number of columns that there is which means if it's over the number of columns that we have right so if it's this one it's gonna give us a remainder of one again so we're gonna get the correct X sort of column that we want okay but this is this is going to give us a cell location because we've divided everything by cell size for these columns and everything so here we're gonna have to times it back by cell size because what we want is a X&Y position because that's what we're going to be drawing it I'm going to do the same for the y this will probably make more sense when we're actually drawing it so just like this we put div so let's actually draw the item itself so to draw sprite putt ext and this is probably going to be a long one so now the sprite that we want is SP uh in items because remember we set that variable here the sub image is just Sara so now the location that we're gonna be drawing from this writes text and y at the top left and right is going to be here or here or here or here so that is gonna be what this is equal to so you can put SX and sy and the width we know it's just going to be 32 which is our cell size and the same for the height and now the X&Y location to draw it up which we figured out here and finally the X scale and the Y scale is just gonna be our scale and for the blend color we don't want to blend it so we'll just say white and an alpha of 1 okay so it's for drawing the slide and actually we need to draw one other thing so remember how I said so this is what remember this looks like at the moment we also want to draw this if we actually have a slot at the location so in addition to drawing the item itself we're going to draw this thing right here which we know is just going to be part of this holes fight starting at zero zero and then with the 32 and height of 32 across so our UI sprite to the left and top is just zero and zero and then the width so it's going to be at the same location as our item it's also going to be scaled and CY and one okay and finally we're just gonna draw the number and I'm actually gonna say if the number is zero actually I'm not gonna draw the number so first I just want to check so if we have the nun item right so if we're getting this value here then I don't want to draw this and actually I've put that here as well so if we put if item is larger than zero only then do we want to go and draw this and the same for the number so if it's larger than zero what I'm going to do is I'm going to pull out the number I was gonna make a variable for this sir phone number so this is gonna be equal to the inventory grid so column 0 remember was for the items one is for the amount so the amount is here whatever our feiiow value currently is that would give us the number and then we just draw text color exactly the same as before at the X&Y location and again I'm going to translate this into a string because this is actually a number and we're supposed to be giving this function a string like that and our C value up here I think is still set to black and we'll just keep using that again if you want to change that here feel free to and one okay I think we're done so let's give that a run and see how it looks there we go so it's filled our grid and we have all of our slots in if I hit R you can see it just randomizes all of our items and we can't really interact with them at the moment right there just in our inventory but they are there and next time we'll make so that we can select an inventory slot and move it around and we can pick up items and drop them so I'd like to thank everyone on patreon who are supporting me to make these tutorials and a special shout out to 3d monkey biz Daniel Hargraves maximilan are and Luther lien for their support I really appreciate it I hope you guys are all well and I'll see you next time
Info
Channel: FriendlyCosmonaut
Views: 41,779
Rating: undefined out of 5
Keywords: inventory tutorial gamemaker, inventory gamemaker, rpg inventory gamemaker, inventory system gamemaker, inventory grid gamemaker, inventory data structures gamemaker, inventory gamemaker 2, inventory gms2, inventory tutorial gamemaker studio 2, inventory friendly cosmoanut, inventory farming rpg, farming rpg gamemaker, rpg gamemaker, gamemaker, gms2, friendly cosmonaut, farming rpg
Id: Bj48UWayTsM
Channel Id: undefined
Length: 46min 12sec (2772 seconds)
Published: Tue Oct 24 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.