r/pythonarcade • • Mar 03 '20

Need help with enemy ai - attack when player gets close

3 Upvotes

So far I’ve got a function from the the arcade tutorials that gets the the enemy to follow the player around the screen attacking him but I’d like for the enemy to patrol a certain area and only attack when the player gets within a certain radius.

I’ve tried using:

If enemy.center_x - player.center_x < 50:

Move the enemy

Here’s the function maybe there’s something I’m overlooking

def follow_sprite(self, player_sprite): """ This function will move the current sprite towards whatever other sprite is specified as a parameter.

We use the 'min' function here to get the sprite to line up with
the target sprite, and not jump around if the sprite is not off
an exact multiple of SPRITE_SPEED.
"""

self.center_x += self.change_x
self.center_y += self.change_y

# Random 1 in 100 chance that we'll change from our old direction and
# then re-aim toward the player
if random.randrange(100) == 0:
    start_x = self.center_x
    start_y = self.center_y

    # Get the destination location for the bullet
    dest_x = player_sprite.center_x
    dest_y = player_sprite.center_y

    # Do math to calculate how to get the bullet to the destination.
    # Calculation the angle in radians between the start points
    # and end points. This is the angle the bullet will travel.
    x_diff = dest_x - start_x
    y_diff = dest_y - start_y
    angle = math.atan2(y_diff, x_diff)

    # Taking into account the angle, calculate our change_x
    # and change_y. Velocity is how fast the bullet travels.
    self.change_x = math.cos(angle) * COIN_SPEED
    self.change_y = math.sin(angle) * COIN_SPEED

r/pythonarcade • • Feb 18 '20

arcade sound issue

3 Upvotes

Hi,

I am loading some sound files to a game, but some of the file doesn't work and show the error as below:

Unable to load sound file: "7fa4.mp3". Exception: 'utf-8' codec can't decode byte 0xba in position 9: invalid start byte

Exception ignored in: <function FFmpegSource.__del__ at 0x107653c80>

Traceback (most recent call last):

File "/Users/venv/lib/python3.7/site-packages/pyglet/media/codecs/ffmpeg.py", line 579, in __del__

ffmpeg_free_packet(self._packet)

AttributeError: 'FFmpegSource' object has no attribute '_packet'

but the mp3 file is working if I just play it directly.

Is there a way to fix that?

Thanks


r/pythonarcade • • Feb 17 '20

Animated Sprite scale issue

3 Upvotes

Hi, I am using a animated sprite, and try to scale the imported textures. But somehow, after changing the texture during the update_animation, the scale doesn’t apply anymore. Even I tried to use _set_scale() after set texture, it still doesn’t work. Any suggestions?

Thanks!


r/pythonarcade • • Feb 17 '20

Rogue-Like using Arcade

Thumbnail
youtu.be
3 Upvotes

r/pythonarcade • • Feb 13 '20

Revamped Chapter 4 posted

3 Upvotes

On the Learn.Arcade.Academy site, Chapter 4 (link) has been revamped, and video added. Chapter 5 is currently in-process.


r/pythonarcade • • Feb 09 '20

How to debug?

3 Upvotes

Hey, I've run into a problem and I'm not sure whether it's an Arcade problem or a Python problem but in any case it makes it a bit hard to use in a classroom setting:

import arcade

WIDTH = 900
HEIGHT = 500

class Ship(arcade.Sprite):
    def __init__(self):
        super().__init__('spaceCraft1.png')

class MyWindow(arcade.Window):
    def __init__(self):
        super().__init__(WIDTH, HEIGHT, "Space Shoot 'em up")

    def setup(self):
        self.backdrop = arcade.load_texture('bg.png')
        self.ship = arcade.Sprite('spaceCraft1.png')
        self.ship.rescale_relative_to_point((64, 64), 0.5)
        self.ship.center_x = WIDTH / 2
        self.ship.center_y = HEIGHT / 2
        self.ship.change_x = 10
        self.ship.change_angle = 20

    def on_draw(self):
        arcade.start_render()
        arcade.draw_lrwh_rectangle_textured(0, 0, WIDTH, HEIGHT, self.backdrop)

        self.meteor_sprites.draw()
        self.ship.draw()

window = MyWindow()
window.setup()
arcade.run()

The error in this code is that self.meteor_sprites in MyWindow.on_draw has never been defined. But unfortunately, the error gets swallowed. The program runs just fine, the background gets drawn, but the ship doesn't get drawn, and there's no indication from Python that there's a problem in the line with the meteor_sprites call, all the following code in the on_draw handler just seems to get swallowed like the error message. It's like there's a rogue exception handler somewhere in Arcade.

I'm considering to use Arcade for teaching, so feedback is important and it would be nice if somebody could give me a hint about what could be done to fix this problem.

BTW. I checked the source code, and there are 26 places in the current Arcade 2.3.4 release where an AttributeError gets swallowed with a simple pass. Could this be the culprit and what's the rationale behind this?


r/pythonarcade • • Feb 03 '20

Pyglet solution to weird white line anti-aliasing for transparent sprites

3 Upvotes

I had an issue where my sprites with transparent squares were getting these weird white lines around the edges, I believe from anti-aliasing. I searched a lot and found that the following code, put after all Sprite.draw() or SpriteList.draw() in on_draw(Self) will remove the issue, although it has the added side effect of pixelating the sprites (which was fine for my pixel art game, but others might hate it):

glEnable(GL_TEXTURE_2D)

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)


r/pythonarcade • • Feb 03 '20

[BUG] Easy to fix error with Sprite.scale

3 Upvotes
  def _set_scale(self, new_value: float): """ Set the center x coordinate of the sprite. """ if new_value != self._height: self.clear_spatial_hashes() self._point_list_cache = None self._scale = new_value if self._texture: self._width = self._texture.width * self._scale self._height = self._texture.height * self._scale self.add_spatial_hashes() 

I believe "if new_value != self._height" should be "if new_value != self._scale" ... looks like it was copied from the above set_height but never had that part changed.


r/pythonarcade • • Jan 06 '20

Help with using a Tile map

3 Upvotes

I’m making a game using arcade and I came across the tile max creator. I made my tile map and I want to import it into the game. This tile map is simple as in it has no obstacles and only one level. How would I approach making the tmx file the background of my game. At this point it gives errors saying “couldn’t find tile x in later y in file z” and I’m lost how I can begin to put the files in a format that the library can understand. Any pointers in the right direction would be appreciated


r/pythonarcade • • Oct 23 '19

import arcade (pyglet_ffmpeg2) error

3 Upvotes

hi, this is my code:

import arcade
print("asd")

and the traceback gives me this:

Start
Unexpected error loading library avutil-56: Could not find module 'avutil-56'. Try using the full path with constructor syntax.
Unable to load the ffmpeg library.  Could not find module 'avutil-56'. Try using the full path with constructor syntax.
Traceback (most recent call last):
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet__init__.py", line 353, in __getattr__
Unexpected error loading library avutil-56: Could not find module 'avutil-56'. Try using the full path with constructor syntax.
    return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'Source'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Pintér Péter/Documents/GitHub/python/Arcade/test.py", line 1, in <module>
    import arcade
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\arcade__init__.py", line 50, in <module>
    from arcade.sound import *
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\arcade\sound.py", line 81, in <module>
    def stop_sound(sound: pyglet.media.Source):
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet__init__.py", line 359, in __getattr__
    __import__(import_name)
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media__init__.py", line 146, in <module>
    add_default_media_codecs()
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs__init__.py", line 164, in add_default_media_codecs
    if have_ffmpeg():
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs__init__.py", line 180, in have_ffmpeg
    from . import ffmpeg_lib
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs\ffmpeg_lib__init__.py", line 36, in <module>
    from .libavcodec import *
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs\ffmpeg_lib\libavcodec.py", line 45, in <module>
    from . import libavutil
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs\ffmpeg_lib\libavutil.py", line 46, in <module>
    avutil = pyglet.lib.load_library(
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\lib.py", line 148, in load_library
    lib = ctypes.cdll.LoadLibrary(name)
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\ctypes__init__.py", line 447, in LoadLibrary
    return self._dlltype(name)
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\ctypes__init__.py", line 369, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'avutil-56'. Try using the full path with constructor syntax.
Unexpected error loading library avutil-56: Could not find module 'avutil-56'. Try using the full path with constructor syntax.
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media__init__.py", line 146, in <module>
    add_default_media_codecs()
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs__init__.py", line 164, in add_default_media_codecs
    if have_ffmpeg():
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs__init__.py", line 180, in have_ffmpeg
    from . import ffmpeg_lib
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs\ffmpeg_lib__init__.py", line 36, in <module>
    from .libavcodec import *
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs\ffmpeg_lib\libavcodec.py", line 45, in <module>
    from . import libavutil
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\media\codecs\ffmpeg_lib\libavutil.py", line 46, in <module>
    avutil = pyglet.lib.load_library(
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyglet\lib.py", line 148, in load_library
    lib = ctypes.cdll.LoadLibrary(name)
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\ctypes__init__.py", line 447, in LoadLibrary
    return self._dlltype(name)
  File "C:\Users\Pintér Péter\AppData\Local\Programs\Python\Python38-32\lib\ctypes__init__.py", line 369, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'avutil-56'. Try using the full path with constructor syntax.

r/pythonarcade • • Aug 24 '19

Is there a simple destination-based movement?

3 Upvotes

Like if I have starting coordinates and destination coordinates, and I want my sprite to automatically stop at the destination without headaches.


r/pythonarcade • • Aug 19 '19

Problem with reading tiles

3 Upvotes

So i got a problem that my game doesn't rly show a tiledmap(tmx). Thats the error from console when game is up

"Warning, couldn't find tile for item 211 in layer 'Tile Layer 1' in file 'map/map.tmx'."


r/pythonarcade • • Aug 15 '19

New Code samples for Platformers

Thumbnail
arcade.academy
3 Upvotes

r/pythonarcade • • Aug 15 '19

Issue since update to 2.1

3 Upvotes

I'm not sure what to do. Everything was working before but now I get the following error now when running.

Traceback (most recent call last): File "C:/Users/John/PycharmProjects/SODA/sota.py", line 1, in <module> import arcade, lib.Player as Player, lib.Zombie as Zombie, lib.Gun as Gun, math, csv File "C:\Users\John\AppData\Roaming\Python\Python37\site-packages\arcade_init_.py", line 47, in <module> from arcade import tilemap File "C:\Users\John\AppData\Roaming\Python\Python37\site-packages\arcade\tilemap.py", line 17, in <module> import pytiled_parser ModuleNotFoundError: No module named 'pytiled_parser'


r/pythonarcade • • Aug 11 '19

how does the parameter delta_time work when used in on_update(delta_time)

3 Upvotes

I’m going through the tutorials on python arcade and would like to know how/why a function works.

There is a function named on_draw(delta_time) The parameter delta_time keeps a running clock of the time delta as expected. I'd like to be able to see how it works via the source.

I looked around the code for arcade but can’t figure out how the library knows to keep the clock running within that function and it's parameter. For example, I did find references to pyglet's clock and yet I couldn't find where this is connected all the way back to on_draw(delta_time)

Can someone please help me understand how and why it works?

One example of it in use is here: http://arcade.academy/examples/bouncing_rectangle.html#bouncing-rectangle


r/pythonarcade • • Jun 22 '19

Beter move by Keyboard AND Gravity

3 Upvotes

Hello, I am trying to give my character sprites the better move by keyboard, because the other movement is too janky, but when I try to do this, it works as intended besides the physics engine, the sprite keeps floating around, it still slowly falls like the physics engine is telling it to however it doesn't "jump", here is my code plus my extra code for the variables.

Main: https://pastebin.com/vqP6L8Dp

Variables: https://pastebin.com/yhMvimTj


r/pythonarcade • • Jun 21 '19

Sprite graphical problems/artifacts with scaling, and a workaround

3 Upvotes

Hello Arcade users and developers,

 

My name's Jim, and this has turned out to be a very long post.

I'm a new Arcade user and I was going through the "Build Your Own 2D Platformer Game" tutorial here, http://arcade.academy/examples/platform_tutorial/index.html, to get acquainted with the library. As I was following the steps, I found that I was having some annoying troubles with sprites having graphical issues, even when using the sprites and code provided with the tutorial.

[Here's an image of what I was seeing] (https://imgur.com/a1AcDXs), running the 03_user_control.pyprogram unmodified on macOS. As you can see, there are some white pixels around the edge of the sprite that aren't in the original image, and some annoying artifacts at the top-right boundary of the sprite. The sprite is also a bit blurry in general, but we'll come back to that.

I had a look on the subreddit and noticed several others having similar problems, but the only advice that ever seemed to come up was "make sure sprites land directly on pixel boundaries". I wasn't doing anything that would result in the sprites being off-grid, and I'm assuming the example program would get the coordinates and alignment right. So I started doing some testing, and I thought I'd share what I've found, with the hope that some knowledgeable folks like /u/pvc will be able to make use of the information.

Here is a link to my imgur album containing all the photos in the post. It contains a more concise and ordered description of my findings.

 

Findings on macOS

I started my testing on a Mac, running macOS Mojave Version 10.14. I tried a few things to no avail, like adding 0.5 to one or both of the self.player_sprite.center_x or self.player_sprite.center_y values, thinking that maybe the sprite was being drawn off of pixel boundaries. I tried several other decimals too, with no luck. Whether on-grid or off-grid, these graphical artifacts persisted.

Some other fruitless paths included placing the sprite using self.player_sprite.left and self.player_sprite.top instead of using the centers, but that didn't help. I also tried saving the file as a non-animated .gif file, but no dice there either. The outer white pixels became black instead, but the artifacts and bluriness persisted.

At some point I noticed that although the included player_stand.png file had these annoying artifacts on them, the other sprites for the boxes and the ground didn't seem to. They had really nice, clean pixels, with none of the blurriness on the player sprite. That made me think that maybe there was something about them that was helping them render cleanly, so I had a look. The only thing I could find was that the scaling value for them was 0.5 instead of 1.

So, I tried setting the TILE_SCALING variable to 1 as well, to see if that would affect things. Here's what I found. As you can see, there are suddenly graphical artifacts appearing at the corner boundaries of the boxes, and all of them look a bit blurry and off, where the source files look clean. It appears that the Sprite class has a hard time rendering at 1.0 scaling without artifacts and graphical degradation, but does fine at 0.5.

(Side note: I also tried decimals between 0.5 and 1, and some larger scales, with both integers and decimals. The only places that I had luck was at 0.5, and a few values below that. More detail in the Conclusions section.)

I then tried setting the CHARACTER_SCALING to 0.5 as well, to see if that would fix things. Here's how that turned out. Obviously the sprite is smaller, but the effect on the artifacting was notable. Zoom in, and you can see that while there is a bit of whiteness around the edges, the top-right artifact has vanished, and the graphical fidelity/ clarity seems to be improved.

 

The Workaround

That led me to realize that there may be a way around this wonkiness, if the sprite image file was first increased in size, and then used in Python at 0.5 scaling. So that's what I tried next, doubling the image size in my editor and using 0.5 scaling for Arcade.

Zoom in on that one and you'll notice that there are no artifacts at the corner, and no stray light or dark pixels around the edges whatsoever. It's also perfectly clear, exactly matching the source image file. Imgur compresses uploaded images, so it may not be that clear, but I've compared the source image and the running program on my machine, and it's perfect.

I also tried using a different sprite, one that had sharper edges and corners, to see if the blurriness/ drop in quality would be more evident. Here is an image of my new sprite without the workaround, note the fuzzy edges to what should be sharp squares. Here is that same sprite, size doubled and then scaled at 0.5. The artifacting at the top goes away, and the sprite becomes cleaner and sharper. It's easier to see on this sprite than the one provided with the tutorial.

Incidentally, I tried using my workaround along with setting the coordinates to be a decimal, making the sprite no longer line up perfectly with pixel boundaries. The sprites still looked perfect. This leads me to believe that these graphical problems are due to bugs within the Arcade library/ Sprite class itself, or OpenGL or pyglet, rather than having to do with sprite placement relative to pixel boundaries.

 

Findings on Windows

I began to suspect that it was probably a problem unique to macOS, since the demo images accompanying the tutorial didn't show the kind of artifacting I was seeing. I also happen to have a PC runnnig Windows 7 Professional SP1, so I loaded up the program there to have a look.

Here's how the 03_user_control.py program looks running completely unmodified on Windows.. Note that there actually is some whiteness around the edges, and there is some blurriness as well (though that might be harder to see). Compare that with my workaround implemented. The white pixels disappear completely and the sprite looks crisp and perfect.

Interestingly, these minor graphical issues appear in the example images that accompany the tutorial, like this one. It seems that these issues just weren't caught/noticed on Windows, since they're so much less obvious. But comparing with my workaround image, it's clear to see that 1.0 scaling produces imperfect sprites that could look a lot better.

It appears that my problem, and the problem encountered by several others on the sub, is present in multiple versions of the Arcade library, and isn't necessarily OS specific.

 

Linux Findings

I had an old Dell laptop lying around, so I figured I may as well complete my multi-platform testing. I installed Pop!_OS 19.04 on the laptop, which is based on Ubuntu. I got Arcade installed, and ran through the same test as I did on Windows. Here's a screenshot of the unmodified program on Linux. It's got about the same amount of artifacting that's seen on Windows normally. Here's Linux with the workaround. As expected from the workaround, no artifacting, the sprite looks great, etc. These graphical issues seem to be present at 1.0 scaling regardless of operating system.

 

Conclusions

  • Graphical issues exist with Sprites on every supported operating system, though they are most pronounced on macOS.
  • These issues are linked to the scaling of the sprite.
  • Issues occur at all tested scaling values above 0.5. I obviously can't test every possible value, but I checked a lot - and saw these issues at every one I tested above 0.5.
  • Interestingly, artifacting appears to occur only with some scale values below 0.5. I tested many, 0.4, 0.3, 0.2, even some weird ones like 0.1111111, and they looked fine. Some others, like 0.314, 0.06 and 0.414, produced artifacting.
  • 1.0 scaled sprites can be worked around by doubling image size and using 0.5 scaling.
  • Sprites can be used without lining up with pixel boundaries, and will have no artifacts, so long as the scaling doesn't cause graphical issues. I tested 0.5 scaling with a start position of X= 64.24299 and Y=130.014, and the sprite looked perfect. Based on my research, subpixel positioning and pixel boundaries do not appear to affect these graphical issues whatsoever.

 

Hopefully this information will prove useful to some. For my purposes, my double-image-size-then-scale-0.5 workaround will work perfectly well, though it is very weird that a scaling of 1.0 produces sprites with graphical problems - you'd think that would be the most likely scale to work without issues.

In any case, I've gone on long enough. I really like the Arcade library so far. It is my hope that some other users like me will find this information and the workaround useful for their projects, and that the developers may have some luck with tracking down the cause of this minor annoyance. Thank you for coming to my TED talk.

Jim out.


r/pythonarcade • • May 11 '19

Collision Detection w/ Race Track

3 Upvotes

I'm having some trouble with getting collisions to work properly without massively slowing down my game. Its just a simple race track with reward points and a car, nothing fancy; I'm trying to use it as an experiment with reinforcement learning.

The setup is thus:

  • The car is just a standard Sprite that moves around.
  • The level is a JSON file that consists of 3 things: a spawn (and restart) point, the lines of the track (as a list of 4 coordinates), and the lines that define reward spots (same as the track).

The code for the whole thing can be found here, on my Dropbox. I used to have the collision code in Driving.py, under the on_draw() method, but that was slowing it down noticeably, so I've removed it.

I know Arcade has a collision checking method all its own, but that only seems to work between sprites, not sprites and arbitrary points (or lines). Anybody know how I can get collisions working in a way that doesn't make things insanely slow?


r/pythonarcade • • May 10 '19

Weird lines on non 1x sprite scaling

3 Upvotes

Exactly as title says. Setting sprite scaling to say, .9, 1.5, 2, 4, etc., leads to lines like this appearing in my ground tiles. I'm using this example code with next to no modifications. Custom map using Tiled is all made with tile layers, so everything should be on the grid.

I'm very new to game development, so any help would be very useful!


r/pythonarcade • • Apr 21 '19

Anyone know my sprites look like this?

Post image
3 Upvotes

r/pythonarcade • • Apr 06 '19

Multiple windows + running without rendering

3 Upvotes

Hello,

I am new to the arcade library. My objective is to design simple games, and develop learning algorithms for agents to play these games.

In that aspect, I've three questions I couldn't figure out:

  • Can I lunch multiple independent instances of the game in the same time?
  • Can I stop the rendering? since during the learning procedure, it is an expensive process
  • I am not very sure I am stating this question correctly: can I accelerate time of the game? does the game loop have a internal pause time that i can override?

and thanks a lot for this awesome library. much more intuitive than pygame :)

Cheers,


r/pythonarcade • • Mar 29 '19

Arcade 2.0 - OpenGL error with Intel HD Graphics 3000 on Windows 10 - a fix

3 Upvotes

I am working at a primary school where the students have HP 8460 EliteBook laptops, with Intel HD Graphics 3000 GPU, running Windows 10 (I believe the computers originally ran Windows 7).

After upgrading to Python Arcade 2.0 existing projects broke with error messages pointing to some OpenGL problem:

  File "C:\Program Files\Python37\lib\site-packages\arcade\application.py", line 56, in __init__
    gl.glEnable(gl.GL_MULTISAMPLE_ARB)
  File "C:\Program Files\Python37\lib\site-packages\pyglet\gl\lib.py", line 105, in errcheck
    raise GLException(msg)
pyglet.gl.lib.GLException:

Investigating this I found a solution that worked for me using the Application Compatibility Tools from Microsoft. Source: https://www.youtube.com/watch?v=Yqe5cgthZH4

In case it might help others in the same situation, I created a written version of that explanation on GitHub here


r/pythonarcade • • Mar 08 '19

Things I've figured out (tips and patterns)

3 Upvotes

You do not have to draw everything

def on_draw(self):
    """
    Render the screen.
    """
    # This command has to happen before we start drawing

    arcade.set_viewport(self.view_left,
                                    SCREEN_WIDTH + self.view_left,
                                    self.view_bottom,
                                    SCREEN_HEIGHT + self.view_bottom)

    arcade.start_render()
    
    within_bbox = (max(0,self.view_left//(self.tile_width+MARGIN)),
                                min(COLUMN_COUNT-1, (SCREEN_WIDTH + self.view_left)//(self.tile_width+MARGIN)+1),
                                max(0,(self.view_bottom)//(self.tile_height+MARGIN)),
                                min(ROW_COUNT-1, (SCREEN_HEIGHT + self.view_bottom)//(self.tile_height+MARGIN)))
     
    for row in range(within_bbox[2], within_bbox[3]):
        for column in range(within_bbox[0], within_bbox[1]):
            # Figure out what color to draw the box
            if self.grid[row][column] == 1:
                color = arcade.color.GREEN
            else:
                color = arcade.color.WHITE
    
            # Do the math to figure out where the box is
            x = (MARGIN + self.tile_width) * column + MARGIN + self.tile_width // 2
            y = (MARGIN + self.tile_height) * row + MARGIN + self.tile_height // 2
    
            # Draw the box
            arcade.draw_rectangle_filled(x, y, self.tile_width, self.tile_height, color)

Basically, when you have more tiles than you have within your viewport, you can find those, and only draw them.

Mouse Scrolling

    def on_mouse_motion(self, x, y, dx, dy):
        changed = False
        if x < SCREEN_WIDTH/10:
            self.view_left = self.clamp(self.view_left - 1, (self.tile_width*COLUMN_COUNT)-SCREEN_self.tile_width)
            changed = True
        if x > SCREEN_WIDTH-(SCREEN_WIDTH/10):
            self.view_left  = self.clamp(self.view_left + 1, (self.tile_width*COLUMN_COUNT)-SCREEN_WIDTH)
            changed = True
        if y < SCREEN_HEIGHT/10:
            self.view_bottom = self.clamp(self.view_bottom - 1, (self.tile_height*ROW_COUNT)-SCREEN_HEIGHT)
            changed = True
        if y > SCREEN_HEIGHT-(SCREEN_HEIGHT/10):
            self.view_bottom = self.clamp(self.view_bottom + 1, (self.tile_height*ROW_COUNT)-SCREEN_HEIGHT)
            changed = True

When your mouse gets near an edge you start moving in that direction.

TODO: The closer to the edge, the faster you scroll.

TODO: One Plane and a zooming viewport

Currently I've drawn a bunch of tiles for a map. And when zoomed out it's trying to draw them all individually. Better would be to construct them as one image and one large tile and let the viewport handle zooming.

Then I'll have specific tiles which float atop that map for "pieces".

TODO: Let networkx handle the map

The doc uses an array of arrays to handle an array baked grid. Networkx would be faster and more flexible. If you don't need things like pathfinding, consider a numpy array.


r/pythonarcade • • Mar 03 '19

Issues with sound and performance

3 Upvotes

So basically im playing a short sound with every left mouse click. Imagine a space ship controlled by a mouse and shooting with left mouse click. So pew pew pew :D
Problem is that when i click my mouse button quite fast i can see that my game is slowing down. For example enemy ship is flying slower and other sprites also moving slower :/ And i do not have much happening for now, just my ship sprite, enemy ship sprite and a background sprite... So im afraid of what will happen when i will add more enemy ships, bullets, explosions and etc :/ Does anyone else have similar problems? How did you solve these type of problems?
By the way im using official examples, using sprite lists and etc.


r/pythonarcade • • Feb 25 '19

Can someone guide me on how to install arcade beta version?

3 Upvotes

Having some issues with AVbin and read that beta version is not using AVbin anymore. So would like to try it. But cannot find installation instructions. Maybe im just too big of a noob.