Having some trouble splicing


(Nate ) #21

Thank you very much for your time! It is greatly appreciated! I will look into this in about 20 minutes once I finish lunch!

In the meantime, I attempted to put an image in for the inventory and everything is still working, just when stuff enters the inventory it is not longer visible. I tried setting the inventory layer to -1 but it still is not working. Any ideas?


(Nate ) #22

Okay I just went through and added all of this. Couple of questions now, it is telling me that g is not defined even though I am defining it.


(Zachary Lewis) #23

Your compiler is probably right. Double check your definitions.


(Nate ) #24

I should re-word my statement. I defined it but with a static initialization which I am not ENTIRELY sure is correct:

This is the item class which was provided to me by Raptor:

package  {
import flash.display.BitmapData;
import flash.display.Graphics;
import net.flashpunk.FP;

public class Items 
{
	
public static const ITEM_TYPE_NONE:int = 0;
public static const ITEM_TYPE_CHERRY:int = 1;
public static const ITEM_TYPE_LIME:int = 2;
public static const ITEM_TYPE_BLUEBERRY:int = 3;
public static const ITEM_TYPE_COUNT:int = 4; // Last one


public static const itemNames:Vector.<String> = Vector.<String>(["Nothing", "Cherry", "Lime", "Blueberry"]);

public static var pickupsBmp:BitmapData;
public static var inventoryBmp:BitmapData;


//Static initialization code to create graphics
 {
	var g:Graphics = FP.sprite.graphics;
  // Create dots for pickups
  pickupsBmp = new BitmapData(32 * 4, 32, true, 0);
  g.clear();
  g.beginFill(0xFF0000); g.drawCircle(32 * 0 + 16, 16, 16); g.endFill();
  g.beginFill(0x00FF00); g.drawCircle(32 * 1 + 16, 16, 16); g.endFill();
  g.beginFill(0x0000FF); g.drawCircle(32 * 2 + 16, 16, 16); g.endFill();
  pickupsBmp.draw(g);
  
  // Create rectangles for inventory
  inventoryBmp = new BitmapData(32 * 4, 32, false /*true*/, 0);
  g.clear();
  g.beginFill(0xFF0000); g.drawRect(32 * 0, 0, 32, 32); g.endFill();
  g.beginFill(0x00FF00); g.drawRect(32 * 1, 0, 32, 32); g.endFill();
  g.beginFill(0x0000FF); g.drawRect(32 * 2, 0, 32, 32); g.endFill();
  pickupsBmp.draw(g);
  

}

}}

(JP Mortiboys) #25

I errā€¦ made a couple of changes to that code - typing too fast; it happens when I write on the fly. I fixed it a while ago, but youā€™ve still got the old version there.


(Nate ) #26

Okay thanks Raptor I will make those revisions now! :grin:

Also would you mind pointing me in the right direction for basically doing EXACTLY what you have done so far, but instead of dynamically generated shapes, can you show me how to do this with .pngā€™s. So like an image of a cherry, lime and blueberry. Then once they are picked up, in the inventory an icon of a cherry lime or blueberry?

EDIT:

these are the boatloads of errors I am getting, I am guessing it is something really easy but I have never worked with a class like this before D:


(JP Mortiboys) #27

Create two bitmaps in photoshop or gimp, 38*4 pixels wide and 38 pixels high (for the inventory, Iā€™m not sure how big your on-screen pickups are).

In each 38x38 pixel cell, paste one image (leave the first one blank).

Do the same for the pickup bitmap, at whatever size you need it - each cell/frame must be the same size.

Now instead of using the temp bitmaps, uncomment the references and correct the embed path/filename to your image. If youā€™re not sure how to do that, read the tutorial!.

Basically instead of creating a bitmap, you embed it and pass the reference to the Tilemap or Spritemap, everything else remains the same.


(Nate ) #28

Okay thank you very much :smiley: I already have all my images from a couple days ago! So I will go ahead and start to plug them in.

However I am still getting this G issue D:

EDIT:

Also I am assuming the two bitmaps have to be in the same order?


(JP Mortiboys) #29

My bad! You canā€™t declare variables in a static initializerā€¦ just use FP.sprite and FP.sprite.graphics and it will work fine.


(Nate ) #30

Itā€™s quite alright!

So like this?

	var s = FP.sprite; 
var g = FP.sprite.graphics;

EDIT

Wait I think you meant swap out all the Sā€™s with FP.sprite and all the Gā€™s with FP.sprite.graphics


(JP Mortiboys) #31

No, donā€™t use the variables at all - just use the references:

  pickupsBmp = new BitmapData(32 * 4, 32, true, 0);
  FP.sprite.graphics.clear();
  FP.sprite.graphics.beginFill(0xFF0000); FP.sprite.graphics.drawCircle(32 * 0 + 16, 16, 16); FP.sprite.graphics.endFill();
  FP.sprite.graphics.beginFill(0x00FF00); FP.sprite.graphics.drawCircle(32 * 1 + 16, 16, 16); FP.sprite.graphics.endFill();
  FP.sprite.graphics.beginFill(0x0000FF); FP.sprite.graphics.drawCircle(32 * 2 + 16, 16, 16); FP.sprite.graphics.endFill();
  pickupsBmp.draw(FP.sprite);
/// etc

Thatā€™s a little long-winded though; you could try declaring the var as static first; that might work - not sure (static var s = ...).

If not, maybe an immediate function? ( see here for an example )

Not that you need any of that if youā€™re using PNGs, of course!


(Nate ) #32

Okay the G issue has been solved! I now have two smaller issues

One in the world and one in the pickup!

the pickup issue says col: 8 Warning: variable ā€˜spriteā€™ has no type declaration. and points to this code:

		var sprite = new Spritemap(Items.pickupsBmp);
		sprite.frame = itemType;
		this.graphic = sprite;

the second issue is from the world and says Access of possibly undefined property ITEM_TYPE_MAX through a reference with static type Class. and is pointing to this line:

//the 1 is the item type... probably best to use constants for this
				add(new Pickup(FP.rand(FP.width - 32), FP.rand(FP.height - 32), 1 + FP.rand(Items.ITEM_TYPE_MAX)));

I donā€™t think ITEM_TYPE_MAX exists in Items.

UPDATE:

I manually plugged a 4 into that constant that I am not sure what you meant to beā€¦ And I have it running. It is being strange though, the screen gets covered in triplets of red green and blue and you can only click on the red ones and it then shoves all three of them into the inventory which is no longer displaying :confused:


(JP Mortiboys) #33

Demo: http://shinyhappypixels.com/punk-forums/inventory/

Source: http://shinyhappypixels.com/punk-forums/inventory/InventoryTestSrc.zip (includes entire FP source code)


(Nate ) #34

Thank you so much :smiley:

I am going to attempt getting my images in there! :grin:

Thanks again Raptor!


(Nate ) #35

Hey Raptor for setting up the bitmaps correctly, I have twelve different items as well as the one empty slot, so a total of 13 items.

I would like the inventory to only hold 9. I changed the value of ITEM_COLS to 9.

I also changed the TILE_WIDTH and TILE_HEIGHT of the inventory to 32x32 which matches the item sizes of 32x32.

What do I have to do for numbers and such in the bitmaps?

Will the photoshop file be, 32 * 12 x 32?


(David Williams) #36

Itā€™d be 32 * 13 x 32. The first 32x32 pixels should be blank, the rest each having the respective item in it.


(Nate ) #37

Okay thank you! :smiley: Now I just have to see if I can figure out how to embed it within the supplied code!


(Nate ) #38

WOOHOO first try I got it! Yay!

EDIT:

How would I go about moving the Inventory to the bottom center of the screen?

I have tried this but it does nothing:

 super(FP.halfWidth - halfWidth, FP.halfHeight - halfHeight, tilemap);

(David Williams) #39
super(FP.halfWidth - halfWidth, FP.halfHeight - halfHeight, tilemap);

It looks like thatā€™d be centering the text?

Iā€™d try:

super(FP.width - width - 5, FP.height - height - 5, tilemap);

(Nate ) #40

Okay I got it, since it isnā€™t all of my code I wasnā€™t sure how to relocate the inventory but doing this seemed to have made it work:

		  tilemap.x = FP.halfWidth - halfWidth;
	  tilemap.y =FP.height - tilemap.height;
	  
	  super(tilemap.x, tilemap.y, tilemap);