Easiest way to scroll inventory


(Nate ) #1

Hey guys! I have another quick question, my game has an inventory that I have displayed to the screen. I would like the inventory to scroll along with the rest of the game like my health bar does. The inventory has 9 slots, and I also would like the slots to be clickable.

The issue I am currently having is getting the entire inventory to move with the screen. Also what would be recommended if I want the inventory able to be interacted with?

This is how I currently populate the bottom portion of the screen with blank inventory blocks:

for (var i:int = 0; i < 9; i ++)
		{
			add(new Inventory(200 + 32 * i, 448));
		}

I tried messing with the FP.camera.x and FP.camera.y in the update function of the Inventory class but it then only makes one block appear. I am assuming that is because they are all stacking on top of each other since the actual X and Y locations are not being saved?

I am assuming some kind of array work?

Thanks in advance guys!


(JP Mortiboys) #2

Set scrollX and scrollY to zero on the Inventory's graphic, and use Input.mouseX and Input.mouseY for collision (world.mouseX and world.mouseY use the camera).


(Nate ) #3

Thanks again Raptor coming to the rescue! :grin:


(Nate ) #4

How would I go about adding images to the inventory blocks now? Say I pick up a tomato, how do I get it to appear in the inventory?

Thanks


(Nate ) #5

Okay so in my Inventory class I just added this and am now able to click the 9 different boxes, what would the best approach be for being able to pick up each box individually, and then getting images to appear in individual boxes as the player picks up items?

	override public function update():void 
	{
		if (collidePoint(x, y, world.mouseX, world.mouseY))
		{
			if (Input.mouseReleased) click();
		}
			
			
	}
	
	public function click():void
	{
		trace("clicking the inventory");
	}