collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 59 forks source link

Extending the ig.Character abstract to make it a player doesn't work. #133

Closed timolins closed 10 years ago

timolins commented 10 years ago

Hello!

In my current project I need to create a player from a custom Character Class. In the docs it says, I just need to set the name of the entity to "player", which doesn't work properly. When I try to move the player, it correctly flips in to that direction, but it stays at the same place. Even in the Debugger, I wasn't able to locate any velocity!

This is the code im using:

ig.EntityPlayer = ig.global.EntityPlayer = ig.Character.extend({
            name: "player",
            animSheet: new ig.AnimationSheet("media/player/player.png", 32, 32),
            animInit: "idle",
            animSettings: {
                idle: {
                    sequence: [11, 12, 13, 14, 15, 16, 17],
                    frameTime: 1 / 6
                },
                move: {
                    sequence: [0, 1, 2, 3, 4, 5],
                    frameTime: 1 / 12
                }
            }
        });

I'm not really sure where the problem is, but it seems like a bug in PlusPlus and not in my source, but I could be wrong.

Pattentrick commented 10 years ago

Hi @Deesr,

why don't you just extend the player abstract? You can add your own character specific methods there too.

javascript ig.module( 'game.entities.player' ) .requires( 'plusplus.abstractities.player' ) .defines(function () { ig.EntityPlayer = ig.global.EntityPlayer = ig.Player.extend({ size: {x: 8, y: 14}, offset: {x: 4, y: 2}, animSheet: new ig.AnimationSheet( "media/player.png", 16, 16), animInit: "idleX", animSettings: { idleX: { sequence: [0], frameTime: 0.1 } }, myOwnMethod: function(){

        // Add here your awesome game mechanics ;-)

    }
});

});



The player abstract extends the character abstract. So you got everything there what you need ;-)
timolins commented 10 years ago

Because I want to base it off another Character Sub-Class. It's going to be a Multiplayer Game, and every Ingame Character is based on that Sub-Class. But since I need a controllable Character I thought this was the easiest solution to use the same base-class and then just add the name "player".

Pattentrick commented 10 years ago

A few ideas ...

Is the performance of your sub class dynamic?

performance: "dynamic"

If you call ig.game.getPlayer(), do you get your character sub class?

collinhover commented 10 years ago

I believe @Pattentrick is correct, the default character performance is movable, which does not include physics. Check https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abstractities/player.js to look at some of the settings used.

timolins commented 10 years ago

Yes, that was the problem. Movement works again, but triggering events (like Sreenshake) don't seem to work, still.

Pattentrick commented 10 years ago

Character entities don't collide with other entities by default. So your character won't collide with the camera trigger and it's activate method won't be triggered. Add this to your class:

collides: ig.EntityExtended.COLLIDES.LITE

As @collinhover mentioned, take a look at the player class for more infos on that.

timolins commented 10 years ago

Yes, I already tried that, but it still doesn't seem to work.

collinhover commented 10 years ago

Go back to square one and have your player characters extend ig.Player for the moment. Does the movement work?

timolins commented 10 years ago

Yes it does, but movement was already fixed, just the triggers didn't work.

Pattentrick commented 10 years ago

So even if you extend ig.Player the trigger won't work on collision? Are you using an own modified trigger entity, or are you using some of the trigger entities that came with ++? If you made your own trigger entity, can you post the code of that one? If not, did you modify some of its propertys in the Weltmeister level editor? Can you also post the whole code of your player as it is at the moment?

I could swear that this is just caused by a missing/false property on the player or the trigger.

collinhover commented 10 years ago

I'm going to agree with @Pattentrick here, something small is missing. @Deesr can you post some demo code that shows the issue? It is much easier to track the problem if we're not guessing blind =)

collinhover commented 10 years ago

Assuming this is fixed as we've heard nothing for some time. If not, please reopen =)