The forum is read-only. New threads, replies and edits are disabled.
Doubt about score
fgb01

I'm trying to make a very simple punctuation system ... the correct method to do is to use the "New Text Sprite" in the editor and it updates?
Thank you very much.

krumza

If you use online editor create text sprite 

then open your app.js and fint in it  init function 

App = function()

{

    this.init = function()

    {

then in init() add some variable:

App = function()

{

    this.init = function()

    {

      wade.app.score=0;

     ....

    }

    ....

}

Then open onUpdate funct in your text object and add:

this.getSprite(0).setText(wade.app.score);

If text sprite is not first sprite - use getSprite(1)... etc 

then find in your code fragments whitch you use for score, as example destroy something and after this action add:

wade.app.score++ //if simple increment or



//OR!!!



wade.app.score=wade.app.score+20//30,50,100 etc

 

fgb01

Good Morning,
It did not work ... the error message appeared:
"Uncaught TypeError: Can not read property 'toString' of undefined (textSprite.js, 285: 22)." Do not have to pass the value, no?

krumza

It must work, it work

okay

open your app.js file

find init function

insrt this:

this.init = function()//find init function

	{

	    wade.app.score=0;

        

        var scoreSprite = new TextSprite('learn javascript', '64px Arial', 'blue', 'center');

        var score = new SceneObject(scoreSprite);

        wade.addSceneObject(score,true);

        wade.addEventListener(score, 'onUpdate');

        score.onUpdate = function(){

            this.getSprite(0).setText(wade.app.score)

        }

//...

...

}

 

 

fgb01

Can not you just add a textsprite in the editor and that it starts with 0 and use a code so that at the time of the collision add another point?

Without abusing your goodwill ... could you give me an explanation or example of a jump using physical or not, in the simplest way please?

 

krumza

As example add in app.js next code:

//insert in 

App = function(){

//..here code



wade.app.onClick = function(){

  wade.app.score++;

}



//another your code



}

This simple case when click increase score.

I dont know your game logic but in any case you need some trigger for change score

if we use code from topic Doubt with collision

you see fragment^

var collidingObjects = wade.getOverlappingObjects(true);

for (var i=0; i<collidingObjects.length; i++)

{

    if (collidingObjects[i].getName() == 'some specific object name')

    {

         wade.removeSceneObject(collidingObjects[i]);//trigger 

         wade.app.score++;//insert after trigger

         break;

    }

}

 

fgb01

The part of the collision I understood ...
But what part of the code should I put in the Textsprite object?

fgb01

Sorry for being annoying but I just need this and the doubt of the jump to finish my doubts ...

fgb01

From so long I persisted I got my friend ...
Thanks a lot for the help...

Can you help me with the jump too?

krumza

TextSprite must have in it upade function this:

this.getSprite(0).setText(wade.app.score)

if textsprite is not first - use this.getSprite(1)...//etc

About jump - i cant help you, because i dont make platformers and dont use phisics module

But i give you a one working method in topic Move object with keyboard