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 It made me doubt logic. LOGIC!
John's Epic Megathread Of Confusion & Tomfoolery
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.
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.
THANK YOU!!!
IT WORKS NOW!
WOOOOOOOOOO!
I LOVE YOU SO MUCH! (L) Thank you!!!
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. glad itās working.
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ā¦
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);
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?
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!
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.
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
I donāt have time to give you full code at the moment but a basic rundown:
- Give your Pants, Armor, Weapon etc classes a āparentā variable of type Entity (public var parent: Entity = null)
- 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
- When a piece of equipment is picked up by the player, set their parent variable to reference the player (equipment.parent = this).
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
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.
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
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