[SOLVED] Problem Score / FadeIn


(I'll tell you what I want, what I really really want) #1

Hello again, FP.

I’m participating in Ludum Dare, and I need help with few things.

First of all, I’m trying to make something like a counter of seconds, like a score of how long have player survived in a world, and I’d like it to be displayed in the middle on the top of the game, and I know that it’s a number converted to a string, I just don’t know how to assemble all of that. Tried one way and another and I’m just embarrassed. BTW. I have a scrolling background, I’d like the counter to be absolute, I mean, not movable(?).

Second of all, I’d like to make a FadeIn FadeOut from one world to another, and I have NO IDEA how to even start.

Can anyone help?


(Jacob Albano) #2

To convert a Number to a String is quite simple:

var scoreText:String = score.toString();

To display it in the center of the screen at all times, something like this should do it:

scoreGraphic.x = (FP.width / 2) - (scoreGraphic.width / 2);
scoreGraphic.relative = false;

And to fade between worlds, you can do this:

var newWorld:World = new NextWorld();
var oldView:Image = FP.screen.capture();
oldView.relative = false;

// add the graphic to the world, storing a reference to its entity for later
var e:Entity = newWorld.addGraphic(oldView, -1000);

var fader:VarTween = new VarTween(function() { newWorld.remove(e);}, ONESHOT);
fader.tween(oldView, "alpha", 0, 1); // fade to 0 over 1 second
newWorld.addTween(fader, true);

FP.world = newWorld;

(I'll tell you what I want, what I really really want) #3

I am honestly sorry I’m such a pain in the ass but here’s what’s going on now:


(Jacob Albano) #4

You’re getting that error because you didn’t write what I told you to. :wink: The way you’ve adapted my example won’t work at all. You should be able to just copy and paste in what I gave you in the spot where you change worlds.

You need to call addTween(), addGraphic(), etc on instances of your class, not the class itself.


(I'll tell you what I want, what I really really want) #5

I did now, but all I get is a blank white screen. I changed it to that, because my nextWorld is Alice_game

			var newWorld:World = new Alice_game();
			var oldView:Image = FP.screen.capture();
			oldView.relative = false;

			// add the graphic to the world, storing a reference to its entity for later
			var e:Entity = newWorld.addGraphic(oldView, -1000);

			var fader:VarTween = new VarTween(function() { newWorld.remove(e);}, ONESHOT);
			fader.tween(oldView, "alpha", 0, 1); // fade to 0 over 1 second
			newWorld.addTween(fader, true);

			FP.world = newWorld;

And just a second ago there was a error, something about this line var fader:VarTween = new VarTween(function() { newWorld.remove(e);}, ONESHOT); about function being empty (function ())


(Jacob Albano) #6

Still having that white screen problem, huh? Are your Flash Player and Debug Player up to date?

Can you upload the SWF here so I can see if it works for me?


(I'll tell you what I want, what I really really want) #7

C:\Users\HP\Documents\FlashPunk\ALICE\src\Alice_world1.as(38): col: 48 Warning: return value for function ‘anonymous’ has no type declaration.

In my bin folder, the swf file has 0kb. I don’t know what’s going on.


(Jacob Albano) #8

Oh, my bad. That should be like this:

var fader:VarTween = new VarTween(function():void { newWorld.remove(e);}, ONESHOT);

It’s not enough to cause a compile failure though.

It sounds like something’s going terribly wrong with your build step. My guess is that it’s not that your game is producing a white screen, it’s that the Debug player opens up without a SWF running (or with an empty SWF) and therefore nothing is displayed.

How old is your version of Flashdevelop?


(I'll tell you what I want, what I really really want) #9

It’s up to date. Maybe it’s the debugger. Changed it, still throwing whitey.


(Jacob Albano) #10

Is your source code online somewhere? I’d be happy to try running your project to see if it’s something wrong with the project settings.


(I'll tell you what I want, what I really really want) #11

Updated the project debugger, now it works just fine. And thanks for the fader, looks awesome!

It’s not, this is my first “serious” project I’m working on, and to be honest with you, I don’t even know how github works.


(Jacob Albano) #12

Oh, awesome! Glad you got it working. :smiley:

When you have the time, I highly recommend checking out source control in some form. Nothing gives me peace of mind like the idea that I can, with the click of a button, revert my code to any previous point if I start having trouble with it. It’s like the ultimate undo button.


(I'll tell you what I want, what I really really want) #13

I am SO sorry bro, but I have another problem. The text that’s displayed on the screen is moving along with my backdrop, and I can’t make it relative = false.


(Jacob Albano) #14

No worries; that’s what I’m here for. :sunny:

Can you show me how you create the text object, and how you attach it to an entity/add it to the world?


(I'll tell you what I want, what I really really want) #15
		scoreGraphic = new Text("60", 100, 100);

I am so embarrassed. Sharing my code is like being naked in front of a crowd of bad guys from Matrix.

Also, I’d like to go backwards from 60, to 0, but that seems to be 2 complicated for me as well.


(Jacob Albano) #16

Ugh, I’m sorry. >< I’ve led you astray! This is actually what you want to do:

scoreGraphic.scrollX = scoreGraphic.scrollY = 0;

That will prevent it from moving with the camera. You should do the same thing with the fade-in image or it might look weird.

And don’t worry about showing your code! I guarantee you we’ve all written stuff that we look back on and shudder over. I’ve got a whole game engine (in the loosest sense) that I wrote in C++ when I was first learning, and it’s the most awful thing you could ever wish to see.


(I'll tell you what I want, what I really really want) #17

You are a wizard my friend!

Could you also help me with that counter of mine?

count:uint = 60;

scoreGraphic = count.toString; scoreGraphic—;

Because this is not working.


(Jacob Albano) #18

Sure:

  • First of all, you’ll need to set the text of the graphic whenever your counter ticks down; you can’t set it once and trust it to update.
  • Second, toString() is a function, so you have to call it instead of treating it like a variable.
  • Finally, you can’t set the graphic itself to a string, you have to set the text property of the graphic in order for it to work.

So that should give you something like this:

count--;
count = FP.clamp(count, 0, 60); // keep the counter from rolling over, just in case
scoreGraphic.text = count.toString();

(I'll tell you what I want, what I really really want) #19

I swear after Ludum Dare I’m going to sit and learn, so I don’t bother y’all with this stuff. :frowning:


(Jacob Albano) #20

Well, that was unexpected. Is count not a numeric type?