forked from pythonarcade/arcade
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update for Issue pythonarcade#26, having example code with window res…
…izing.
- Loading branch information
Showing
4 changed files
with
65 additions
and
70 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
.. _resizable-window: | ||
:orphan: | ||
|
||
.. _resizable_window: | ||
|
||
Resizable Window | ||
================ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Example showing how handle screen resizing. | ||
""" | ||
import arcade | ||
|
||
SCREEN_WIDTH = 500 | ||
SCREEN_HEIGHT = 500 | ||
START = 0 | ||
END = 2000 | ||
STEP = 50 | ||
|
||
|
||
class MyApplication(arcade.Window): | ||
""" | ||
Main application class. | ||
""" | ||
|
||
def __init__(self, width, height): | ||
super().__init__(width, height, title="Resizing Window Example", resizable=True) | ||
|
||
arcade.set_background_color(arcade.color.WHITE) | ||
|
||
# Create some text labels for our coordinates | ||
self.label_list = [] | ||
for y in range(START, END, STEP): | ||
my_text = arcade.create_text(f"{y}", arcade.color.BLACK, 12, anchor_x="left", anchor_y="bottom") | ||
self.label_list.append(my_text) | ||
|
||
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. """ | ||
|
||
arcade.start_render() | ||
|
||
# Draw the y labels | ||
i = 0 | ||
for y in range(START, END, STEP): | ||
arcade.draw_point(0, y, arcade.color.BLUE, 5) | ||
arcade.render_text(self.label_list[i], 5, y) | ||
i += 1 | ||
|
||
# Draw the x labels. | ||
i = 1 | ||
for x in range(START + STEP, END, STEP): | ||
arcade.draw_point(x, 0, arcade.color.BLUE, 5) | ||
arcade.render_text(self.label_list[i], x, 5) | ||
i += 1 | ||
|
||
|
||
def main(): | ||
MyApplication(SCREEN_WIDTH, SCREEN_HEIGHT) | ||
arcade.run() | ||
|
||
main() |
This file was deleted.
Oops, something went wrong.