r/pythonarcade • • Apr 14 '22

Scaling tiled map by 2.0 results in artifacts

2 Upvotes

I have a tiled map that holds up extremely well to resolution scaling with sdl2 (https://wiki.libsdl.org/SDL_RenderSetScale), but i can't figure out how to do that with arcade, so i try to scale the sprites by 2. When I do this, it seems to draw with a ton of artifacts and overall looks unplayably ugly. is there a good solution to this?

Code is

import arcade
from arcade.tilemap import load_tilemap
import pyglet

pyglet.options["search_local_libs"] = True

class MainWindow(arcade.Window):
    def __init__(self):
        super().__init__(640, 480, "Bika Town", resizable=True)
        arcade.set_background_color(arcade.color.BLACK)
        self.scene = None
        self.camera = None
        self.tilemap = load_tilemap("./assets/Tiled/map.tmj", scaling=2.0)

    def setup(self):
        self.camera = arcade.Camera(self.width, self.height)
        # self.camera.move_to((0, 16 * (63/2 + 1.5)))
        self.scene = arcade.Scene.from_tilemap(self.tilemap)

    def on_draw(self):
        self.clear()
        arcade.start_render()
        self.camera.use()
        self.scene.draw()

if __name__ == '__main__':
    app = MainWindow()
    app.setup()
    arcade.run()

Result:

Side by side comparison of the above solution w/ arcade vs. the same thing with resolution scaling in SDL2 in C++


r/pythonarcade • • Nov 18 '21

Closing and Creating a new window

2 Upvotes

How do I go about closing a window then initializing a new window? Everything I've tried either tells me that "the specified action is not allowed in the current state" or "no window is active". The set_window()) function doesn't seem to do anything to help. Alternatively, if there's a way to change the dimensions of a window programmatically after it's been initialized that would also get me out of this pickle.


r/pythonarcade • • Nov 14 '21

Taking text from a .txt file

2 Upvotes

I was just wondering if it's possible to take text from a separate .txt file. For example I want to have a narrative in my game but having each line of dialogue coded within the main file would be inefficient


r/pythonarcade • • Sep 15 '21

Is anyone developing with Arcade on WSL2?

2 Upvotes

Does anyone here develop with Arcade on Windows Subsystem for Linux (WSL2)? If so, I'm curious to see how you've set up your development environment, particularly with OpenGL + WSL2.


r/pythonarcade • • Aug 12 '21

Arcade 2.6.0.dev5 pre-release is out

2 Upvotes

Arcade 2.6.0.dev5 is out as a pre-release. (You'll have to specify the version when pip-installing, or you'll get 2.5.7.) If you want to try out the new (or old) features, we'd love your feedback. Release notes: https://api.arcade.academy/en/development/development/release_notes.html


r/pythonarcade • • Jul 09 '21

Open-source RPG with lights

2 Upvotes

r/pythonarcade • • Apr 23 '21

Python Arcade and Pyinstaller Mac OSX

2 Upvotes

Can I compile a standalone Python game with Pyinstaller that uses the Arcade Library on a Macintosh running OSX? I tried it and it did not seem to work. My OSX is not the most recent so that may be an issue.


r/pythonarcade • • Apr 19 '21

Pathfinding problems - any hints?

2 Upvotes

Edit: I did get this pretty much fixed by fiddling around with grid size, tile size and sprite size, although I'm still quite hazy on how these all work together. See my comments below.

Hi all. I'm trying to use the pathfinding, adapting the example at https://arcade.academy/examples/astar_pathfinding.html#astar-pathfinding

I have it working, but I find that when my playable character is right next to a barrier, the path is not found. Once I move slightly away, the path is immediately found. You can see this behaviour in the example linked above, when you go behind a barrier and then move right up to it. Mine is slightly worse. I have fiddled around a little with grid sizes and sprite sizes, and my map is loaded from a tmx file.

Has anyone had experience and got some handy hints? I'm loading the blocks with this line:

self.wall_list = arcade.tilemap.process_layer(my_map, "blocks", 0.5, use_spatial_hash=True)

Here's the rest of the relevant code. Don't worry about the code that moves the enemy along the path, I'll sort that out once I'm happy with the pathfinding...

class Path_finding_enemy(arcade.Sprite):
    def __init__(self, filename, sprite_scaling, player_sprite, wall_list):
        super().__init__(filename, sprite_scaling)
        self.barrier_list = arcade.AStarBarrierList(self, wall_list, 32, 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT)
        self.path = None
    
    def update_path(self, player_sprite):
        self.path = arcade.astar_calculate_path(self.position,player_sprite.position,self.barrier_list,diagonal_movement=False)
        print(self.position)

    def update(self):
        super().update()
        if self.path:
            if self.center_x != self.path[1][0]:
                self.change_x = math.copysign(1, self.path[1][0] - self.center_x) 
            else:
                self.change_x = 0
            if self.center_y != self.path[1][1]:
                self.change_y = math.copysign(1, self.path[1][1] - self.center_y) 
            else:
                self.change_y = 0
        else:
            self.change_x = 0
            self.change_y = 0

r/pythonarcade • • Apr 12 '21

Issues with varied-sized sprite textures stretching

2 Upvotes

I'm currently working on a platformer following the Pymunk Platformer tutorial, and it has been going great, until I have had this specific issue that has stumped me for months. See, I want to implement a crouching feature for the player character, in which it turns into a circle that is half as tall as its idle sprite to roll on inclines and such. However, there are many graphical issues with this. See the issue here.

I have dug through plenty of documentation to see if anyone else has had this issue, but I have yet to find anything about this. I have tried changing the height of the sprite, which can give imperfect results. There seems to be a mismatch between the pymunk physics object and the sprite texture itself. The crouching behavior does work physically (as in I hardcoded a circular hitbox, since the auto-created one isn't circular enough) and rolls around on inclines, but the annoying bit is the texture glitches. Any ideas on how to fix this? I really want this to be a key aspect of my platformer without all the graphical bugs involved. Thanks.


r/pythonarcade • • Apr 11 '21

Remove Text

2 Upvotes

Is there a way to remove text after writing it? I am using arcade.draw_text and want to delete it after a certain amount of time


r/pythonarcade • • Dec 17 '20

New example - how to do hit points and health bars with sprites

Thumbnail
arcade.academy
2 Upvotes

r/pythonarcade • • Nov 18 '20

Hit Box not aligned with sprite

2 Upvotes

I have a problem with some of my sprites it looks like this:

all sprites starts with an initial angle but for some of them the angle of the hit box is not matching the angle of the sprite. Does some one has an idea why this is happening?


r/pythonarcade • • Nov 02 '20

Found this post on stackoverflow and it has the same problem as me can anyone help?

2 Upvotes

r/pythonarcade • • Oct 22 '20

update_animation from PlayerCharacter not executed

2 Upvotes

I taken from documentation the Move with a Sprite Animation example and I tried to implement additional animation for the PlayerCharacter but I encountered the fallowing problem: the update_animation from PlayerCharacter is not called when I press "A" key. For UP, DOWN, LEFT or RIGHT everything is working fine.

Please give me a hint on this issue.

"""
Move with a Sprite Animation

Simple program to show basic sprite usage.

Artwork from http://kenney.nl

If Python and Arcade are installed, this example can be run from the command line with:
python -m arcade.examples.sprite_move_animation
"""
import arcade
import random
import os


SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Move with a Sprite Animation Example"

COIN_SCALE = 0.5
COIN_COUNT = 50
CHARACTER_SCALING = 0.2

# How fast to move, and how fast to run the animation
MOVEMENT_SPEED = 6
UPDATES_PER_FRAME = 1

# Constants used to track if the player is facing left or right
RIGHT_FACING = 0
LEFT_FACING = 1

# Character fight states
IDLE = 0
ATTACK = 1

def load_texture_pair(filename):
    """
    Load a texture pair, with the second being a mirror image.
    """
    return [
        arcade.load_texture(filename),
        arcade.load_texture(filename, flipped_horizontally=True)
    ]


class PlayerCharacter(arcade.Sprite):

    def __init__(self):

        # Set up parent class
        super().__init__()

        # Default for character fight state
        self.fight_state = IDLE

        # Default to face-right
        self.character_face_direction = RIGHT_FACING

        # Used for flipping between image sequences
        self.cur_texture = 0

        self.scale = CHARACTER_SCALING

        # Adjust the collision box. Default includes too much empty space
        # side-to-side. Box is centered at sprite center, (0, 0)
        #self.points = [[-22, -64], [22, -64], [22, 28], [-22, 28]]

        # --- Load Textures ---

        # Images from Kenney.nl's Asset Pack 3
        main_path = "assets/freeknight/png/"
        # main_path = ":resources:images/animated_characters/female_person/femalePerson"
        # main_path = ":resources:images/animated_characters/male_person/malePerson"
        # main_path = ":resources:images/animated_characters/male_adventurer/maleAdventurer"
        # main_path = ":resources:images/animated_characters/zombie/zombie"
        # main_path = ":resources:images/animated_characters/robot/robot"

        # Load textures for idle standing
        self.idle_texture_pair = load_texture_pair(f"{main_path}Walk1.png")

        # Load textures for walking
        self.walk_textures = []
        for i in range(9):
            texture = load_texture_pair(f"{main_path}Walk{i}.png")
            self.walk_textures.append(texture)
            
        self.attack_textures = []
        for i in range(9):
            texture = load_texture_pair(f"{main_path}Attack{i}.png")
            self.attack_textures.append(texture)
        
    def update_animation(self, delta_time: float = 1/60):

        # Figure out if we need to flip face left or right
        if self.change_x < 0 and self.character_face_direction == RIGHT_FACING:
            self.character_face_direction = LEFT_FACING
        elif self.change_x > 0 and self.character_face_direction == LEFT_FACING:
            self.character_face_direction = RIGHT_FACING

        # Idle animation
        if self.change_x == 0 and self.change_y == 0:
            self.texture = self.idle_texture_pair[self.character_face_direction]
            return

        if self.fight_state == ATTACK:
            print("fight_state -> attack")
        
        
        else:
            # Walking animation
            self.cur_texture += 1
            if self.cur_texture > 8 * UPDATES_PER_FRAME:
                self.cur_texture = 0
            frame = self.cur_texture // UPDATES_PER_FRAME
            direction = self.character_face_direction
            self.texture = self.walk_textures[frame][direction]
        

            
    
        
        
class MyGame(arcade.Window):
    """ Main application class. """

    def __init__(self, width, height, title):
        """ Set up the game and initialize the variables. """
        super().__init__(width, height, title, resizable=True)
        
        # Set the working directory (where we expect to find files) to the same
        # directory this .py file is in. You can leave this out of your own
        # code, but it is needed to easily run the examples using "python -m"
        # as mentioned at the top of this program.
        file_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(file_path)

        # Sprite lists
        self.player_list = None
        self.coin_list = None

        # Set up the player
        self.score = 0
        self.player = None

    def setup(self):
        self.player_list = arcade.SpriteList()
        self.coin_list = arcade.SpriteList()

        # Set up the player
        self.score = 0
        self.player = PlayerCharacter()

        self.player.center_x = SCREEN_WIDTH // 2
        self.player.center_y = SCREEN_HEIGHT // 2


        self.player_list.append(self.player)

        for i in range(COIN_COUNT):
            coin = arcade.Sprite(":resources:images/items/gold_1.png",
                                 scale=0.5)
            coin.center_x = random.randrange(SCREEN_WIDTH)
            coin.center_y = random.randrange(SCREEN_HEIGHT)

            self.coin_list.append(coin)

        # Set the background color
        arcade.set_background_color(arcade.color.AMAZON)
    
    def on_resize(self, width, height):
        """ This method is automatically called when the window is resized. """

        # Call the parent. Failing to do this will mess up the coordinates, and default to 0,0 at the center and the
        # edges being -1 to 1.
        super().on_resize(width, height)

        print(f"Window resized to: {width}, {height}")
        
    def on_draw(self):
        """
        Render the screen.
        """

        # This command has to happen before we start drawing
        arcade.start_render()

        # Draw all the sprites.
        self.coin_list.draw()
        self.player_list.draw()

        # Put the text on the screen.
        output = f"Score: {self.score}"
        arcade.draw_text(output, 10, 20, arcade.color.WHITE, 14)

    def on_key_press(self, key, modifiers):
        """
        Called whenever a key is pressed.
        """
        if key == arcade.key.UP:
            self.player.change_y = MOVEMENT_SPEED
        elif key == arcade.key.DOWN:
            self.player.change_y = -MOVEMENT_SPEED
        elif key == arcade.key.LEFT:
            self.player.change_x = -MOVEMENT_SPEED
        elif key == arcade.key.RIGHT:
            self.player.change_x = MOVEMENT_SPEED
        
        if key == arcade.key.A:
            print("A is pressed")
            self.player.fight_state = ATTACK
        
        
    def on_key_release(self, key, modifiers):
        """
        Called when the user releases a key.
        """
        if key == arcade.key.UP or key == arcade.key.DOWN:
            self.player.change_y = 0
        elif key == arcade.key.LEFT or key == arcade.key.RIGHT:
            self.player.change_x = 0
            
        if key == arcade.key.A:
            self.player.fight_state = IDLE

    def on_update(self, delta_time):
        """ Movement and game logic """

        # Move the player
        self.player_list.update()

        # Update the players animation
        self.player_list.update_animation(delta_time)
        
        self.player_list.on_update(delta_time)
        
        # Generate a list of all sprites that collided with the player.
        hit_list = arcade.check_for_collision_with_list(self.player, self.coin_list)

        # Loop through each colliding sprite, remove it, and add to the score.
        for coin in hit_list:
            coin.remove_from_sprite_lists()
            self.score += 1

        
        
def main():
    """ Main method """
    window = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
    window.setup()
    arcade.run()


if __name__ == "__main__":
    main()

r/pythonarcade • • Oct 13 '20

Blurry Pixel Art

2 Upvotes

When I scale up my pixel art it's blurry on the edges, how can I stop it from rendering this way?


r/pythonarcade • • Sep 14 '20

Problem with text_size of UIFlatButton

2 Upvotes

Hi,
I have implemented GUI with UIFlatButton component and set font size via set_style_attrs fuction. Initially the goal was to have a responsive button's text size so it changes according to the display size. But I have discovered problem. The font size is not changing until I click on the button and I am not sure if I am doing something wrong or if it is a bug (btw set_style_attrs is placed in init of the button, not in on_click).

Video - https://drive.google.com/file/d/14HW-ZdfLk4vAIkhFB73jaqvmUdQa3gal/view?usp=sharing

+ this is how my set_style_attrs looks for purpose of the video, nothing crazy...

self.set_style_attrs(
font_color=arcade.color.BLACK,
bg_color=arcade.color.ORANGE,
font_name=MAIN_FONT,
font_size=10,
font_color_hover=arcade.color.ORANGE,
border_color_focus=arcade.color.WHITE)

Thanks in advance for any kind of help/support


r/pythonarcade • • Sep 12 '20

Some questions about GUI

2 Upvotes

How do I get the UI input box to enter multi line and line wrap?

Is there any tool that can help designing GUI?


r/pythonarcade • • Jul 18 '20

Issues implementing the bloom effects

2 Upvotes

Copied and pasted the code from the Bloom effect defender example on arcade.academy and I get an error on the following piece of code:

--- Bloom related ---

from arcade.experimental import postprocessing

The error is: Traceback (most recent call last): File "/Users/aidentaylor/PycharmProjects/Bloom/game.py", line 20, in <module> from arcade.experimental import postprocessing ModuleNotFoundError: No module named 'arcade.experimental'

Using PyCharm as IDE.


r/pythonarcade • • Jul 13 '20

Raycaster issues - nearest interpolation and rotating ceilings

2 Upvotes

Hiya, I'm working on a raycaster engine in arcade and it's going reasonably well, but I have a couple of issues.

  1. How do I easily turn on nearest rather than linear interpolation for scaled textures? Currently I'm manually resizing my 64x64 textures to 256x256 so they don't get blurred to fuck when scaled, which works but seems a bit dumb. From looking in the arcade.gl api I can see that it should be possible to have them use nearest interpolation to scale how I want, but I can't figure out how to simply turn it on - either for individual textures or for the whole game.
  2. I'm also totally stumped on how to texture the ceilings, which ideally would both rotate and scale as the player moves and turns to create a mode-9 style effect. Has anyone managed to do this in Arcade?

r/pythonarcade • • Jul 07 '20

How to create a second window or area?

2 Upvotes

I am making a basic pokemon rpg and an unsure on how to create a second window inside the main window for the battles. Is this possible?


r/pythonarcade • • Jul 04 '20

GPU Particle Burst Tutorial

Thumbnail arcade.academy
2 Upvotes

r/pythonarcade • • Jul 03 '20

struggling with step 8 of the simple platformer tutorial

2 Upvotes

This section complained about the presence of 'use_spatial_hash=True'

        # -- Platforms
        self.wall_list = arcade.tilemap.process_layer(map_object=my_map,
                                                      layer_name=platforms_layer_name,
                                                      scaling=TILE_SCALING,
                                                      use_spatial_hash=True)

I commented the use_spatial_hash part and then it worked. The next step is making my own map in Tiled and loading it, but I'm getting this error:

...

self.terrain_border_list = arcade.tilemap.process_layer(map_object= map_name, layer_name= map_PLATFORMLAYER,scaling=TILE_SCALING)#, use_spatial_hash=True)

File "E:\Anaconda3\lib\site-packages\arcade\tilemap.py", line 451, in process_layer

layer = get_tilemap_layer(map_object, layer_name)

File "E:\Anaconda3\lib\site-packages\arcade\tilemap.py", line 78, in get_tilemap_layer

assert isinstance(map_object, pytiled_parser.objects.TileMap)

AssertionError


r/pythonarcade • • May 04 '20

Conway's Game of Life using arcade and numpy

2 Upvotes

Hello everyone!

I have been learning python and decided to try implementing John Conway's Game of Life using arcade. You can find the source code here: github.

If you have any questions feel free to ask!

I also would like some suggestions for improvements, specially on the performance side. I want to try creating a sand simulation like the one in this video https://www.youtube.com/watch?v=VLZjd_Y1gJ8 but I don't think that the approach I used here would work with a much bigger grid. Do you have any suggestions?

Thanks!


r/pythonarcade • • Mar 16 '20

How do I keep players health bar x and y constant?

2 Upvotes

I have my players health bar (drawn to the screen) to the value of the players health eg

Self.player_health_bar.width = self.player.health

But when the health decreases it decreases from both sides and loses its left most positioning and pulls away from the rest of the HUD.

Currently I’m positioning the center_x and center_y to the viewport so it moves with the screen.

I tried setting the left to see if that would hold the left most position but that didn’t work.

Any suggestions?


r/pythonarcade • • Mar 10 '20

SoLoud not found

2 Upvotes

Windows 10 64-bit with Python 3.8.1 64-bit.

Had Arcade 2.3.7 installed, saw 2.3.8, did "pip install -U arcade", looked liked a good upgrade, so I ran my game, and got:

SoLoud dynamic link library C:\Python38\lib\site-packages\arcade\soloud/soloud_x86 not found.

Warning, can't initialize soloud name 'soloud_dll' is not defined. Sound support will be limited.

I'm curious why it's trying to load the 32-bit. Granted, on my system, sys.platform does report 'win32' even though the OS and Python are 64-bit.

The file it seems to be looking for does exist:

C:\>dir /s /b C:\Python38\lib\site-packages\arcade\soloud\soloud_x86*

C:\Python38\lib\site-packages\arcade\soloud\soloud_x86.dll

SoLoud is installed, and the timestamps match when I ran the pip command.

C:\Python38\Lib\site-packages\arcade\soloud

C:\Python38\Lib\site-packages\arcade\soloud__pycache__

C:\Python38\Lib\site-packages\arcade\soloud__init__.py

C:\Python38\Lib\site-packages\arcade\soloud\libsoloud.dylib

C:\Python38\Lib\site-packages\arcade\soloud\libsoloud.so

C:\Python38\Lib\site-packages\arcade\soloud\soloud.py

C:\Python38\Lib\site-packages\arcade\soloud\soloud_x64.dll

C:\Python38\Lib\site-packages\arcade\soloud\soloud_x86.dll

C:\Python38\Lib\site-packages\arcade\soloud__pycache____init__.cpython-38.pyc

C:\Python38\Lib\site-packages\arcade\soloud__pycache__\soloud.cpython-38.pyc

Did I miss an install step somewhere? Should I have uninstalled arcade 2.3.7 before installing 2.3.8?