John's Epic Megathread Of Confusion & Tomfoolery


(John Andersson) #43

I know it may sound lazy, but can you post an example? I have been struggling with this for so long that I just want it to be over with :frowning: It made me doubt logic. LOGIC!


(Jacob Albano) #44

I donā€™t have time to post an example now, sorry. Iā€™m in crunch mode on a game of my own. Just take a step back, read through the steps in my last comment, and should have all the information you need in order to solve the problem.

Itā€™s quite possible youā€™ll need to throw out a lot of code. Thatā€™s not a bad thing! If a given component isnā€™t working, itā€™s better to break it down and rewrite than spend a lot of time trying to retrofit it into a working system. Iā€™ve written and discarded hundreds of lines of code in my current project alone, and itā€™s better off because of that.


(Ultima2876) #45

The code link isnā€™t working any more :frowning:


(John Andersson) #46

Oh, Iā€™ll upload it again

Here it is

http://freetexthost.com/0rp0ojk33b


(John Andersson) #47

So can anyone help? Pleaseā€¦


(Ultima2876) #48

In your pants class, in this bit of code:

if (!_equipped)
{
  if (heroCollide != null)
  {
    _equipped = true;

    //etc
  }
}
else
{

}

After _equipped = true, try adding this.graphic = null;. That will remove the spritemap from the Pants entity when it adds it to the graphiclist, meaning it wonā€™t get updated twice.


(John Andersson) #49

THANK YOU!!!

IT WORKS NOW!

WOOOOOOOOOO! :smiley:

I LOVE YOU SO MUCH! (L) Thank you!!!


(Ultima2876) #50

Credit where itā€™s due; if it wasnā€™t for @jacobalbanoā€™s post I probably wouldnā€™t have figured out that it was getting updated twice. :slight_smile: glad itā€™s working.


(John Andersson) #51

:smiley:

Okay! So actually, this isnā€™t entirely finished yet. A minor problem came up.

Previously, the helmet and swords werenā€™t added to the graphicslist, but now I tried mkaing it so they are. However, I canā€™t seem to figure out how to change the helmetā€™s spritemapā€™s position, currently it is in the middle of the heroā€™s body!

Also, I am thinking that maybe the sword shouldnā€™t be added to the heroā€™s graphicslist. Because how would I make it so that it has its own independent animations (like electrical sparks and stuff) if the code

this.graphic = null;

makes it null? It seems pretty painful to animate the weapon through the hero classā€¦


(Ultima2876) #52

You still have the reference to the spritemap in the ā€˜equipmentā€™ classes, even though the graphic is null in them. So if you want to change the spritemap position:

spritemap.x = -10;
spritemap.y = -40;

Independent animations:

spritemap.play("myAnim");

That stuff would all be in the Pants/Sword/Whatever class. Even though their graphic property is null, they can still update the spritemap as they please because they have a reference to it. If you want to create particles (like sparks), do those with a separate entity from within the sword class at the appropriate time.

//pseudocode, I'll let you figure out the exact functions and arguments!
if(spritemap.animation == "myAnim" && spritemap.frame == 5)
{
  world.create(MySparksEntity, blahblahblahblah arguments);
}

//in your sparks entity, make sure it recycles itself when it's done playing
world.recycle(this);

(John Andersson) #53

Iā€™ll try to make it work, but in the meanwhile, a little question:

Does this mean I always have to use graphicslists when wanting entities to follow other entities and donā€™t want desynched movement?


(John Andersson) #54

Another question; since I made the helmet as a spritemap just now (so I can add it to the heroā€™s graphicslist like the other equipment), I had to place the helmet in the middle of every frame, since otherwise it wouldnā€™t fit inside the frameā€¦ How can I make it so that the hero ā€œwearsā€ the spritemap a bit higher? The two sprietmaps have the same height and width, so when I try it out in-game, the helmet is always in the middle, it is synched, but in the wrong place!


(Ultima2876) #55

The top bit of code that I posted before:

spritemap.x = -10;
spritemap.y = -40;

Changes the position of the spritemap relative to the drawing entityā€™s position. So you can tweak those values to change the position.

I use multiple entities all the time because I dislike graphiclists (itā€™s a pain to get multiple hitboxes with those), and it works fine for me.


(John Andersson) #56

I wish to use multiple entities too, since it feels like graphicslist complicate more than they helpā€¦ Can you maybe show me an example of paperdolling without graphicslists? Because I just noticed that when I pick up the items, they just turn invisible but stay in the same spot (their hitboxes), so it feels like I have to remove them if I pick them up, then add them back if I unequip them etc etc.

If I make the weapons into a spritemap, then suddenly every weapon goes from a 5kb file to a 50000 one, it feels very unnecessary to use graphicslistsā€¦ I need some good examples of paperdolling, please :stuck_out_tongue:


(Ultima2876) #57

I donā€™t have time to give you full code at the moment but a basic rundown:

  1. Give your Pants, Armor, Weapon etc classes a ā€˜parentā€™ variable of type Entity (public var parent: Entity = null)
  2. In their update functions, if parent != null, get parentā€™s position and use that to follow parent (this.x = parent.x + blah, this.y = parent.y + blah). Experiment with doing this both before and after super.update to see which works best
  3. When a piece of equipment is picked up by the player, set their parent variable to reference the player (equipment.parent = this).

(John Andersson) #58

The thing is that I have done this but it isnā€™t perfect, so Iā€™d love some source code that worksā€¦ so I can see the actual code written and how it is done


(Jacob Albano) #59

This might sound harsh but it needs to be said.

You should never come onto a forum expecting fully working source code. If you get it, great, but if someone gives you advice on how to solve your problem and you immediately brush it aside and ask for a fully functional solution, it looks like youā€™re just looking for someone to write your game for you.

I said this earlier, and Iā€™ll say it again; take a step back, reevaluate your structure, donā€™t be afraid to delete code that doesnā€™t fit. Take a look through Ultimaā€™s suggestions, think about what each step will accomplish, and try to implement it on your own. Donā€™t ask for help and expect people to respond with full source code.


(John Andersson) #60

I know what you are saying, and I agree. But Iā€™ve tried making it work, but it just doesnā€™t. Iā€™ve spent the last weeks trying to make it work either by coming up with various bad solutions, or following all of your advice. But no matter what I do, it doesnā€™t work. So all I want is some source code that basically has an entity holding another entity with no ā€œslowā€ following, so I can remake itā€¦

Iā€™m sorry if I come off as lazy or arrogant, but if I ever get cancer, this problem is probably the underlying reason to it. It has frustrated me beyond belief


(Ultima2876) #61

Iā€™ll try to find time to whip something up for you within the next few days. Iā€™m publishing a lot of games at the moment so those developers are my priority.

Thanks! Dave