edit; Just a bunch of questions.
edit; Just a bunch of questions.
First Question:fixed
So It seems this project is pretty dead, but i figured i'd ask a question anyway. maby it will get seen before i figure it out on my own.
Ive just gotten the client-server setup running, and modified the movement to be input based prediction + regular polling to prevent desync which will occur eventually.
What im at a slight loss at is where i would put all of my functions that are in index.html.
fixed below
Second Question/statement:(fixed)
also, it by default draws other players over the clients player. gotta go fix that
this.zIndex = 3; and ig.game.sortEntitiesDeferred();
third question : (fixed)
bullets cant get a negative velocity.. (left, up, or any combination)
fixed by following link below x.x
fourth:
No method kill when players disconnect?
So It seems this project is pretty dead, but i figured i'd ask a question anyway. maby it will get seen before i figure it out on my own.
Ive just gotten the client-server setup running, and modified the movement to be input based prediction + regular polling to prevent desync which will occur eventually.
What im at a slight loss at is where i would put all of my functions that are in index.html.
fixed below
Second Question/statement:(fixed)
also, it by default draws other players over the clients player. gotta go fix that
this.zIndex = 3; and ig.game.sortEntitiesDeferred();
third question : (fixed)
bullets cant get a negative velocity.. (left, up, or any combination)
fixed by following link below x.x
fourth:
No method kill when players disconnect?
Last edited by Lutcikaur on Sat Mar 30, 2013 5:50 am, edited 10 times in total.
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Getting functions out of index.html
I am not sure what you mean by where to put all the functions in Index.html. You are wanting to move them?
Re: edit; Just a bunch of questions.
Yea, in one of your tutorials you had mentioned that eventually they would be moved. I would move them myself but ive only been trying this for a few hours, and am trying to get my bullets to go in the direction of my mouse
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: edit; Just a bunch of questions.
Here is a simple tutorial that will show you how to do just that. Also get to know that site well if you haven't already. It is actually a better ImpactJS resource site than Impact's own site (short of the official forums, that is).Lutcikaur wrote:Yea, in one of your tutorials you had mentioned that eventually they would be moved. I would move them myself but ive only been trying this for a few hours, and am trying to get my bullets to go in the direction of my mouse
The indelible lord of tl;dr
Re: edit; Just a bunch of questions.
For the first question, you can put that code as an impact plugin on a js file and load it in the main.js file like this:
socketFunctions.js
main.js
socketFunctions.js
Code: Select all
ig.module('plugins.socketFunctions')
.defines(function() {
// your js code from index.html
})
Code: Select all
ig.module('game.main')
.requires(
...
'plugins.socketFunctions'
...
)
.defines( function() { ...
Orgullo Catracho
Re: edit; Just a bunch of questions.
Getting a
Pretty sure its not running socketFunctions after i moved it over.
Code: Select all
Uncaught ReferenceError: playername is not defined
Code: Select all
ig.module('plugins.socketFunctions')
.defines(function() {
var namerand = Math.floor(Math.random()*999);
var playername = "player" + namerand;
var socket = io.connect('http://localhost:8080');
socket.on('message', function (data) {
var player = ig.game.getEntitiesByType( EntityPlayer )[0];
if(player)
{
player.messagebox = player.messagebox + '\n' + data + ' disconnected';
}
});
socket.on('playermove', function (positionx,positiony,currentanimation,thisgamename) {
var otherplayer = ig.game.getEntitiesByType( EntityOtherplayer );
if(otherplayer)
{
for(var i in otherplayer)
{
if(thisgamename == otherplayer[i].gamename)
{
//otherplayer[i].pos.x = positionx;
//otherplayer[i].pos.y = positiony;
otherplayer[i].xinc += (positionx-otherplayer[i].pos.x);
otherplayer[i].yinc += (positiony-otherplayer[i].pos.y);
otherplayer[i].accel = 1;
otherplayer[i].animation = currentanimation;
}}}
});
socket.on('playerdir',function (direction,currentanimation,thisgamename){
var otherplayer = ig.game.getEntitiesByType( EntityOtherplayer );
if(otherplayer){
for(var i in otherplayer){
if(thisgamename==otherplayer[i].gamename){
otherplayer[i].direction=direction;
otherplayer[i].animation=currentanimation;
}
}
}
});
socket.on('addbullet',function(r,startx,starty){
ig.game.spawnEntity(EntityBullet,startx,starty,
{
flip:this.flip,
angle:r
});
});
socket.on('netreplayer', function (playerlist) {
var netplayers = ig.game.getEntitiesByType( EntityOtherplayer );
//////////////loop to see if players exist
if(netplayers){
for(var i in netplayers)
{
netplayers[i].kill();
}}
for(var i in playerlist)
{
if(playername != playerlist[i])
{
ig.game.spawnEntity( EntityOtherplayer, 160, 260, {gamename:playerlist[i]} );
}
}
/////////////////////////////////
});
socket.on('addplayer', function (playerlist,otherplayername) {
var player = ig.game.getEntitiesByType( EntityPlayer )[0];
player.messagebox = player.messagebox + '\n' + otherplayername + ' joined';
for(var i = 0;i<playerlist.length;i++)
{
if(player.gamename != playerlist[i])
{
ig.game.spawnEntity( EntityOtherplayer, 160, 260, {gamename:playerlist[i]} );
}}
});
})
Re: edit; Just a bunch of questions.
Uhmm.. where does playername is not defined? Inside main.js? If that's the case then the error occurs because playername variable is not a global scope anymore. I actually don't remember much of the code that halls used, but you can put those 2 lines inside game's init or before defining the game class and they will be global e.g.
Code: Select all
ig.module('game.main')
.requires(...)
.defines(function(){
var namerand = Math.floor(Math.random()*999);
var playername = "player" + namerand;
MyGame = ig.Game.extend({ ...
})
Orgullo Catracho
Re: edit; Just a bunch of questions.
Yea a pal in class helped me with it.
I needed to add
and
needed to lose their 'var' status
------------------
Now im just confused with
.. im trying to rewrite the server so a specific client will act as a server to be used for collision detection. the latency inbetween socket commands and the other client should be minimal. . . after i get it to run without a window x.x
I needed to add
Code: Select all
.requires(
'impact.entity')
Code: Select all
namerand = Math.floor(Math.random()*999);
playername = "player" + namerand;
------------------
Now im just confused with
Code: Select all
delete playerlist[socket.clientname];
for (var i in playerlist) {
if (playerlist[i] == socket.clientname) {
playerlist.splice(i, 1);
}
}
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: edit; Just a bunch of questions.
Be careful with that structure as you are doubling your network. I too went this route on a game but never got enough tests to see if the weight off the server was worth the extra weight on the network.
Re: edit; Just a bunch of questions.
Its not really for weight off the server.. its that i cant use nodejs for collision detection without a good amount of dirty work. I might just scrap it and try and make something from scratch.