Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Q-ro

4
Posts
2
Topics
15
Followers
9
Following
A member registered Sep 03, 2016 · View creator page →

Creator of

Recent community posts

yeah, we found this bug quite late into the jam, with literally 8 mins before it closed and we couldn’t fix it in time :’<

Hello everyone, so i managed to kind of sort of get my code to do what i wanted it to do, i'm trying to build a top down adventure game a la link to the past but i'm not sure if the way i'm doing this is the right way to go about it, would love for somebody more experience with the engine to give me some tips about my code or how it could be better written or point me towards a tutorial or documentation that could help me out, Thanks in advance :) i really appreciate it.


Sup.ArcadePhysics2D.setGravity(0, 0);
class PlayerBehavior extends Sup.Behavior {

//stores the idle state to transition to when player stops pressing a key
public currentIdle: string;

//trying a different way to go about managing the animation to play
public currentAnimation : string;
//How fast the player can go
public maxSpeed = 0.15;
//The acceleration rate
public acceleration = 0.007;
//How fast he decelerate
public decelaration = 0.0085;
//Current Velocity
private _velocity:Sup.Math.Vector2;


awake() {

this.currentIdle = "Idle_Dwn";
this.currentAnimation = "Idle_Dwn";
this.actor.spriteRenderer.setAnimation(this.currentIdle);

this._velocity = this.actor.arcadeBody2D.getVelocity();
}



update() {

Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, Sup.ArcadePhysics2D.getAllBodies());
// Sup.log(`Actor ${this.acceleration}`);





if (Sup.Input.isKeyDown("LEFT"))
{
// Move the current behavior's actor by a small negative offset on the X axis
//Trying to implement inertia

this._velocity.x = Sup.Math.clamp(this._velocity.x-this.acceleration,-this.maxSpeed,0);



//this.actor.spriteRenderer.setAnimation("Walk_Left");
this.currentAnimation = "Walk_Left";
this.currentIdle = "Idle_Left";



}
if (Sup.Input.isKeyDown("RIGHT"))
{
// Same but positive to go to the right
this._velocity.x = this._velocity.x = Sup.Math.clamp(this._velocity.x+this.acceleration,0, this.maxSpeed);



//this.actor.spriteRenderer.setAnimation("Walk_Right");
this.currentAnimation = "Walk_Right";
this.currentIdle = "Idle_Right";
}
if (Sup.Input.isKeyDown("UP"))
{
// Move the current behavior's actor by a small negative offset on the X axis
this._velocity.y = Sup.Math.clamp(this._velocity.y+this.acceleration,0, this.maxSpeed);



//this.actor.spriteRenderer.setAnimation("Walk_Up");
this.currentAnimation = "Walk_Up";
this.currentIdle = "Idle_Up";
}
if (Sup.Input.isKeyDown("DOWN"))
{
// Move the current behavior's actor by a small negative offset on the X axis
this._velocity.y = Sup.Math.clamp(this._velocity.y-this.acceleration,-this.maxSpeed,0);

//this.actor.spriteRenderer.setAnimation("Walk_Dwn");
this.currentAnimation = "Walk_Dwn";
this.currentIdle = "Idle_Dwn";
}

if(!Sup.Input.isKeyDown("UP") && !Sup.Input.isKeyDown("DOWN") && !Sup.Input.isKeyDown("LEFT") && !Sup.Input.isKeyDown("RIGHT"))
{

//De-accelerate depending on the directtion of the speed vector
if(this._velocity.x > 0)
{
this._velocity.x = Sup.Math.clamp(this._velocity.x-this.decelaration,0,this.maxSpeed);
}
else if(this._velocity.x < 0)
{
this._velocity.x = Sup.Math.clamp(this._velocity.x+this.decelaration,-this.maxSpeed,0);
}

if(this._velocity.y > 0)
{
this._velocity.y = Sup.Math.clamp(this._velocity.y-this.decelaration,0,this.maxSpeed);
}
else if(this._velocity.y < 0)
{
this._velocity.y = Sup.Math.clamp(this._velocity.y+this.decelaration,-this.maxSpeed,0);
}
//If we have achieved complete standstill, pay the idel animation
else if(this._velocity.x === 0 && this._velocity.y === 0)
{
this.actor.spriteRenderer.setAnimation(this.currentIdle);
}

//Testing for better de-aceleration code
//if(Sup.Input.wasKeyJustReleased)

//velocity.y = Sup.Math.clamp(Math.abs(velocity.y)-this._decelaration,0,this._maxSpeed);
//velocity.x = Sup.Math.clamp(Math.abs(velocity.x)-this._decelaration,0,this._maxSpeed);
}
this.actor.spriteRenderer.setAnimation(this.currentAnimation);
//this.actor.arcadeBody2D.setVelocityX(velocity.x);
this.actor.arcadeBody2D.setVelocity(this._velocity);


}
}
Sup.registerBehavior(PlayerBehavior);

Oh god I feel so silly, thank you :P, now I didn't saw that line in the code until you pointed that out.

So i started checking the engine out and following the simple tutorial from the documentation, the platformer one, and everything was ok until it was time to add the collision detection to the game, once added my character wouldn't move at all, not in the slightest, help ? this is how my player behavior looks like:


Sup.ArcadePhysics2D.setGravity(0, 0);
class PlayerBehavior extends Sup.Behavior {

//stores the idle state to transition to when player stops pressing a key
public currentIdle: string;
//How fast the player can go
public _maxSpeed = 0.1;
//The acceleration rate
public acceleration = 1;
//How fast he decelerate
public _decelaration = 0.002;
//Current speed
private _speed = 0;


awake() {

this.currentIdle = "Idle_Dwn";
this.actor.spriteRenderer.setAnimation(this.currentIdle);
}



update() {

Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, Sup.ArcadePhysics2D.getAllBodies());
let velocity = this.actor.arcadeBody2D.getVelocity();





if (Sup.Input.isKeyDown("LEFT")) {
// Move the current behavior's actor by a small negative offset on the X axis
//Trying to implement inertia
velocity.x = -0.3;

//Sup.log(`Actor ${velocity}`);
//Sup.Math.clamp(this._speed,0,this._maxSpeed);

//this.actor.move(new Sup.Math.Vector3(-0.1, 0, 0));
this.actor.spriteRenderer.setAnimation("Walk_Left");
this.currentIdle = "Idle_Left";



}else if (Sup.Input.isKeyDown("RIGHT")) {
// Same but positive to go to the right

//velocity.x += this.acceleration;
//Sup.log(`Actor ${velocity}`);

//this.actor.move(new Sup.Math.Vector3(0.1, 0, 0));
this.actor.spriteRenderer.setAnimation("Walk_Right");
this.currentIdle = "Idle_Right";
}else if (Sup.Input.isKeyDown("UP")) {
// Move the current behavior's actor by a small negative offset on the X axis
//this.actor.move(0, 0.1, 0);

//velocity.y += this.acceleration;

this.actor.spriteRenderer.setAnimation("Walk_Up");
this.currentIdle = "Idle_Up";
}else if (Sup.Input.isKeyDown("DOWN")) {
// Move the current behavior's actor by a small negative offset on the X axis
//this.actor.move(0, -0.1, 0);
//velocity.y += -this.acceleration;

this.actor.spriteRenderer.setAnimation("Walk_Dwn");
this.currentIdle = "Idle_Dwn";
}else
{
this.actor.spriteRenderer.setAnimation(this.currentIdle);
}


}
}
Sup.registerBehavior(PlayerBehavior);


I wanted the player to be able to move on a top down perspective, but it won't move on any direction at all