r/pythonarcade • • Jan 22 '24

How to calculate new hitbox after changing texture?

2 Upvotes

I'm just changing the texture by the self.texture property, but some of my sprites are even twice as big as others in the animations, and it is just off when the game does not register a clear hit.

I've tried using:

entity.set_hit_box(entity.get_adjusted_hit_box()

but it just makes all entities fall through the map.


r/pythonarcade • • Jan 21 '24

Arcade Not Working??

3 Upvotes

I've tried installing arcade multiple times using pycharm and replit but it never works and gives me errors/doesn't work at all. Is this because I need a less new python version??


r/pythonarcade • • Jan 08 '24

Heat Haze Shader

3 Upvotes

I’m trying to add a heat haze shader to my game, but every time I try something comes up and I can’t find any good documentation online. Does anybody know how to do this? I use Pycharm btw.


r/pythonarcade • • Jan 19 '24

Trouble displaying Japanese words in draw_text

2 Upvotes

I can't get the text to display properly in draw_text. I'm using VS code, UTF-8 encoding with python 3.9.7. I can input Japanese text, dump it using JSON which saves as unicode and read in the unicode and output to terminal no problem. I'm only having trouble displaying the Japanese on any arcade objects - text, buttons, ect.

I have tried different fonts but havent found one that works. The only other solution that comes to mind now is making a png for each word and making them all sprites...all 2000+ words.... Any ideas are welcome

Here's some sample code:

import arcade
class My_Game(arcade.Window):
def __init__(self):
self.WIDTH, self.HEIGHT = arcade.get_display_size()

super().__init__(width=self.WIDTH, height=self.HEIGHT, resizable=True)
self.kanji = "食"
self.uni_kanji = "\u98df"
def on_update(self, delta_time):
self.update(delta_time)
def on_draw(self):
arcade.start_render()
arcade.set_background_color(arcade.color.AMAZON)
arcade.draw_text(text=f"Kanji: {self.kanji} / Unicode: {self.uni_kanji}",
start_x=0,
start_y=self.HEIGHT * 0.75,
width=self.WIDTH,
align="center",
color=arcade.color.BLACK,
font_size=50)

arcade.draw_text(text=f"Kanji: {self.kanji} / Unicode: {self.uni_kanji}",
start_x=0,
start_y=self.HEIGHT * 0.5,
width=self.WIDTH,
align="center",
color=arcade.color.BLACK,
font_size=50,
font_name= "MS Gothic")

arcade.draw_text(text=f"Kanji: {self.kanji} / Unicode: {self.uni_kanji}",
start_x=0,
start_y=self.HEIGHT * 0.25,
width=self.WIDTH,
align="center",
color=arcade.color.BLACK,
font_size=50,
font_name= "FreeSans")

def on_key_press(self, key, modifier):
if key == arcade.key.ESCAPE:
arcade.exit()
My_Game()
arcade.run()


r/pythonarcade • • Jan 16 '24

Changing the color of SpriteSolidColor?

4 Upvotes

Hi! New to arcade and also to programming and I'm stuck on one thing. I have a little projects where ants are running around and if they pick up (collide) with food I want them to change color. But the color doesn't change...or it changes to something else that I wanted.

The ants are represented like this:

class Ant:
    def __init__(self, x, y, app):
        self.app = app
        self.color = arcade.color.RED
        self.shape = arcade.SpriteSolidColor(TILE_SIZE, TILE_SIZE, self.color)
        self.shape.center_x = x
        self.shape.center_y = y
        self.size = TILE_SIZE
        self.direction = self.get_random_direction()

And when I check for collision it seems to work because they do turn around, but the color doesn't change correctly:

        collision = arcade.check_for_collision(self.shape, self.app.food.shape)
        if collision:
            self.direction.x *= -1
            self.direction.y *= -1
            self.has_food = True
            self.shape.color = arcade.color.GREEN

Ants are drawn to the screen using the Spritelist.draw() method like this:

class Hive:
    def __init__(self, app):
        self.app = app
        self.size = TILE_SIZE * 3
        self.x = random.randrange(self.size * 2, SCREEN_WIDTH - self.size * 2)
        self.y = random.randrange(self.size * 2, SCREEN_HEIGHT - self.size * 2)
        self.color = arcade.color.AMBER
        self.shape = arcade.SpriteSolidColor(self.size, self.size, self.color)
        self.shape.center_x = self.x
        self.shape.center_y = self.y
        self.total_ants = 0
        self.ants = []
        self.ant_sprite_list = arcade.SpriteList(use_spatial_hash=False)

    def update(self):
        if self.total_ants < MAX_ANTS:
            self.spawn()
            self.total_ants += 1
        [ant.update() for ant in self.ants]
        self.ant_sprite_list.update()

    def draw(self):
        self.shape.draw()
        self.ant_sprite_list.draw()

    def spawn(self):
        ant = Ant(self.x, self.y, self.app)
        self.ants.append(ant)
        self.ant_sprite_list.append(ant.shape)

I changed to different colors around a lot, sometimes it changes to black on collision, sometimes doesn't change at all, but it never changes to the color I write in...no idea why, please help :)

In the screenshot below you can see how the ants that collided with the food (and also the borders for testing purposes) changed to black instead of green...

https://imgur.com/a/k1V6qNr


r/pythonarcade • • Feb 09 '24

GUI widget won’t disable when I hide view

4 Upvotes

I have a flat button that simultaneously hides the current view and shows a new view. I disable the manager in on_show_view but I can still click the buttons on the new view. Does anyone know what I’m doing wrong? Thanks


r/pythonarcade • • May 29 '21

A few questions about view/end screens and window sizes

3 Upvotes

I have just started learning python arcade for school and need to make a platformer game out of it. Just warning for everyone I don't really know code that well so there are probably some obvious things I'm missing out on.

I want a menu and main game level so I am using (arcade.view) to do this. This creates some problems with having a window resize option that I was going to add. Because I'm making a platformer that has to scroll with the player doesn't seem to work properly when I resize the window. I was going to fix this problem but having a set option of screen resolutions and on a button press it would then change the resolution of the screen but I also don't know how to change the resolution of the screen without manually changing it in the code. Any help would be great thanks

Here is a preview of the code

SCREEN_WIDTH = 1024
SCREEN_HEIGHT = 768
SCREEN_TITLE = "Platformer"

class MenuView(arcade.View):
    def on_show(self):
        self.background = arcade.load_texture(**background_image**)

    def on_draw(self):
        arcade.start_render()
        arcade.draw_lrwh_rectangle_textured(0, 0,
                                            SCREEN_WIDTH, SCREEN_HEIGHT,
                                            self.background)

    def on_mouse_press(self, _x, _y, _button, _modifiers):
        """ Use a mouse press to advance to the 'game' view. """
        game_view = MyGame()
        game_view.setup()
        self.window.show_view(game_view)

def main():
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable = True)

    game = MenuView()
    window.show_view(game)
    arcade.run()

if __name__ == "__main__":
    main()

What I have tried to do (Dont exactly know why this doesnt work so im just curious as to why)

SCREEN_WIDTH = 1024
SCREEN_HEIGHT = 768
SCREEN_TITLE = "Platformer"

class MenuView(arcade.View):
    def on_show(self):
        self.background = arcade.load_texture(**background_image**)

    def on_draw(self):
        arcade.start_render()
        arcade.draw_lrwh_rectangle_textured(0, 0,
                                            SCREEN_WIDTH, SCREEN_HEIGHT,
                                            self.background)
    def on_key_press(self, key, modifiers):
        if key == arcade.key.ENTER:
            SCREEN_WIDTH = 1920
            SCREEN_HEIGHT = 1080

    def on_mouse_press(self, _x, _y, _button, _modifiers):
        game_view = MyGame()
        game_view.setup()
        self.window.show_view(game_view)

def main():
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable = True)

    game = MenuView()
    window.show_view(game)
    arcade.run()

if __name__ == "__main__":
    main()

r/pythonarcade • • May 26 '21

Arcade 2.5.7 has been released

4 Upvotes

Arcade 2.5.7 is out! Arcade is a Python library for creating 2D games. See the release notes: https://arcade.academy/release_notes.html


r/pythonarcade • • May 23 '21

Safe highscore and create executable

3 Upvotes

Hi all,

currently working on a tiny game using arcade and right now adding score keeping. But I also want to add a highscore view, where the best results are stored permanently.

I later want to bundle the game into an executable in order to send it to other people so they can play. So that has to be taken into account when I want to set up the highscore functionality.

Do I have to use some kind of database in order to do this or can I do this using shelve? Really kinda lost at this point...


r/pythonarcade • • Oct 29 '17

What is "ShapeElementList"?

2 Upvotes

Line 15 of the "Skylines" example code reads

shape_list = arcade.ShapeElementList()

What is "ShapeElementList"? Running the example code gives me the error AttributeError: module 'arcade' has no attribute 'ShapeElementList', and I don't see it mentioned in any of the API listings or index.


r/pythonarcade • • Mar 18 '18

How to disable anti-aliasing

3 Upvotes

I'd like to make a game with a pixel art feel. When I load my assets they get smoothed an anti-aliased. How do I deactivate the smoothing in arcade to keep the assets original pixels?


r/pythonarcade • • Dec 06 '23

sensors - using PyMunk with Arcade

3 Upvotes

Hi,

I would like to use physics sensors for things like "the player is in front of the door". I cannot find sensors in the Arcade documentation or in the examples.

PyMunk has sensors. Can I use PyMunk instead of the built-in arcade.PymunkPhysicsEngine?

How hard would it be to expose the PyMunk sensors in arcade.PymunkPhysicsEngine?

Thanks.


r/pythonarcade • • Nov 26 '23

Curious about a splitscreen demo

4 Upvotes

Hellos,

having a hell of a time trying to wrap my head around setting up a splitscreen display for a co-op top-down game. Was hoping to assign 1/4 of the screen for each player, and have a camera or view focused on top of each of them as they walked around.

I've attempted playing with multiple cameras (2.6 and the 3.0.x dev branch) and their viewports, even going so far as to try and set up separate sections to manage each one, but no luck.

As such I was wondering if this is something actually possible and if so, would anyone more familiar with Arcade be willing to throw together a quick 20-30 line demo of how to do it?

Apologies for not providing any code myself, but I'm still at square one so this is less a debug (since nothing I've done has come close to working) and more an information ask. Any help would be much appreciated


r/pythonarcade • • Nov 22 '23

UIAnchorLayout

2 Upvotes

What Happened to UIAnchorLayout, is it no longer supported? And what can i use instead?

"""
Menu.

Shows the usage of almost every gui widget, switching views and making a modal.
"""
from typing import List

import arcade
import arcade.gui

# Screen title and size
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Making a Menu"


class MainView(arcade.View):
    """This is the class where your normal game would go."""

    def __init__(self):
        super().__init__()

        self.manager = arcade.gui.UIManager()

        switch_menu_button = arcade.gui.UIFlatButton(text="Pause", width=150)

        # Initialise the button with an on_click event.
        @switch_menu_button.event("on_click")
        def on_click_switch_button(event):
            # Passing the main view into menu view as an argument.
            menu_view = MenuView(self)
            self.window.show_view(menu_view)

        # Use the anchor to position the button on the screen.
        self.anchor = self.manager.add(arcade.gui.UIAnchorLayout())

        self.anchor.add(
            anchor_x="center_x",
            anchor_y="center_y",
            child=switch_menu_button,
        )

    def on_hide_view(self):
        # Disable the UIManager when the view is hidden.
        self.manager.disable()

    def on_show_view(self):
        """ This is run once when we switch to this view """
        arcade.set_background_color(arcade.color.DARK_BLUE_GRAY)

        # Enable the UIManager when the view is showm.
        self.manager.enable()

    def on_draw(self):
        """ Render the screen. """
        # Clear the screen
        self.clear()

        # Draw the manager.
        self.manager.draw()


class MenuView(arcade.View):
    """Main menu view class."""

    def __init__(self, main_view):
        super().__init__()

        self.manager = arcade.gui.UIManager()

        resume_button = arcade.gui.UIFlatButton(text="Resume", width=150)
        start_new_game_button = arcade.gui.UIFlatButton(text="Start New Game", width=150)
        volume_button = arcade.gui.UIFlatButton(text="Volume", width=150)
        options_button = arcade.gui.UIFlatButton(text="Options", width=150)

        exit_button = arcade.gui.UIFlatButton(text="Exit", width=320)

        # Initialise a grid in which widgets can be arranged.
        self.grid = arcade.gui.UIGridLayout(column_count=2, row_count=3, horizontal_spacing=20, vertical_spacing=20)

        # Adding the buttons to the layout.
        self.grid.add(resume_button, col_num=0, row_num=0)
        self.grid.add(start_new_game_button, col_num=1, row_num=0)
        self.grid.add(volume_button, col_num=0, row_num=1)
        self.grid.add(options_button, col_num=1, row_num=1)
        self.grid.add(exit_button, col_num=0, row_num=2, col_span=2)

        self.anchor = self.manager.add(arcade.gui.UIAnchorLayout())

        self.anchor.add(
            anchor_x="center_x",
            anchor_y="center_y",
            child=self.grid,
        )

        self.main_view = main_view

        @resume_button.event("on_click")
        def on_click_resume_button(event):
            # Pass already created view because we are resuming.
            self.window.show_view(self.main_view)

        @start_new_game_button.event("on_click")
        def on_click_start_new_game_button(event):
            # Create a new view because we are starting a new game.
            main_view = MainView()
            self.window.show_view(main_view)

        @exit_button.event("on_click")
        def on_click_exit_button(event):
            arcade.exit()

        @volume_button.event("on_click")
        def on_click_volume_button(event):
            volume_menu = SubMenu(
                "Volume Menu", "How do you like your volume?", "Enable Sound",
                ["Play: Rock", "Play: Punk", "Play: Pop"],
                "Adjust Volume",
            )
            self.manager.add(
                volume_menu,
                layer=1
            )

        @options_button.event("on_click")
        def on_click_options_button(event):
            options_menu = SubMenu(
                "Funny Menu", "Too much fun here", "Fun?",
                ["Make Fun", "Enjoy Fun", "Like Fun"],
                "Adjust Fun",
            )
            self.manager.add(
                options_menu,
                layer=1
            )

    def on_hide_view(self):
        # Disable the UIManager when the view is hidden.
        self.manager.disable()

    def on_show_view(self):
        """ This is run once when we switch to this view """

        # Makes the background darker
        arcade.set_background_color([rgb - 50 for rgb in arcade.color.DARK_BLUE_GRAY])

        # Enable the UIManager when the view is showm.
        self.manager.enable()

    def on_draw(self):
        """ Render the screen. """
        # Clear the screen
        self.clear()
        self.manager.draw()


class SubMenu(arcade.gui.UIMouseFilterMixin, arcade.gui.UIAnchorLayout):
    """Acts like a fake view/window."""

    def __init__(self, title: str, input_text: str, toggle_label: str, dropdown_options: List[str], slider_label: str):
        super().__init__(size_hint=(1, 1))

        # Setup frame which will act like the window.
        frame = self.add(arcade.gui.UIAnchorLayout(width=300, height=400, size_hint=None))
        frame.with_padding(all=20)

        # Add a background to the window.
        # Nine patch smoothes the edges.
        frame.with_background(texture=arcade.gui.NinePatchTexture(
            left=7,
            right=7,
            bottom=7,
            top=7,
            texture=arcade.load_texture(
                ":resources:gui_basic_assets/window/dark_blue_gray_panel.png"
            )
        ))

        back_button = arcade.gui.UIFlatButton(text="Back", width=250)
        # The type of event listener we used earlier for the button will not work here.
        back_button.on_click = self.on_click_back_button

        title_label = arcade.gui.UILabel(text=title, align="center", font_size=20, multiline=False)
        # Adding some extra space around the title.
        title_label_space = arcade.gui.UISpace(height=30, color=arcade.color.DARK_BLUE_GRAY)

        input_text_widget = arcade.gui.UIInputText(text=input_text, width=250).with_border()

        # Load the on-off textures.
        on_texture = arcade.load_texture(":resources:gui_basic_assets/toggle/circle_switch_on.png")
        off_texture = arcade.load_texture(":resources:gui_basic_assets/toggle/circle_switch_off.png")

        # Create the on-off toggle and a label
        toggle_label = arcade.gui.UILabel(text=toggle_label)
        toggle = arcade.gui.UITextureToggle(
            on_texture=on_texture,
            off_texture=off_texture,
            width=20,
            height=20
        )

        # Align toggle and label horizontally next to each other
        toggle_group = arcade.gui.UIBoxLayout(vertical=False, space_between=5)
        toggle_group.add(toggle)
        toggle_group.add(toggle_label)

        # Create dropdown with a specified default.
        dropdown = arcade.gui.UIDropdown(default=dropdown_options[0], options=dropdown_options, height=20, width=250)

        slider_label = arcade.gui.UILabel(text=slider_label)
        pressed_style = arcade.gui.UISlider.UIStyle(filled_bar=arcade.color.GREEN, unfilled_bar=arcade.color.RED)
        default_style = arcade.gui.UISlider.UIStyle()
        style_dict = {"press": pressed_style, "normal": default_style, "hover": default_style, "disabled": default_style}
        # Configuring the styles is optional.
        slider = arcade.gui.UISlider(value=50, width=250, style=style_dict)

        widget_layout = arcade.gui.UIBoxLayout(align="left", space_between=10)
        widget_layout.add(title_label)
        widget_layout.add(title_label_space)
        widget_layout.add(input_text_widget)
        widget_layout.add(toggle_group)
        widget_layout.add(dropdown)
        widget_layout.add(slider_label)
        widget_layout.add(slider)

        widget_layout.add(back_button)

        frame.add(child=widget_layout, anchor_x="center_x", anchor_y="top")

    def on_click_back_button(self, event):
        # Removes the widget from the manager.
        # After this the manager will respond to its events like it previously did.
        self.parent.remove(self)


def main():
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    main_view = MainView()
    window.show_view(main_view)
    arcade.run()


if __name__ == "__main__":
    main()

r/pythonarcade • • May 16 '17

getting mouse clicks without classes.

2 Upvotes

Hi great library that i have been using to teach a class of 13 to 14 yr olds python. I would like them to be able to use the mouse click yes or no on the screen, without introducing them to classes. I can do this in pyglet, but was wondering how to do it with arcade. i am quite a beginner myself. Thanks , i tried the following

import arcade

arcade.open_window("Drawing Example",640, 480, ) def on_mouse_press( x, y, button, modifiers): """ Called when the user presses a mouse button. """

if button == arcade.MOUSE_BUTTON_LEFT:
    print("Left mouse button pressed at", x, y)
elif button == arcade.MOUSE_BUTTON_RIGHT:
    print("Right mouse button pressed at", x, y)

arcade.run()


r/pythonarcade • • Mar 04 '18

Arcade and Pymunk Platformer Demo

Thumbnail arcade.academy
2 Upvotes

r/pythonarcade • • Oct 17 '17

Using Python Arcade for PyWeek 24 and loving it!

Thumbnail
pyweek.org
2 Upvotes

r/pythonarcade • • May 24 '17

Problem with create rectangle function

2 Upvotes

File "/usr/lib/python3.6/site-packages/arcade/draw_commands.py", line 1403, in create_rectangle data2 = gl.GLfloat * ctypes.c_float(len(v2f)) TypeError: can't multiply sequence by non-int of type 'c_float'


r/pythonarcade • • Mar 12 '18

Help: on_mouse_press - cannot get to work at all.

3 Upvotes

Im not sure if I've done something wrong, but even testing example code from arcade.academy, nothing is triggering on mouse presses. on_mouse_release works fine though.

For example, using this code: http://arcade.academy/examples/move_mouse.html#move-mouse

And changing the functions in question to:

def on_mouse_press(self, x, y, button, modifiers):
    """
    Called when the user presses a mouse button.
    """
    print('press')
    print(button)
    if button == arcade.MOUSE_BUTTON_LEFT:
        self.left_down = True

def on_mouse_release(self, x, y, button, modifiers):
    """
    Called when a user releases a mouse button.
    """
    print('release')
    if button == arcade.MOUSE_BUTTON_LEFT:
        self.left_down = False

I will only see the release printed to the console.


r/pythonarcade • • Mar 08 '18

New example showing speed of using ShapeElementLists

Thumbnail
arcade.academy
2 Upvotes

r/pythonarcade • • Dec 03 '17

Arcade 1.2.2 has been released

1 Upvotes

Arcade 1.2.2 has been released.

Release Notes

To upgrade:

pip install --upgrade arcade

Bug Fixes

  • Issue 143: Error thrown when using scroll wheel

  • Issue 128: Fix infinite loop in physics engine

  • Issue 127: Fix bug around warning with Python 3.6 when imported

  • Issue 125: Fix bug when creating window on Linux

Enhancements

  • Issue 147: Fix bug building documentation where two image files where specified incorrectly

  • Issue 146: Add release notes to documentation

  • Issue 144: Add code to get window and viewport dimensions

  • Issue 139: Add documentation on what collision_radius is

  • Issue 131: Add example code on how to do full-screen games

  • Issue 113: Add example code showing enemy turning around when hitting a wall

  • Issue 67: Improved support and documentation for joystick/game controllers

There are also more code examples available.


r/pythonarcade • • Oct 24 '24

Preparing metadata (setup.py) ... error

2 Upvotes

Hullo, I'm very very new to python, as well as the command prompt window where we use pip to get the library, so sorry if this is a painfully obvious thing that I'm missing. I'm trying to install the arcade library but have ran into "python setup.py egg_info did not run successfully." and I can't understand the following text that's used to figure out what went wrong:

[18 lines of output]

Traceback (most recent call last):

File "<string>", line 2, in <module>

exec(compile('''

~~~~^^^^^^^^^^^^

# This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

...<31 lines>...

exec(compile(setup_py_code, filename, "exec"))

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

''' % ('C:\\Users\\(name)\\AppData\\Local\\Temp\\pip-install-nk9d_e2v\\pillow_d85510c174b943b1a05cda0cc1bfa898\\setup.py',), "<pip-setuptools-caller>", "exec"))

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "<pip-setuptools-caller>", line 34, in <module>

File "C:\Users\(name)\AppData\Local\Temp\pip-install-nk9d_e2v\pillow_d85510c174b943b1a05cda0cc1bfa898\setup.py", line 29, in <module>

PILLOW_VERSION = get_version()

File "C:\Users\(name)\AppData\Local\Temp\pip-install-nk9d_e2v\pillow_d85510c174b943b1a05cda0cc1bfa898\setup.py", line 26, in get_version

return locals()["__version__"]

~~~~~~~~^^^^^^^^^^^^^^^

KeyError: '__version__'

[end of output]

I have a fresh installation of the latest version of python. Pip, setuptools, and wheels are all up-to-date as well, and I have C++. Am I missing something or what? Thanks.


r/pythonarcade • • Jan 15 '21

Using Spritesheets

4 Upvotes

I'm trying to utilize spritesheets in my game. The tutorials I've found use deprecated classes and I was wondering if anyone had experience or examples using the newer AnimatedTimeBasedSprite instead?


r/pythonarcade • • Jan 07 '21

Tank game using arcade module

Thumbnail
github.com
2 Upvotes

r/pythonarcade • • Jan 22 '19

How do you scale a sprite in the x or y axis?

2 Upvotes

So far trying to edit sprite attributes upon creation raises errors. Is there any way to scale a sprites width/height independently without using the ._set_width method?