Game Development Community

Problems with FishGameTutorial in TGB Pro 1.7

by Acy Forsythe · in Torque Game Builder · 02/22/2008 (6:55 am) · 9 replies

Problem1:

The Bubble and Mine graphics are not loaded when I add the resource. I'm fairly sure I know why they aren't showing up, but I don't know how to fix it, and figuring that out will go a loooong way to my understanding how graphics are used in TGB (I'm completely ignorant on the subject).

The image file has cells that are the same size for all the fish in the PNG file, and they all come in fine, but the mine and the bubble are in smaller cells.

What I have done:

Step1: I copy/pasted those two graphics into their own PNG files and added them manually: Lesson learned? MS Paint doesn't support transparency, and what do you know, I didn't even know what transparency was.

Solution: Got Gimp, learned about transparency (sort of) and got the images back in the game, only they are completely transparent now.

Step2: The graphics (cut/pasted into MSPaint and then fixed with GIMP) show up just fine in windows explorer, transparency working just fine, so my mistake must now be with how I added them into TGB (drag and Drop) Lesson Learned? The simplest solution turns out to be really friggin complex sometimes.

So I added a new datablock to the resource.cs for the fish art, adding in the new bubble and the new mine, Great! I get them in, but they are blank images. Lesson Learned? I now know what a datablock is, and I know how to add graphics to specific resource sets, without getting it right.

That is where I am with the graphics. In the meantime, I am still using my original bubble and mine with the non-transparent backgrounds so they are basically white squares with the picture in the middle.

------------------------------------------------------------

Problem 2:

I wanted to add fish to my game that hurt my playerfish, but I did not want them going up and down, I want them going left and right.

So I copied the FishModifyHealth.cs behavior modified all the Y's to X's, and the "bottom" to "right" so that they respawn when they hit the right edge instead of the bottom edge. So far, so good, except I did NOT modify any collision details and the other fish PUSH my fish instead of disappearing and respawning like the Mine and the Bubble do.

I cannot figure out why, any one have any ideas?

EDIT:
Just on an added note, while I beleive that broken tutorials are a huge turn off to beginners who do not know what they are doing, and have pushed me away from many purchases (including TGE which own but don't use because I can't get simple things to work and can't figure it out), I'd like to say that the TGB tutorials (while still broken) have at least been very simple and easy to understand.

I didn't do any other tutorials other than the Fish game tutorial, and through the docs and the other tutorials, I've managed to add a whole lot to a simple tutorial without too much of a headache. I've got varying scrolling backgrounds that look nice, fish swimming in different directions, mines and bubbles falling, and even an invincibility power-up all added within about 8 hours of working, and 5 of those hours were trying to fix the broken graphics. So thumbs up to whoever wrote the tutorials and the documentation, most answers were easy to find, and examples were fantastic so far!

#1
02/22/2008 (10:29 am)
For your first problem, are you using TGB 1.7.2? I just added the fishArt resource to a project and the mine and bubble graphics show up fine. They are located in the fishImagesImage, frame 13 and 14. This image uses KEY mode to create each frame - the datablock should look like this:

new t2dImageMapDatablock(fishimagesImage) {
      canSaveDynamicFields = "1";
      imageName = "./fish/fishimages";
      imageMode = "KEY";
      frameCount = "-1";
      filterMode = "SMOOTH";
      filterPad = "1";
      preferPerf = "0";
      cellRowOrder = "1";
      cellOffsetX = "0";
      cellOffsetY = "0";
      cellStrideX = "0";
      cellStrideY = "0";
      cellCountX = "-1";
      cellCountY = "-1";
      cellWidth = "249";
      cellHeight = "336";
      preload = "1";
      allowUnload = "0";
   };

For the second problem, it sounds like you need to modify the collision details for those fish. Specifically making sure the onCollision callback is checked in the editor and creating a Fish::onCollision function in script that mimics what the mines do in reducing player health.
#2
02/22/2008 (11:38 am)
I downloaded TGB 2 days ago, so whatever version they had available for download (not at that PC right now). I will check my resource.cs file and see if that datablock is exact to the one I have, because those images do not show up. Now, maybe I am doing something wrong, because the other stuff shows up.

I created a new project called FishTut, I clicked on Project-> Resources, highlighted the fishArt, and hit add, everything showed up except for the bubble and the Mine. Where should they show up under static sprites?



As far as the second problem goes, why would a behavior work for one graphic and not for another? Is there some additional setup somewhere that I am missing?

I add the behavior for the bubbles and the mines and I can assign that behavior to any other graphic and use falling rocks (shrunk down background image) and it works. But when I appy the same behavior to a fish graphic, the collision doesn't work the same way, the two fish collide and can't move past each other. I've done nothing with collision other than what the behavior does.

Is the onCollision Call back check box (under scene object rollout right?) something that is defaulted per resource graphic? I'll double check that, but I am fairly certain that I didn't have to check or uncheck that for the other graphics.
#3
02/22/2008 (1:06 pm)
Those images do show up under the static sprite section, but probably not in the way you are thinking. ImageMaps that use the CELL or KEY modes are represented with only 1 thumbnail. The rest of the images can be accessed by clicking on the number below it. So the fishImagesImage has 14 frames and by default it shows frame 1 of 14 as a thumbnail. Click on the 1/14 until the number changes to 13 or 14 and then you can drag that frame into the scene. Or you can change the frame number of an ImageMap on the edit tab, static sprite rollout.

Sorry, for your second issue I was looking at the normal fish game tutorial not the behavior one. I'd have to look a bit more at that tutorial in depth to try and figure out why it's not working for you.
#4
02/22/2008 (4:05 pm)
I hate posting in another thread. but everyone answeres Everyone elses thread. but doesn't help me! Someone please respond in my "help" topic!
#5
02/22/2008 (7:12 pm)
Thanks Mike!, I need to find a good tutorial for adding graphics resources I guess. (I'm sure there is one, probably even in the docs, I just haven't run across it yet).

I do have another question. I've got the wave scrolling and it works just fine. But the backgrounds are also setup in the "scrollers" section. The problem with them, is that there is a blank white section that scrolls along with them. I can't figure out what is setup differently with them as opposed to the wave. The starter resource has the same issue with one of the scrollers it has, but it's not really a graphic that needs to scroll anyway.
#6
02/23/2008 (9:10 am)
I've just about got the hang of everything, but I am having a bit of trouble with behaviors, I've modified the ModifyHealth.cs behavior (for mines and bubbles) and I have added it to more fishes, but the only swim from left to right. So I took the example from the fish tutorial demo (not the fish game tutorial) and I modified the behavior further like this:

if(!isObject(fishiesModifyHealthBehavior))
	{   
		%template = new BehaviorTemplate(fishiesModifyHealthBehavior);
		%template.friendlyName = "Fishies Tutorial Modify Health";
		%template.behaviorType = "Gameplay";
		%template.description  = "Modify health control for our Fishies Tutorial";
		%template.addBehaviorField(healthModifier, "Value in which to modify the health by", integer, 2);
		%template.addBehaviorField(minSpeed, "The min random speed to float down", float, 5);
		%template.addBehaviorField(maxSpeed, "The max random speed to float down", float, 15);
	}
	
	function fishiesModifyHealthBehavior::onBehaviorAdd(%this)
		{   
			// enable collision for sending and then enable the callback   
			%this.owner.collisionActiveSend = true;
			%this.owner.collisionActiveReceive = false;
			%this.owner.collisionCallback = true;
			// disable physics   
			%this.owner.collisionPhysicsSend = false;
			%this.owner.collisionPhysicsReceive = false;
			// set the world limit   
			%this.owner.worldLimitMin = "-50 -45";   
			%this.owner.worldLimitMax = "50 45";
			%this.owner.worldLimitMode = "NULL";
			%this.owner.worldLimitCallback = true;
		}

	function fishiesModifyHealthBehavior::onAddToScene(%this, %scenegraph)
		{   
			%this.startPositionX = %this.owner.getPositionX();
			%this.respawn();
		}

	function fishiesModifyHealthBehavior::onCollision(%this, %dstObj, %srcRef, %dstRef, %time, %normal, %contacts, %points)
		{   
			// lets update the health of the object we are colliding with   
			if(%dstObj.hasHealth)   
				{      
					%dstObj.updateHealth(%this.healthModifier);
					%this.respawn();
				}
		}

	function fishiesModifyHealthBehavior::onWorldLimit(%this, %mode, %limit)
		{   
			switch$(%limit)   
				{      
				  case "left":
				 %this.setLinearVelocityX(getRandom(5, 15));
				 %this.setFlipX(false);

				  case "right":
				 %this.setLinearVelocityX(getRandom(-15, -5));
				 %this.setFlipX(true);
				}
		}

	function fishiesModifyHealthBehavior::respawn(%this)
		{   
			%this.owner.setPositionY(getRandom(-35, 25));
			%this.owner.setPositionX(%this.startPositionX);
			%this.owner.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed));
		}

Now, they disappear off the right edge of the screen and never respawn or swim back to the left. Any idea what is wrong here?

The only changed section is onWorldLimit, and the original code, which had them swimming to the right and respawning on the left still works if I revert back to it:

function fishiesModifyHealthBehavior::onWorldLimit(%this, %mode, %limit)
		{   
			switch$(%limit)   
				{      
				  case "right":
				 %this.respawn();
				}
		}
#7
02/23/2008 (10:56 am)
When using behaviors, there is a difference between %this and %this.owner. %this refers to the behavior itself and is useful for storing information or calling functions. %this.owner refers to the object that has the behavior attached to it. So in your onWorldLimit function change the setLinearVelocityX and setFlipX functions to %this.owner.setLinearVelocityX(getRandom(5, 15)); for example.
#8
02/23/2008 (6:06 pm)
Mike, thanks again! And that leads me to another question :)

I mentioned (and asked) in another thread, what the difference was between using behaviors for certain things, and setting up classes for certain things, and the answer I got was that behaviors were new and should probably used whenever they can, etc...

So, if I do follow older tutorials and use classes, %this refers to the object that is a member of the class in that case correct? If I've got that understood, it should make it easier for me to figure out the different methods used in some older tutorials.
#9
02/24/2008 (4:21 am)
Yes, your understanding is correct when using classes.