1 decade ago by fulvio
I am in the process of building a chat bubble for my game. The problem is I can't get my head around how to properly store 3 lines of sentences within an array and move onto the next set. I managed to set all the correct width and it looks exactly like it does below on screen.
So let's say I have a total of 8 sentences for a particular dialogue.
Because my chat bubble's height will only accommodate 3 lines of sentences at any given time. I therefore would like to move onto the next set of 3 lines of sentences after the user has tapped a game key, eventually bringing them to the end of the complete dialogue and then back to the beginning to start over again.
This code is what I have so far, which displays all 8 sentences. I realise that there is a lot of missing code, but keep in mind there is an `update()` method constantly running that I have waiting for the key press to move onto the next set of sentences.
Update method:
Draw method:
This is currently how it looks in game:
THE QUICK BROWN FOX
JUMPS OVER THE LAZY
DOG. WHILE THE QUICK
FOX JUMPS OVER THE
LAZY DOG. WHILE THE
QUICK FOX JUMPS OVER
THE LAZY DOG. WHILE
THE QUICK BROWN FOX.
I hope this all makes sense. If you need me to elaborate on anything else or provide any further code, please let me know.
Thanks in advance.
So let's say I have a total of 8 sentences for a particular dialogue.
Because my chat bubble's height will only accommodate 3 lines of sentences at any given time. I therefore would like to move onto the next set of 3 lines of sentences after the user has tapped a game key, eventually bringing them to the end of the complete dialogue and then back to the beginning to start over again.
This code is what I have so far, which displays all 8 sentences. I realise that there is a lot of missing code, but keep in mind there is an `update()` method constantly running that I have waiting for the key press to move onto the next set of sentences.
Update method:
update: function() { if (ig.input.pressed('shoot')) { console.log('Move onto next set..'); } }
Draw method:
draw: function() { var sentences = ["THE QUICK BROWN FOX", "JUMPS OVER THE LAZY", "DOG. WHILE THE QUICK", "FOX JUMPS OVER THE", "LAZY DOG. WHILE THE", "QUICK FOX JUMPS OVER", "THE LAZY DOG. WHILE", "THE QUICK BROWN FOX."]; for (x = 0, y = sentences.length; x < y; x++) { var fontX = this.pos.x - ig.game.screen.x + this.textOffset.x; var fontY = this.pos.y - ig.game.screen.y + this.textOffset.y + x * yOffset; this.font.draw(sentences[x], fontX, fontY, ig.Font.ALIGN.LEFT); } }
This is currently how it looks in game:
THE QUICK BROWN FOX
JUMPS OVER THE LAZY
DOG. WHILE THE QUICK
FOX JUMPS OVER THE
LAZY DOG. WHILE THE
QUICK FOX JUMPS OVER
THE LAZY DOG. WHILE
THE QUICK BROWN FOX.
I hope this all makes sense. If you need me to elaborate on anything else or provide any further code, please let me know.
Thanks in advance.