pythonarcade / arcade

Easy to use Python library for creating 2D arcade games.
http://arcade.academy
Other
1.71k stars 329 forks source link

What is the correct way to set the transparency of a sprite ? #311

Closed flazouh closed 5 years ago

flazouh commented 5 years ago

Hi, sorry to disturb.

I am a student from belgium and I'm trying to make a "game of go” clone. So I tried to make my stones transparent when hovering my mouse on the board. I tried to set the sprite alpha attribute to 0.5 but it only works once, when I click one the board it sets the stone and when I’m hovering again, the transparency won’t set. Here is my project repo, the arcade class is in the class “game/GoGui.py”.

https://github.com/Subzero8/Go

I added some console printing to see if the alpha was not setting up correctly but from what’s written, the value of alpha is correct (0.5) but the stone is not half transparent =(

Please excuse my english and my code which may not be pretty to look at.

Thanks in advance

Alexandre

pvcraven commented 5 years ago

With version 2.0.0b4, If you want 50% visible, set the 'alpha' to 127. Goes on a scale 0-255. So in your example, line 81:

stone.alpha = 127

flazouh commented 5 years ago

With version 2.0.0b4, If you want 50% visible, set the 'alpha' to 127. Goes on a scale 0-255. So in your example, line 81:

stone.alpha = 127 Thank you for your answer. I installed the 2.0.0b4 on my mac and I got this error :

Traceback (most recent call last):
  File "/Users/alexandredepape/Documents/Python/Games/Go/Main.py", line 1, in <module>
    import arcade
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/arcade/__init__.py", line 24, in <module>
    from arcade.sound import *
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/arcade/sound.py", line 65, in <module>
    _load_sound_library()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/arcade/sound.py", line 39, in _load_sound_library
    import pyglet_ffmpeg

ModuleNotFoundError: No module named 'pyglet_ffmpeg'

Do you know why it happens ?

flazouh commented 5 years ago

Ok I downloaded pyglet-ffmpeg manually and it works, but now my window resized to something very little. So I resized the window to 1200 1200 but the on_mouse_motion function gives me 600 600 when placing my mouse on the top right corner. I am on macos.

pvcraven commented 5 years ago

Oh, darn. Those bugs with the Mac are why I haven't released the beta version yet. No, the 2.0 version does not play nice with the Mac because of the Retina display. It is bad, and I have no solution yet.

pvcraven commented 5 years ago

New beta 2.0.0b5 out now. I played around with the code in that area. Forgot to check if I need to monkey-patch pyglet.

flazouh commented 5 years ago

Thanks, it appears that when creating a window of size 1200 1200, the top right corner has coordinate 600, 600. Do you know how can I fix it ?

pvcraven commented 5 years ago

There's a 2.0.0b5 out where I messed around with that part. Are you running b5 or b4? I hope it works with b5.

On Mon, Mar 4, 2019, 4:11 PM Subzero notifications@github.com wrote:

Thanks, it appears that when creating a window of size 1200 1200, the top right corner has coordinate 600, 600. Do you know how can I fix it ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pvcraven/arcade/issues/311#issuecomment-469442394, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZTTHQ1C1d09tb3DF9hhpSwRQE7MHLRks5vTZoIgaJpZM4bDmDc .

pvcraven commented 5 years ago

Ok, it didn't work with b5. I just released 2.0.0b6 and I think I have the issues fixed on the Mac. Paul Vincent Craven

On Mon, Mar 4, 2019 at 4:47 PM Paul Vincent Craven paul@cravenfamily.com wrote:

There's a 2.0.0b5 out where I messed around with that part. Are you running b5 or b4? I hope it works with b5.

On Mon, Mar 4, 2019, 4:11 PM Subzero notifications@github.com wrote:

Thanks, it appears that when creating a window of size 1200 1200, the top right corner has coordinate 600, 600. Do you know how can I fix it ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pvcraven/arcade/issues/311#issuecomment-469442394, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZTTHQ1C1d09tb3DF9hhpSwRQE7MHLRks5vTZoIgaJpZM4bDmDc .

flazouh commented 5 years ago

Thank you very much ! Sorry for the late answer, I was working on other projects. I have a question, if I wanted to create a little menu, would it be possible to add a listener to each of the buttons in the menu ?

pvcraven commented 5 years ago

As far as the listener, not at this time. It would be a good feature to have.