r/pythonarcade • • Dec 18 '19

How to scale the window, and only the window?

4 Upvotes

Hi! I'm starting my first Python Arcade game.

Since I am looking for a "retro" feel to my game, I'd like the resolution of the game to be 256 x 240, but, of course, that's super tiny on any modern monitor. So I'd like the actual window to be (256 * 4) x (240 * 4).

In other words, I'd like to have all of my sprites, level design, and game logic to be "small", and then when drawing to the screen scale it up to be "big".

Do you know of a way to do this in Python Arcade (or Pyglet)?

Thank you!


r/pythonarcade • • Dec 21 '18

Arcade 2.0.0b3

4 Upvotes

Arcade 2.0.0b3 has been released. It improves backwards compatibility over the prior betas. You can install it via:

pip install arcade==2.0.0b3

My hope is to do a full 2.0 release soon.


r/pythonarcade • • Mar 15 '19

How to change each individual pixel's color

2 Upvotes

I want to be able to change the color of each individual pixels, so I can make something like the Mandelbrot. Is there a better way to do this the to draw small points?


r/pythonarcade • • May 02 '22

Are multiple Camera instances possible?

2 Upvotes

I’m working on a top-down 2D racing management-style game. I want the user to be able to control strategy for multiple cars, essentially making suggestions to two AI cars as they race against the computer-controlled AI cars.

I’ve been searching for a way to have three viewports showing essentially the same data (I’d much prefer not to run the calculation or draw the result three times, unless Arcade is built in such a way that makes that efficient) - one following one of the player team’s cars, another following the second player team’s car, and the third showing the entire circuit. I’ve seen the minimap tutorial, but I need two of the cameras to follow a sprite, and the minimap as tutorialized seems to only work as a static object.

Is what I’m looking to do possible within the scope of Arcade?


r/pythonarcade • • May 18 '22

Arcade 2.6.14 has been released

15 Upvotes

Arcade, an OpenGL based library for creating 2D games, has released version 2.6.14.

Website: https://arcade.academy

Release notes: https://api.arcade.academy/en/latest/development/release_notes.html

Demo video: https://www.youtube.com/watch?v=QClDvEwcxmg

  • Various Improvements

    • Allow specifying hit box parameters in load_textures() and load_spritesheet()

    • Camera should no longer apply zoom on the z axis

    • Promote using arcade.View.on_show_view() in examples and tutorials

    • The arcade window and views now expose arcade.Window.on_enter()
      arcade.Window.on_leave()
      . These events are triggered when the mouse enters and leaves the window area.

    • Sections should now also support mouse enter/leave events

    • Hit box calculation methods should raise a more useful error message when the texture is not RGBA.

    • Slight optimization in updating sprite location in SpriteList

    • Removed all remaining references to texture transforms

    • Removed the broken Sprite.__lt__
      method

    • Added get_angle_radians()

    • Removed Texture.draw_transformed

    • Add support for changing the pitch while playing a sound. See the speed parameter in arcade.play_sound().

    • Set better blending defaults for arcade GUI

    • Can now create a texture filled with a single color. See Texture.create_filled()
      . The Sprite class will use this when creating a solid colored sprite.

    • Bump version numbers of Sphinx, Pillow to current release as of 17-May.

    • Bump Pyglet version to 2.0.dev15. (Thanks Pyglet!)

  • Shadertoy

    • Added Shadertoy.delta_time
      alias for time_delta
      (iTimeDelta
      )

    • Support the iFrame
      uniform. Set frame using the arcade.experimental.ShadertoyBase.frame
      attribute

    • Support the iChannelTime
      uniform. Set time for each individual channel using the arcade.experimental.ShadertoyBase.channel_time
      attribute.

    • Support the iFrameRate
      uniform. Set frame rate using the arcade.experimental.ShadertoyBase.frame_rate
      attribute

    • Support the iDate
      uniform. This uniform will be automatically set. See arcade.experimental.ShadertoyBase._get_date()

    • Support the iChannelResolution
      uniform. This uniform will be automatically set

    • Added example using video with shadertoy

    • Improve Shadertoy docstrings + unit tests

  • Docs / Tutorials / Examples

    • Updated install docs

    • Added tutorial for compiling an arcade game with Nuika

    • Improved/extended shadertoy tutorials

    • Added example using textures with shadertoy

    • Added sprite rotation examples

    • Clarified the difference between arcade.View.on_show_view() and arcade.View.on_show()

    • Improved UIManager docstrings

    • Various annotation and docstring improvements

    • Fixed several broken links in docs

    • We’re now building PDF/EPUB docs

  • OpenGL

    • Added new method for safely setting shader program uniforms: arcade.gl.Program.set_uniform_safe(). This method will ignore KeyError
      if the uniform doesn’t exist. This is often practical during development because most GLSL compilers/linkers will remove uniforms that is determined to not affect the outcome of a shader.

    • Added new method for safely setting a uniform array: arcade.gl.Program.set_uniform_array_safe(). This is practical during development because uniform arrays are in most cases shortened by GLSL compiler if not all array indices are used by the shader.

    • Added arcade.gl.Texture.swizzle. This can be used to reorder how components are read from the texture by a shader making it easy to crate simple effects or automatically convert BGR pixel formats to RGB when needed.

    • Added ray marching example with fragment shader

    • Allow reading framebuffer data with 2 and 4 byte component sizes

    • Simplified texture atlas texture coordinates to make them easier to use in custom shaders.

    • Support dumping the atlas texture as RGB

    • Support dumping the atlas texture with debug lines showing texture borders

    • We no longer check GL_CONTEXT_PROFILE_MASK
      due to missing support in older drivers. Especially GL 3.1 drivers that can in theory run arcade

    • Various shader cleanups

  • Experimental

    • Added a simple profiler class


r/pythonarcade • • May 17 '19

Animated Sprite issues

2 Upvotes

Hello All,

My students and I are having different problems with animated sprites. Can someone please provide guidance how to ensure we are running the right versions of python and arcade. We are having different problems with different hardware, but all around animated sprites.

We are using IDLE and students are using various operating systems and hardware.

My last post on this didn't get an answer, so I'm assuming I'm missing something basic.

I'm a high school teacher, in New Zealand, teaching programming using arcade for the first time. We can get around this by not using animated sprites, but we are all excited about using them.

Thanks in advance.


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 • • Jul 29 '19

I've create my first AI with arcade

8 Upvotes

r/pythonarcade • • Apr 24 '18

How to create a 2D game with Python and the Arcade library

Thumbnail
opensource.com
9 Upvotes

r/pythonarcade • • Apr 21 '18

PyWeek 25 Arcade Game Submission

Thumbnail
github.com
5 Upvotes

r/pythonarcade • • May 16 '19

Window not rendering until resize (MacOS)

2 Upvotes

Hi,

I am running the example from: http://arcade.academy/examples/happy_face.html#happy-face

The window shows up, but does not render until I resize it, furthermore, when I am calling the arcade.open_window() function with resizable=True the window renders, but starts in fullscreen mode.

Somebody facing the same issue? I will try the same code tomorrow on some other Macs...

System: MacOS 10.14 Python 3.7.2 (venv using pipenv)

> python --version
Python 3.7.2

> pip list
Using pip3...
Package        Version
-------------- -------
arcade         2.0.9  
blinker        1.4    
future         0.17.1 
numpy          1.16.3 
Pillow         6.0.0  
pip            19.1.1 
pyglet         1.4.0b1
pyglet-ffmpeg2 0.1.12 
PyTMX          3.21.7 
setuptools     41.0.1 
six            1.12.0 
wheel          0.33.4 

r/pythonarcade • • May 20 '19

Running an creating test in Linux

2 Upvotes

Hello,

I'm new to arcade and I really like it so far. But it is missing some features that I want, so I have decided to help with what I can. I have worked with python for a few years but pytest is new for me so it would be great if someone could point me in the right direction.

First of all, is there any way to run only the test without running all commands in the make file?

The second question: Is there any documentation for how the test works and are run? I haven't manage to find any and I'm feeling lost looking at the source code for the test.


r/pythonarcade • • Aug 18 '18

arcade.color and the Drawing with Functions tutorial

3 Upvotes

Teaching myself arcade (and python) as I am looking for a fun lightweight linux-friendly way to refresh my game dev skills... the last time I tried anything like this it was in C++ about a decade ago.

In the Drawing with Functions tutorial, even if I copy-paste the entire code, I cannot get the birds to show up when drawing them in arcade.color.BLACK.

Strangely enough, they show up if I choose another color, such as WHITE or BEAVER. But not with BLACK_BEAN.

Also strangely, I can, say, change the color of the trees to BLACK and they draw just fine.

Any clues as to what is going on here? I am running in mint 18.1.


r/pythonarcade • • Feb 24 '19

Did anyone tried to package their game made with Arcade?

4 Upvotes

So did anyone tried to use cx_Freeze or something similar? How was is it? Did you managed to do it?


r/pythonarcade • • Feb 08 '23

Screen flickering on MacBooks with M1/M2 chips

2 Upvotes

Hi,

we developed this game with python arcade on Linux and an older MacBook with Intel chip. When we run it on newer MacBooks with M1/M2 chips some views flicker.

Has anyone encountered a similar issue?

cheers

Jake


r/pythonarcade • • Feb 08 '23

Is there a way to load only part of a tilemap?

5 Upvotes

I have a large tiled tilemap and while loading it the game hangs. Even after 5 minutes the game still loads. Is there a way to only the part of the map that is around the player? Here is the the tilemap if someone is interested.

https://xfl.jp/rtgxNM

I really appreciate any help you can provide.


r/pythonarcade • • Nov 04 '22

Compute shaders: errors when combining with matplotlib

2 Upvotes

Hello everybody, I'm discovering arcade, and want to use it for a non-gaming application (radiative transfer code). In particular, using the compute shaders as the demo on the arcade website. I posted the full question on stack overflow here: SO_link

In short, when combining the particle shader with matplotlib, I encounter this error, and can't find any comprehensive info on this (maybe I did, but did not regognize it as such since I'm a shader newb...):

(python:20832): GLib-GIO-CRITICAL **: 14:10:15.559: g_application_run() cannot acquire the default main context because it is already acquired by another thread!

(python:20832): Gdk-WARNING **: 14:10:15.563: gdk_gl_context_make_current() failed

Anybody knows this issue, or a good beginner friendly tuto on this?


r/pythonarcade • • Nov 01 '22

I'm getting an Key Error when I try to add my enemy layer in my platformer

3 Upvotes

I've been following the api arcade acadmady to code a platformer for fun and its been going smoothly up unitl this point https://api.arcade.academy/en/latest/examples/platform_tutorial/step_13.html#source-code the rest of my code works but when I try to add my enemy layer from tiled it says: line 256, in setup

enemies_layer = self.tile_map.object_lists[LAYER_NAME_ENEMIES]

KeyError: 'Enemies'

which im really confused by since I have an enemy object layer.

I have even tried there .json file from github and get the same error if anyone has any idea how I could fix this I would very much appreciate the help


r/pythonarcade • • Oct 27 '22

Set color from a list of names

1 Upvotes

I am porting a game that I made with Turtle graphics, and running into trouble with the colors. I used color names as dictionary keys for several sprite attribute, including their colors. I can't figure out how to use the same dictionary to set the colors of my sprite in arcade. For instance, suppose my allowable colors are

CAR_COLORS = ["RED", "BLACK", "RAJAH", "BRIGHT_GREEN", "BRIGHT_NAVY_BLUE", "BOYSENBERRY"]

I know I could use (for example) myspriteclassinstance.color = arcade.color.RAJAH But I want to store those colors names as strings, not as arcade colors...I want to be able to use them as lookup keys also:

myspriteclassinstance.colorname = "RAJAH"
myspriteclassinstance.threat = THREATLIST[myspriteclassinstance.colorname]
myspriteclassinstance.color = ???????? #I don't know what to put here, but I want it to be RAJAH colored.

Any suggestions?


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 • • 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 29 '20

how to best use Vector2 and Vector3 classes from pygame in arcade?

2 Upvotes

While trying to port some projects from pygame to arcade i run into this question:

my pygame projects make much use of pygame.math.Vector2 ( and pygame.math.Vector3) classes.

I discovered an internal _Vec2 class in arcade.utils, but it has not all the features i need for 2D Vectors.

Is the recommended way to extend/replace the _Vec2 class in arcade.utils or is it better to create my own Vector2 / Vector3 classes and leave arcade.utils alone ?


r/pythonarcade • • Oct 26 '20

Help with arcade in Mac

4 Upvotes

Hello, I need help.

I recently installed the arcade library in PyCharm, and I am having trouble whenever I try to draw circles or ellipses. I have tried using previous versions of python (rolling back from 3.9 to 3.7) as well as rolling back the bumpy version(1.19 to 1.18) however, none of these solutions work. The problem looks as follows:

Here is another example when running one of the test scripts from the arcade website:

Anyone knows how to fix this? thanks for your help.


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 • • Nov 09 '20

Using arcade to dynamically generate still images of a game board....

4 Upvotes

Hi all! I’ve written a function to use arcade to draw a game board based on two strings of data that I pass to the function.

I’m doing this by basically drawing the board, and then using the input strings to locate sprites as the game pieces. This works great the first time I call the function in my script, the second time through the loop, however, I get an error that says this: “pyglet.gl.ContextException: Unable to share contexts.”

Any ideas on this? Or should I just not use arcade for this application? sorry I’m very much a beginner with python and arcade. Thank you all !!