1 decade ago
by paulh
Hi all
i want to keep the player in the centre of the screen and then scroll the map horizontally based on the velocity, while allowing player to move up and down the screen (i have the vertical camera working!)
Ive started with the jump and run demo but cant keep player in the centre with either of:
this.pos.x = ig.game.screen.x/2;
this.pos.x = ig.system.width/2;
How do i keep the player in the centre of the screen and still scroll the map (which has repeat (so it tiles) set to on ... (using repeat isn't essential!)
1 decade ago
by Joncom
The idea is that you want to scroll the screen, not player.
var playerCenterX = (player.pos.x + player.size.x/2);
var playerCenterY = (player.pos.y + player.size.y/2);
ig.game.screen.x = playerCenterX - ig.system.width/2;
ig.game.screen.y = playerCenterY - ig.system.height/2;
1 decade ago
by paulh
yea, i can either get the player to stand in centre, or the whoel screen to scroll:-)
init: function( x, y, settings ) {
this.parent( x, y, settings );
// Add the animations
this.addAnim( 'idle', 1, [0,1,2,3,4,3,4,3,4,3] );
this.addAnim( 'run', 0.07, [17,18,19,20,21] );
this.addAnim( 'jump', 0.5, [40,41,42] );
//this.addAnim( 'fall', 0.4, [7,8,9,10,11] );
this.playerCenterX = (this.pos.x + this.size.x/2);
this.pos.x = this.playerCenterX;
ig.game.screen.x = this.playerCenterX - ig.system.width/2;
},
update: function() {
// move left or right
var accel = this.standing ? this.accelGround : this.accelAir;
if( ig.input.state('left') ) {
ig.game.screen.x = ig.game.screen.x + 2;
this.pos.x =this.playerCenterX;
this.flip = true;
console.log ("ig.game.screen.x ", ig.game.screen.x , " this.pos.x", window.innerHeight);
}
1 decade ago
by paulh
Bah! the collision layer wont repeat either .. im trying to make an old school sega style game, where the character stays horizontally in the centre of the screen and the map scrolls and tiles :-(
setting repeat: true in the level.js created in the editor doesn't solve the problem:-(
Any help on this appreciated, havent touched impact for ages :-(
1 decade ago
by paulh
so the screen is scrolling, thanks JONCOM .. just need to repeat the collision ... which apparently you cant do (based on forum searching :-(
init: function( x, y, settings ) {
this.parent( x, y, settings );
// Add the animations
this.addAnim( 'idle', 1, [0,1,2,3,4,3,4,3,4,3] );
this.addAnim( 'run', 0.07, [17,18,19,20,21] );
this.addAnim( 'jump', 0.5, [40,41,42] );
//this.addAnim( 'fall', 0.4, [7,8,9,10,11] );
this.playerCenterX = (this.pos.x + this.size.x/2);
this.pos.x = this.playerCenterX;
ig.game.screen.x = this.playerCenterX - ig.system.width/2;
},
update: function() {
// move left or right
var accel = this.standing ? this.accelGround : this.accelAir;
if( ig.input.state('left') ) {
ig.game.screen.x = ig.game.screen.x - 2;
this.pos.x = this.pos.x -2;
this.flip = true;
this.currentAnim = this.anims.run;
console.log ("ig.game.screen.x ", ig.game.screen.x , " this.pos.x", window.innerHeight);
}
else if( ig.input.state('right') ) {
this.flip = false;
ig.game.screen.x = ig.game.screen.x + 2;
this.pos.x = this.pos.x +2;
this.currentAnim = this.anims.run;
}
1 decade ago
by Joncom
Quote from paulh
just need to repeat the collision ... which apparently you cant do (based on forum searching :-(
Might make for an interesting plugin project...
1 decade ago
by paulh
way beyond me i think though :-(
1 decade ago
by dominic
It's not that complicated:
1) build the collision layer a bit larger than needed. I.e. if the layer is 16x16 tiles, make it 18x18 and repeat the first two rows and columns in the last two ones.
2) if the player is at the edge, set him to the opposite edge of the screen.
if( this.pos.x > 17 * tileSize ) {
this.pos.x -= 16 * tileSize;
}
else if( this.pos.x < 1 * tileSize ) {
this.pos.x += 16 * tileSize;
}
// same for pos.y
Depending on what you want to do with the game, you may have to wrap around all other entities as well. Also, maybe your margin needs to be a bit wider than 2 tiles, if the player can move fast.
1 decade ago
by paulh
Unfortunatly the player stays in centre of the screen :-(
1 decade ago
by Joncom
Another solution, inspired by Dominic's post:
Make your level, and then make two copies, one of the left, and one to the right.
1 decade ago
by paulh
i had this working when the player could move freely, and yes i just teleported to the other side of the screen ... but understanding just the coordinates is pretty difficult when the screen starts scrolling...
1 decade ago
by paulh
prob the best way of doing this will be to modify drop to scroll horizontally. then duplicate the half of screen edges and kill one of them when they are totally of screen.
As dom says, will prob also have to iterate through entities to keep them consistant... a real shame :-( Would of been able to write the majority of the game in a few days if collisions had repeated ;-)
1 decade ago
by Joncom
Yes, on second thought, although the player would seamlessly be able to continue running forever, it would be pretty noticeable when he sees entities appearing and disappearing.
1 decade ago
by Joncom
@paulh: It turned out that I needed to achieve the exact same thing for a game I'm working on. Hopefully I wasn't too late and you can still find this helpful! :)
Demo
Plugin for repeating collision map.
1 decade ago
by paulh
Hey Joncom, this is awesome, i was still trying to write my own ... i noticed that the app crashes after awhile in ejecta, maybe there's a leak or something?
Np data to help you im afraid...
1 decade ago
by paulh
Hey Joncom, this is awesome, i was still trying to write my own ... i noticed that the app crashes after awhile in ejecta, maybe there's a leak or something?
this is the only error i coudl find:
error: call to a function 'class_getName' that is not present in the target
(lldb)
1 decade ago
by Joncom
Try disabling the plugin and see if the crash still occurs.
There is no class_getName
or getName
function in the plugin.
Perhaps search your code for that, and see what turns up?
1 decade ago
by paulh
will do, when apple comes back online, looks liek i might have an older version :-)
Thanks again Joncom its an awesoem plugin, i was only telling you about the potential issue for your benefit really :-) Ill let you know if i cna reproduce when i can reinstall stuff from apple ;-)
1 decade ago
by paulh
Actually i reset up impact/ejecta nd its run for the last 45 mins or so without incident!
Thanks again!
1 decade ago
by paulh
i guess you also might have run into the same problem i have now on how to draw entities relative to the screen/world .. any pointers greatly appreciated...
1 decade ago
by Joncom
Edit: Response removed because I see you created
another thread for your question.
Page 1 of 1
« first
« previous
next ›
last »