Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by saloon12yrd

Hi all,

I tried various search phrases but I couldn't find an existing thread that answers my problem. Sorry if the answer is obvious, I'm fairly new to ImpactJs.

I try to have a switch entity that moves a door entity out of the way when triggered.

So far I have a switch that reacts on collision with the player (currently only changing the animation). Also, I have a resizable door entity that does absolutely nothing on its own.

Now I have two questions:
The cosmetic one: By default my door is 8x8 pixel. In the game the tile is correctly displayed as per the animation. When I resize the door (let's say 24x8) then the extended tiles will not be visible in the game. How can I get the tile to expand to the entities' actual size?

The technical one: To actually have the switch open the door I guess I need to fetch the respective door in the check() function of the switch and manipulate its position. Can anyone point me to a 'smart' way to do this? I.e. I'd like to configure the relation between several switches and their respective doors in Weltmeister, not in code.

Thanks in advance,
Dominique

1 decade ago by saloon12yrd

Ok, I got a very rough switch functional. Using the target property in Weltmeister I can now assign door(s) to a switch. On activation of the switch I shift the doors out of the way.

What I'd actually like to achieve are 'sliding' doors. Right now I just do a
door.pos.y = -1 * door.size.y - 10;

to move them off screen but I'd rather have them slide in a given direction by their dimension, like
// slide the door right
for (var i = 0; i < door.size.x; i++) {
  door.pos.x += 1;
}

Of course this doesn't slide 1px per frame - this is where I'm stuck. Any hints how to achieve that?

Also, I've come across a new quirk. My switch has a .check() function that starts like this:

check: function(other) {

  if (this.targets.length > 0
    && ig.input.state('activate')) {

Now as long as the player keeps pressing 'activate' the switch will flicker between off and on. Is there a smart way to buffer this, i.e. change the state of the switch only once per key press?

Thx,
Dominique

1 decade ago by Arantor

Use ig.input.pressed rather than ig.input.state which will give you a definite 'it's been pressed once' test.

As for the sliding, door.pos.x++ would be the right operation to do (same thing as door.pos.x += 1 only slightly faster), but where's that code being called? If it's in the update() routine, I see no reason why it shouldn't move 1px per frame since the update() should be being called once per frame.

1 decade ago by saloon12yrd

Arantor: Thanks for the reply. I figured the .pressed() part out myself by now. Will certainly try moving the door movement into the door.update() code - makes sense now that you mention it.

Thx,
Dominique
Page 1 of 1
« first « previous next › last »