Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

Code references

A topic by ElJoaGames created May 05, 2016 Views: 519 Replies: 5
Viewing posts 1 to 6
(+1)

Hello people;

I'm just asking if I can use the lines of a code(behavior) in another code like this:

I wrote this in /Player/behavior:

let velocity = this.actor.arcadeBody2D.getVelocity();

And now I want to use this in /Camera/cCamera

let characterVelocity = "Player".arcadeBody2D.getVelocity();

How can I do this?

I hope you can understand me....

Thanks, My English is to bad because I'm Spanish XD

Create an actor in your scene named "Player", in your script do :

let playerActor : Sup.Actor = Sup.getActor("Player");

let characterVelocity = playerActor.arcadeBody2D.getVelocity();

I'm trying this but does not work :(

-This in global variables:

let characterVelocity = playerActor.arcadeBody2D.getVelocityX();

-This in another actor code:

this.actor.moveX(characterVelocity) ;

The game not run with this lines, I don't know how I can get this work :(

Ok,

You need to understand two things :

1) All of these code need to be executed into a behavior script (not in global).

2) this.actor is the actor who is attached the behavior. Exemple you create a player actor in your scene and you link the behavior "playerBehavior". In your playerBehavior script this.actor is the player Actor.

So who is the problem ? Just select player actor in the camera script. Dont forget to use class variable if you need to pass elements between awake/start/update method.

If you need more help send me code via pastebin :)

My personal skype : fraxkens

Can you create a project for camera follow and send to me?

I hope If I see how it works I can made my own mode/method for camera follow. Thanks