John's Epic Megathread Of Confusion & Tomfoolery


(John Andersson) #22

I’m sorry for my extreme noobiness, but I am so confused. Can you please write an example? Maybe convert my current code into your type of code? XD Sorry, I just can’t figure it out myself. I have tried to code it myself according to your explanation, but it doesn’t work no matter what I type


(billy2000) #23

Ah sry its just me that im bad at explications…wait a sec lol


(billy2000) #24

Lets say you have sprHero sprArmor .You have initialised ur graphiclist private var theGraphic:Graphiclist = new Graphiclist(); and u made your graphic to be theGraphic in constructor graphic=theGraphic;.Also u have added your sprHero to the graphiclist in contructor theGraphic.add(sprHero); All fine and nice so far. Now for your sprArmor. When you take your armor from the ground you add the sprArmor to your graphiclist theGraphic.add(sprArmor);.Now when you change/play hero animation you do the same with your piece of armor:

private function renderHero():void
{
	if (Input.check("Left") || Input.check("Right")){
            sprHero.play("run");
            sprAmor.play("run");
        }
}

I hope this time i explained better XD.


(John Andersson) #25

Hey, I’m having trouble making this work.

I made the graphiclist variable public so items can add themselves to it.

public var theGraphic:Graphiclist = new Graphiclist();

in the armor code (let’s just try and make this work for the pants for now):

                     if (!_equipped)
		{
			if (heroCollide != null)
			{
				_equipped = true;
				
				var hero_:Hero= world.getInstance("hero");
				hero_.theGraphic.add(sprArmor);
			}
		}

And in the hero, how do I make it run sprArmor? If I type what you did, it tells me it is a null reference. So I tried doing something like this:

		for each(var g:Graphic in theGraphic)
				{
					g.play("run")
				}

And some similar alternatives. But it doesn’t work. I saw that graphiclists have a function like this:

 theGraphic.children.forEach

But I don’t understand how to use it!


(Jacob Albano) #26
for each (var g:Graphic in theGraphic.children)
{
    var spritemap = g as SpriteMap;
    if (spritemap == null) continue;

    //  stuff
}

(John Andersson) #27

I had to change it to this:

			for each (var g:Graphic in theGraphic.children)
				{
					var spritemap = g as Spritemap;
					if (spritemap == null) spritemap.play("run");

					//  stuff
				}

But I get the error “variable ‘spritemap’ has no type declaration.”

so I tried this var spritemap:Spritemap = g as Spritemap;

But it didn’t work :stuck_out_tongue:


(Jacob Albano) #28

What…why…that’s completely backwards from what it should be.

I forgot to add a type declaration (getting too comfortable with Haxe I guess). var spritemap:Spritemap = g as Spritemap; should be fine.


(John Andersson) #29

Oh…

But isn’t

if (spritemap == null) continue;

the same as

if (spritemap == null)
{

}

?

Anyway, I changed it to what you said, so the code is now this:

for each (var g:Graphic in theGraphic.children)
{
	var spritemap:Spritemap = g as Spritemap
	if (spritemap == null) continue;

	spritemap.play("run");
}

But the animations aren’t synchronized


(Jacob Albano) #30

continue skips the current loop. It’s like returning early from a function; in this case, if the graphic isn’t a Spritemap (cast resulting in null) you don’t want to access it or it will crash.

What do you mean they aren’t synchronized? You’ll have to make sure the animations line up with each other, but this should at least make them all play one animation at the same time.


(John Andersson) #31

They line up perfectly, I can even send you the two individual pngs… Both the armor and the hero have the same fps and everything. It’s just WEIRD that it doesn’t sync! I have no idea how to fix it because it is so surreal. There is no real reason why it doesn’t work. Sometimes when I pause I can see that the animations are the same, but sometimes the armor lags behind. Is there any good way to trace this out? I’m so lost. This has been bugging me for weeks


(Ultima2876) #32

Are they both calling the respective super.update() and super.render() (if necessary) functions in the same place (ie before they update their state or after)?

There has to be a reason for it - computers follow logic completely so there is always a reason for something no matter how illogical it might seem!


(John Andersson) #33

Hi.

Yes, they both have “super.update();” at the end of the update function.

There is no overriding of the render function, so there is no super.render();

This is so frustrating… I’m starting to consider remaking the game in FLASH cs6 just so I can use movieclips… But I want to learn Flashpunk better, so I can use Entities…


(John Andersson) #34

I uploaded the entire Hero class and Pants class…

http://freetexthost.com/sjsk0mv4c1


(John Andersson) #35

Okay, what the hell?

If I set the pants animation speed to 10 fps, it looks way better (but sometimes it isn’t synched). So what, is the pant animation playing at double speed? I’m guessing it sohuld be something like 9.5182581259815 to be perfectly synched. But why is that?


(Jacob Albano) #36

Each spritemap has the same number of frames, correct? They should each have the same animations defined, each with the same framerate. With all of those factors met, and if you play() all matching animations in the same frame, there should be no desync.


(John Andersson) #37

Yes! They all have the same amount of frames, same animations defined, same framerate. It just doesn’t work! I can send you the entire project file so you can see for yourself if you want. This is what is making me tear my hair out. It should be working!

Both the pants spritemap and hero spritemap are 600 x 680.

These are the animations in both of the classes:

Pants:

                spritemap.add("stand", [0], 0, false);
		spritemap.add("run", [5, 6, 7, 8, 9], 20, true);
		spritemap.add("jump", [10], 0, false);
		spritemap.add("crouch", [15], 0, false);
		spritemap.add("attack", [20, 21, 22, 23, 24], 20, false);

Hero:

                spritemap.add("stand", [0], 0, false);
		spritemap.add("run", [5, 6, 7, 8, 9], 20, true);
		spritemap.add("jump", [10], 0, false);
		spritemap.add("crouch", [15], 0, false);
		spritemap.add("attack", [20, 21, 22, 23, 24], 20, false);

Both have the same measurements per frame…

public var spritemap:Spritemap = new Spritemap(HERO, 120, 136);

public var spritemap:Spritemap = new Spritemap(PANTS, 120, 136);

But if I change the pants spritemap.run animation to 10, it works better. WHY IS THAT D: If I have it set to 20, it is playing super fast!

EDIT: So I slowed down the fps of the game to 20, the fps of the pants to 1, and the fps to the hero to 2.

Now I notice that if I run, it looks fine. But after a while, some desync appears. Then it appears more and more. It’s exponential! And only if I keep on running!! WHAT

EDIT 2: Oh wait, no. That wasn’t the case. It would, however, be better if it were, because what it actually is is even more dumb! If I keep on running, after a while, the pants animation kind of “disappears” for a millisecond or so, it flashes.

EDIT 3: I literally swapped the pants animation to the same HERO animation (a.k.a I changed:

[Embed(source="../assets/Armor/Gold_Pants.png")] private const PANTS:Class;

to

[Embed(source="../assets/Hero_Full.png")]private const PANTS:Class;

So the pants armor is the same as the hero. It still does the whole “play at 2x the speed for no god damn reason” thing and it is still weird.


(John Andersson) #38

Can anybody PLEASE help me? I need to fix this!!!


(Jacob Albano) #40

Okay, I looked through your code a bit. It looks like you’re still using separate entities for your pants and your hero? I thought you had changed it to use a single graphiclist on your hero. Is it possible you’re adding the same spritemap to two entities at once? That might explain the fact that it’s running at twice the speed.


(John Andersson) #41

Hmm… When you say graphicslist on the hero, should I not even have the pants as an entity!? But how do I add it then?


(Jacob Albano) #42

Here’s what I think is the problem:

  • You’ve got a set of items in the world, each displaying a graphic that represents itself.
  • You’ve got a hero who walks around collecting these items.
  • When the hero collides with an item, the graphic it used in the first place is added to the hero with a Graphiclist.
  • When the graphic is added, it continues to be updated on its original entity ** as well as the hero, ** causing the animation to play at double speed.

If you’re going to implement armor and weapons as separate entities that the Hero moves around with himself, put your images on entities.

If you’re going to add the images to the Hero with a Graphiclist, use separate entities that do nothing but add the graphics. Make them treasure chests, or Dark Souls-esque particle flares. Even go ahead and use the same image asset; just don’t use the same exact Spritemap instance.