VolosR / TTGOAlienAttack

26 stars 21 forks source link

Repo showing how to use TFT_eSPI sprites for "player" and "enemies" #3

Open patfelst opened 2 years ago

patfelst commented 2 years ago

Hi Volos, have a look at my repo:

https://github.com/patfelst/Volos-AlienAttack-with-sprites/blob/main/src/TTGOAlienAttack.ino

I have modified your Alien Attack code to use TFT_eSPI sprites for the player space ship and the 8 enemies. If you have any questions please let me know. I hope you can use this as a basis for your YouTube tutorial series.

There are other sprite features you can use for scrolling backgounds that I have not shown (e.g. functions .setScrollRect() and .scroll()).

VolosR commented 2 years ago

Hello, i can't open your link, repo dont exist.

ned, 5. pro 2021. u 12:00 Patrick Felstead @.***> napisao je:

Hi Volos, have a look at my repo:

https://github.com/patfelst/Volos-AlienAttack-with-sprites/blob/main/src/TTGOAlienAttack.ino

I have modified your Alien Attack code to use TFT_eSPI sprites for the player space ship and the 8 enemies. If you have any questions please let me know. I hope you can use this in your YouTube tutorial series.

There are other sprite features you can use for scrolling backgounds that I have not shown (e.g. functions .setScrollRect() and .scroll()).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/VolosR/TTGOAlienAttack/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO4RDKXFMHQII5DPQY43IS3UPNA6VANCNFSM5JMUZKUA .

VolosR commented 2 years ago

can you send me code in mail?

ned, 5. pro 2021. u 18:51 Volos Projects @.***> napisao je:

Hello, i can't open your link, repo dont exist.

ned, 5. pro 2021. u 12:00 Patrick Felstead @.***> napisao je:

Hi Volos, have a look at my repo:

https://github.com/patfelst/Volos-AlienAttack-with-sprites/blob/main/src/TTGOAlienAttack.ino

I have modified your Alien Attack code to use TFT_eSPI sprites for the player space ship and the 8 enemies. If you have any questions please let me know. I hope you can use this in your YouTube tutorial series.

There are other sprite features you can use for scrolling backgounds that I have not shown (e.g. functions .setScrollRect() and .scroll()).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/VolosR/TTGOAlienAttack/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO4RDKXFMHQII5DPQY43IS3UPNA6VANCNFSM5JMUZKUA .

patfelst commented 2 years ago

Sorry the repo was private, it's public now. I will email too just in case.

patfelst commented 2 years ago

what is your email address?

VolosR commented 2 years ago

Hello, now I can download it , it works great, thank you. I started to learning about sprites,It isnot so hard as i thought. But i still can't figure some things. I hope you can help me. I want to know how to use transparent sprites. For example I have two images , on one image is house on second is person(player) .Both images have white background, how to make white color transparen in code. So plan is that one image (person) overlaps another image (house) and white pixels are not drawn. I hope you understand me. I will attach images to this email. Thank you for your time.

ned, 5. pro 2021. u 21:49 Patrick Felstead @.***> napisao je:

what is your email address?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/VolosR/TTGOAlienAttack/issues/3#issuecomment-986297629, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO4RDKVYEGKI2QLLAFQJEE3UPPF4TANCNFSM5JMUZKUA .

patfelst commented 2 years ago

Hi Volos, yes I understand what you are trying to do with transparent backgrounds on sprites, but I haven't done this before. That is a question for the TFT_eSPI library. Search through the closed issues and I'm sure somebody has aske the same question before. I mostly use sprites for static text (not moving location) to prevent the numbers flickering.

It is better not to reply to the email notifications because I didn't get the attachments. It is better to use the "view it on GitHub" link and write a reply via the Github web page. Then you can attach images. I would like to try this out for you if you can attach the images, I will do some research on this issue too.

patfelst commented 2 years ago

Please read (or search) through the TFT_eSPI library issues page for transparent sprites https://github.com/Bodmer/TFT_eSPI/issues?q=is%3Aissue

patfelst commented 2 years ago

ok it is a little more complicated, but not too bad, have a look here https://github.com/Bodmer/TFT_eSPI/issues/1127

To get a transparent sprite, you need to create two sprites (sprite_1 and sprite_2), and push one sprite onto the other sprite using sprite_2.pushToSprite(&sprite_1, x, y, transparent_colour); where &sprite_1 is a pointer to the first sprite, and transparent_colour is the background colour of sprite_1 that you want to be transparent. Probably TFT_WHITE in your example.

Becuase the ST7789 is so small, and the ESP32 has lots of RAM, you can probably afford to create one sprite background_sprite as large as the entire display (240x135), then your player sprite and house sprite both get pushed onto the background_sprite. If you use 16 colour images for your sprites (4 bits per pixel) you will use less RAM.

patfelst commented 2 years ago

Sorry one more thing, you will need to experiment, the normal pushSprite (see line 122 in the image below) can also have an transparent colour passed into the function. So that will make a certain colour transparent when pushed on the TFT

Screen Shot 2021-12-06 at 8 16 49 pm
VolosR commented 2 years ago

Thank you my friend, I manage to find solutions. I already made a game using sprites, video will be in couple days. Thank you one more time.