Layering Sprites

sleeper_service, that thing looks huge :astonished: (the events and elevator), thanks for posting it as an example. Something unrelated to the issue at hand but that I want to comment on: the player space ship is moving very smoothly and the boost controls seems natural. I think good controls are very important in a game so I congratulate you on that.

Possibly, though I didn’t add platformer behavior to the mustache. I only gave it animations that change the same way the player animations change and told it to follow the player’s position. Although the player has behaviors added to him, the mustache is only tracking his position and its animations are handled the same way as the player’s.

Indeed the turrets move out of position a bit, but the displacement is minimal. I don’t know how to explain why but it feels right in a space ship game, but not on a character holding items.

Yes, yes yes yes… Mea culpa, mea culpa. I should’ve noticed the descriptions above, but I didn’t, sorry.

That’s exactly what I did:

But:

Are you suggesting using variables, like:

Do =0 to variable Player_Direction
Do =1 to variable Player_Direction

0 being the player is facing right and 1 player is facing left, and then flip the glasses according to the Player_Direction value? I don’t see how that would avoid creating and destroying the objects though, the player should have the freedom to equip/unequip the items, and the only alternative to creating/destroying the items is creating them all at the start of the scene and make them invisible, then change visibility when the player change them.

You can create/show the item when it is equipped and then destroy/hide it once it is unequiped. Since you’ll need a framework for that anyways to manage item effects you’ll have the conditions at hand. With “link object” you can reference the gear in later vents but that isn’t event necessary if gear objects only appear on the player.

Also I’d probably use one universal object per equipment slot, like “headgear” that has animations for every possible head gear in the game and only changes stats and animation per instance on creation. Easier to manage when dealing with large amount of gear. HDog has close to a 150 items but they are all handled through the same three objects.

Since they are evenly spaced down the side of the main craft I wonder if it would make any difference to position them all relative to one point, rather than having lots of points. So have one point for group_mountable 1 and then:

group_mountable 2 = group_mountable 1 X(); group_mountable 1 Y()+40
group_mountable 3 = group_mountable 1 X(); group_mountable 1 Y()+80
group_mountable 4 = group_mountable 1 X(); group_mountable 1 Y()+120

and so on, depending on what the actual vertical spacing is.

By picking precise relative positions it may avoid shifts in the position caused by the points moving just as the position is being set. Presumably, you could also make them all relative to the origin of the main craft.

I agree with sleeper_service that rather than constantly creating and destroying different glasses objects, just have one “glasses” object and store all the glasses sprites as separate animations within that glasses object. That way the object is created once and then visually altered by stepping through its animations when keys are pressed (or power-ups are collided with).

If one of the animations was completely transparent (such as animation 0) then the object could be there from the start and would seem to be created when you changed to animation 1 and destroyed when you changed back to animation 0.

I think @Lizard-13 already narrowed down the cause of the lag.

Forces are always applied after after events, while “change position” actions are always handled during the events. So object movement cause by forces will always applied after changing the position of attachments. Unless there is a separate “change object position after forces applied” action added, GDevelop will never handle attachments correctly at objects with forces applied. I guess what you described could be done by moving the elevator thing with change position only, but that would hell to get right. I’m not even sure one could create smooth movement this way and it probably is way less economic than the “add force” actions.

For something quite slow moving, that just moves up and down, changing the Y position “manually” should still look pretty smooth. You could then move everything (the ship and all the turrets) up/down by a few pixels in one event . You wouldn’t even need to use points then.

Yeah but if you want to have anything else than rigid movement you want to have stuff like dampening and aditive/counteracting forces. That stuff is super complex to do with “change y”. You couldn’t move the elavator as smothly/efficiently as in the gif and the problem doesn’t stop there anyways. Usually you want to move objects in all directions and react to obstacles/player behavior and a dozen other things. There is no feasible way HDog could do this with just “change x/y”. The whole force system exist to make object movement managable in the first place, but it’ll always struggle with managing multi component objects in the current state.

Hi, it’s me again!

I was testing the proposition of having a single object with multiple animations, and while the concept worked, some weird behavior was observed when using the selection mechanism I set up for the test.

To test the above proposition, I made up 3 armors: Default, Fire and Ice. The variable “ArmorID” identifies each of them, with the extra number 0 meaning “no armor”:

ArmorID: 0 = no armor equipped
ArmorID: 1 = default armor
ArmorID: 2 = fire armor
ArmorID: 3 = ice armor

The selection works with the events shown below:

(I’ve set the ArmorID to 0 at the beginning of the scene too)

So by pressing w (let us call it the “forward selection” button), the number in ArmorID increases by 1 and goes back to 0 if it’s on 3. By pressing q (let us call it the “backward selection” button), the number is decreased by 1 and goes to 3 if it’s on 0. The problem, though, is that it seems to be skipping the number 3 (shown in the gif below), and the forward selection button always sets ArmorID to 0, instead of going through the numbers correctly. To my eyes, the mechanism shown in the events above looks correct, so the problem isn’t there. I took a look at the “Armor” object’s animations*, and they are also correctly implemented. Afterwards, I checked the player movement events**, and they also appear to be correctly made. Therefore, I’m completely stuck.

By the way, the number for ArmorID keeps changing for as long as the key is pressed:

I’ve found no action that allows me to stop the pressing of any buttons for a certain amount of time or just delay it. The only way I could come up with were with timers but this method looks so convoluted I doubt it’s the correct way of doings.

**

This is a classic problem of the “key being pressed” condition checking whether the key is being pressed 60 times a second. That means long before you can release the key, GDevelop will have cycled through events 1-4 multiple times, changing the value of ArmorID multiple times too. Which value it has when the text object is updated will vary.

There are two simple solutions:

  1. Use the trigger once condition (found in Advanced)
  2. Test for the release of a key rather than if it is being pressed

Something else you could do just for your own sanity and to cut down the number of events/sub-events is tweak your ArmorID numbers so they match the animation you want. That way instead of having four sub-events for each of moving, jumping, falling etc. you just add one action to their events along the lines of:

Do =Variable.ArmorID to the number of the current animation of Armor

By doing that, GDevelop will always pick the right animation any time you change ArmorID.

If you need a different “Armor” animation for jumping to moving then just have the correct jumping animation set to always be 4 more than the moving one i.e. ArmorIDs 0,1,2,3 are the moving animations for four different armours; ArmorIDs 4,5,6,7 are the jumping animations for the four armours - and so on.

The jumping event would then have the action:

Do =Variable.ArmorID+4 to the number of the current animation of Armor

This will also simplify your “Armor Selection” events as you can get rid of them all and just have:

w key is pressed  |  Do +1 to variable ArmorID

and

q key is pressed  |  Do -1 to variable ArmorID

You will also need to add conditions to check that ArmorID<=3 when w is pressed and >=0 when q is pressed to avoid sprites disappearing if you go outside the range.