Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Redraw letter grid fail

Author
Message
matty47
17
Years of Service
User Offline
Joined: 20th Nov 2007
Location:
Posted: 12th Oct 2024 01:34
Trying to code a wordle style game. The letter grid is a grid of types. All was going well until .......
In the checkIn function if the entered 5 letter word is not a word in the list then I want to clear that word on the grid display. Even though I reset the content of the grid (lines 167-173) and do a Sync, the previous word remains in the display. I also tried a drawGrid() before the Sync but that did not work. Obviously I am missing something simple but I don't know what.
Any help greatly appreciated

Attachments

Login to view attachments
Virtual Nomad
Moderator
19
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 12th Oct 2024 03:22 Edited at: 12th Oct 2024 03:24
it's tough for me to follow but where are you setting r which seems to just be 0 on declaration and not changed?

otherwise, what happens if you remove the message (and you shouldn't need the sync())?

sorry i'm not much help but our coding styles/approaches are different
matty47
17
Years of Service
User Offline
Joined: 20th Nov 2007
Location:
Posted: 12th Oct 2024 05:23
Thanks for replying. r is the row number and is set at 0 for the first row. The code is at an initial stage so far so there is a lot yet to do - however setting the cell content to "" when the word entered is not a word, and then redrawing the grid I thought would delete the letters previously in the grid. It does not. I did check that the cell content had actually been reset (using a Message). It seems that there is some persistence in the display that I am not understanding. I also tried setting the cell content to a space, but the previous letters still showed in the display. The Sync command was only to force a redraw and you are right it should not be needed.
If you add a line c=0 after the next on line 172 and before the sync line you can see that if you enter one five letter word not in the list and then try entering more letters, they appear in the correct cells along with the previous letters! See attached image
Virtual Nomad
Moderator
19
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 12th Oct 2024 05:53
i just don't use DrawText(). maybe do a ClearScreen() at the top of your Do/Loop?
matty47
17
Years of Service
User Offline
Joined: 20th Nov 2007
Location:
Posted: 12th Oct 2024 06:21 Edited at: 12th Oct 2024 08:06
I had tried using ClearScreen() but it did not do the job. What would you use to draw the letters? The Print command does not seem to have the option to print at a specified location - unless I missed something
GemGames
6
Years of Service
User Offline
Joined: 31st May 2018
Location: Edmonton, Alberta, Canada
Posted: 12th Oct 2024 06:25
I suspect it might have something to do with the DrawText() function in line 86. Can you try to comment that line out, and see if the "ghosting" goes away as a result? If both the "ghosting" and the current text entirely disappear, maybe try replacing line 86 with Sync() instead?

I've found the Print() functions in AppGameKit to be quite unconventional, as the text from them will disappear on subsequent Sync() commands. Unlike most BASIC languages, the AppGameKit Print() commands are more of an "immediate mode" graphics output, which outputs to only the current single frame, requiring a redraw for each subsequent frame. Print() seems to draw a volatile line of text that disappears if not reprinted inside a loop with a recurring Sync() inside the same loop.

I noticed there is a Print() inside the do...loop loop. Possibly, is the Print() output printing on top of the DrawText() output? And when the content of one (AGK Text) changes is the other one (Print()) still printing previous content, within the same frame that Sync() renders?

Using AGK's DrawText() might also have some unexpected effects. In contrast to the disappearing effect of Print(), DrawText() apparently pastes a "permanent" copy or snapshot of the current text. If the content of the AppGameKit Text changes after DrawText() is executed, and then Sync() is called, it seems that the former content (current when DrawText() was called) is printed along with the new current content (when Sync() is called). In effect, this gives the same single AppGameKit Text object two differing text strings which are both rendered in the identical same screen frame.

Home-->Commands-->Text-->DrawText.htm
AGK online help wrote: "Immediately draws the text to the backbuffer at its current position, size, and rotation. This is useful if you want to take control of the order that things are drawn. If you do this then be sure to make the text invisible before calling Render or Sync otherwise your text will be drawn twice"


It might be easier and effective to avoid both DrawText() and Print() altogether, and instead limit the graphics output using only CreateText(), SetTextString() and Sync(). I hope this helps.
GemGames
6
Years of Service
User Offline
Joined: 31st May 2018
Location: Edmonton, Alberta, Canada
Posted: 12th Oct 2024 06:28
matty47 wrote: "What would you use to draw the letters?"


Maybe try omitting both DrawText() and Print(), and instead only use CreateText(), SetTextString() and Sync() to draw the letters.
GemGames
6
Years of Service
User Offline
Joined: 31st May 2018
Location: Edmonton, Alberta, Canada
Posted: 12th Oct 2024 06:34
Another possibility would be to use a series of AppGameKit Sprites whose images are set to various letters, and thereby avoid all of the AppGameKit Text and fonts commands.

One advantage of using AppGameKit Sprites would be precise control of the dimensions / sizes of the Sprites, perhaps in a virtual resolution screen. I have found that the AppGameKit Text commands, specifically SetTextSize(), can have varying results based on the current resolution of the screen. In contrast, AppGameKit Sprites can be precisely dimensioned using a virtual resolution, which would fit into the grid's cells precisely on a number of different screen resolutions and screen ratios.
matty47
17
Years of Service
User Offline
Joined: 20th Nov 2007
Location:
Posted: 12th Oct 2024 08:24
Thanks for the replies. I had already started working on using sprites. As the background colour will need to change, in each cell I used a background sprite and then a letter sprite over the top. I found the same result as I did in the previous code. The letters did not disappear if the entered word was not in the list. Finally I added a line that set the letter overlay to a copy of the same image used for the background (line158) and the grid was cleared and allowed new letters to be shown. (If you want to see the previous effect change the value in line 158 from 1 to any value from 65 to 90). I realise that I did not include the media previously and so have done so with this post. Now I should be able to continue working on the checking logic.

Thank you again.

Attachments

Login to view attachments
GemGames
6
Years of Service
User Offline
Joined: 31st May 2018
Location: Edmonton, Alberta, Canada
Posted: 12th Oct 2024 16:24
matty47 wrote: "As the background colour will need to change, in each cell I used a background sprite and then a letter sprite over the top."


That's a neat approach and it creates ease of versatility if you ever want to change colors at some point in the future or at some stage in the program.

I wasn't even aware of the DrawSprite() AppGameKit function (presently on line 86) even though I'm sure I must have seen it before in the AppGameKit documentation at some point in the past. Typically I just use Sync() and it automatically handles the sprite updates instead of using sequentially Update(), Render(), Swap() for manual intervention.

That's good to be aware of the availability of the DrawSprite() function; it could come in very useful for certain scenarios (i.e. if you want to clone a sprite in many simultaneous locations on the screen using only a single sprite instead of a myriad of independent sprites; or maybe a "mouse trailer" motion effect using only a single sprite).

Thanks for sharing your revised code! I learned something through that.
Virtual Nomad
Moderator
19
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 12th Oct 2024 18:26 Edited at: 12th Oct 2024 18:33
hey, matty. glad you've resolved and are moving forward.

i do just assign a text object to each letter & SetTextString() as necessary.

otherwise, something worth mentioning since it appears you're coding for mobile is that reading a single .json file into the array is much faster that reading the words in, line by line. if you're not familiar with .json usage, see the bottom of this guide.

also worth mentioning now that i've seen your media is the use of text font images (ie, a single image vs individual sprites/images for each letter).

see the attached project for a bit of it all; note that FillWords() will convert your .txt file to .json for later use (i could have included the json file but wanted you to be able to see that it works as demarked by the ClearColor.

btw, the font image was created using UO BitmapFontMaker. there is at least 1 more somewhere on the forum but UO's the one i've been using.

anyway, just some different approaches to consider during your wordle journey

good luck! and, do keep us updated

Attachments

Login to view attachments
GemGames
6
Years of Service
User Offline
Joined: 31st May 2018
Location: Edmonton, Alberta, Canada
Posted: 12th Oct 2024 21:09 Edited at: 12th Oct 2024 22:38
Virtual Nomad wrote: "btw, the font image was created using UO BitmapFontMaker. there is at least 1 more somewhere on the forum but UO's the one i've been using."


Great resource, thanks for the information! Would you consider possibly adding UO BitmapFontMaker to the resource directory? It seems like it could be quite useful for a wide variety of different projects.
matty47
17
Years of Service
User Offline
Joined: 20th Nov 2007
Location:
Posted: 12th Oct 2024 22:50
Thanks for the advice and links!!
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Oct 2024 18:15
Back in Myea i arch I made a worldle game. I can share my code if you like.

https://zimnox.com/games/wordbrain/


I glanced over yours and you have a few issues. For one, you're calling drawGrid() in your main loop. In that function you're creating 25 new text objects every time. Texts work like sprites, there's no need to use "drawtext" and manually control the drawing. When you say you've reset the grid content, you really haven't. The text objects still exist, they'll still be displayed unless you delete them or hide them.

Create your text objects once, in your init() function. You'll have 25 total (not 25 new ones every frame). You can then either show/hide them as needed, or simply give each one a "space" character.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Zaxxan
Developer
4
Years of Service
User Offline
Joined: 17th Nov 2020
Location: England
Posted: 28th Oct 2024 18:54
@Phaelax I'd also be interested in the code as well if you don't mind. I'm hoping to start a new AppGameKit project over Christmas and was thinking of some kind of word game.

Login to post a reply

Server time is: 2025-05-08 22:36:08
Your offset time is: 2025-05-08 22:36:08