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 Patrick_Ascher

Hello to everyone,

iam pretty new in impact and also my skills in JS are ok but not perfect. So i learning impact since 5 hours and now i have my first 3 questions.

Player Collisions:
in the short demo game i have a RPG player. The size of it is 32*48.
Is it possible to make the size of the COLLISION just 24px of the height? so that only the legs are collides? I saw that it is possible to resize it but only from the top to the bottom.

So it looks ok when i am in front of the water bucket.
But it looks wrong when i am standing in front of the tree.
Also a screenshot from the player with the full size and the half size.

Image: /><br />
<br />
<br />
<em>______________________________________</em><br />
<br />
My secound question is about the movement:<br />
<br />
main.js -> init<br />
<pre class= // Initialize your game here; bind keys etc. ig.input.bind(ig.KEY.UP_ARROW, 'up'); ig.input.bind(ig.KEY.DOWN_ARROW, 'down'); ig.input.bind(ig.KEY.LEFT_ARROW, 'left'); ig.input.bind(ig.KEY.RIGHT_ARROW, 'right');
Here is my player config:
	    init: function( x, y, settings ) {
	        // Add animations for the animation sheet
	        this.addAnim( 'down', 0.1, [0,1,2]);
	        this.addAnim( 'left', 0.1, [3,4,5] );
	        this.addAnim( 'right', 0.1, [6,7,8] );
	        this.addAnim( 'up', 0.1, [9,10,11] );
	        
	        // Call the parent constructor
	        this.parent( x, y, settings );
	    },

	update: function() {
			

			if( ig.input.state('up') ) {
				this.currentAnim = this.anims.up;
				this.vel.y = -100;
			}
			else if( ig.input.state('down') ) {
				this.currentAnim = this.anims.down;
				this.vel.y = 100;
			}else if( ig.input.state('right') ) {
				this.currentAnim = this.anims.right;
				this.vel.x = 100;
			}
			else {
				this.currentAnim.rewind();
				this.vel.y = 0
				this.vel.x = 0
			}

			this.parent();
		},

so if you try to move: UP (release it) and the press realy quick LEFT or RIGHT after it and hold it, the Player is moving to the LEFT UPPER corner.

The same problem with multiple Keys LEFT+(UP/DONW) or RIGHT+(UP/DOWN) ... its not working if you press UP + (RIGHT/LEFT) or DOWN + (RIGHT/LEFT)

So its a little bit bugy when i am moving... becouse if press RIGHT+UP und release UP its also moving in the TOP RIGHT corner.

you can try it on my demo game.
LINK: DEMO

_______________________________________

And my last question: is there any method that i can check if ANY KEY is pressed in the INTRO? at the moment i bind it to UP.


Thanks,
Patrick

1 decade ago by sunnybubblegum

Hey there!

For your first question, here's what you can do.
In addition to setting your player&039;s collision area with #size: {32, 24}, you can set its position with offset: {0, 24}.
This just moves the top-left corner of the player's collision zone to the x and y coordinates you specify.

For your second question, I don't have my JS files on hand (my hard drive failed), and I can't remember how this was set up in my top-down game. I'll let you know later if you haven't found out how by then.

For your third question, there is no simple way to do this in Impact. But when asking the same question myself a few weeks ago, it was said by Jerczu to just add a 'keydown event listener'. I haven't pursued this yet.

Cheers!

1 decade ago by Arantor

Your code has two problems as far as event handling goes.

Firstly, I see no handling for going left at all, which seems problematic, but is rectifiable relatively easily.

Secondly, you're encountering your problems because your code is geared up to assuming that the user is only pressing one key per frame, because if they press up, the rest of the branches never evaluate properly. That might not be a problem if you're explicitly only ever moving in one direction at a time, but generally, left and right are not exclusive to up and down, while up and down are mutually exclusive to each other, so you generally need to evaluate the branches separately.

Something much like:
    update: function() {
            // Up or down?
            if( ig.input.state('up') ) {
                this.currentAnim = this.anims.up;
                this.vel.y = -100;
            }
            else if( ig.input.state('down') ) {
                this.currentAnim = this.anims.down;
                this.vel.y = 100;
            }
            else {
                this.vel.y = 0;
            }

            // Left or right?
            if( ig.input.state('left') ) {
                this.currentAnim = this.anims.left;
                this.vel.x = -100;
            }
            else if( ig.input.state('right') ) {
                this.currentAnim = this.anims.right;
                this.vel.x = 100;
            }
            else {
                this.vel.x = 0;
            }

            // Reset animation if we're static
            if ( this.vel.x == 0 && this.vel.y == 0 ) {
                this.currentAnim.rewind();
            }

            this.parent();
        },

1 decade ago by Patrick_Ascher

@sunnybubblegum
Thanks for the tip with the offset. It´s working great.

@Arantor
Thanks for that. Now i understand my mistake.

For my third question:
I have resolved it with jquery and keypress yet. Maybe there is a better solution but its working yet.

$(document).keypress(function() {
	myGameModeExt = 1;
});
Page 1 of 1
« first « previous next › last »