question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example for interactively controlling an animation/games

See original GitHub issue

I have managed to create smooth physics animations within jupyter using ipcanvas. I have also managed to successfully use ipyevents on ipycanvas to trigger events.

However I am struggling to combine events within animation loop. This would be required to run a game on ipycanvas, for example when pressing keys to change the direction of a spaceship flying across the canvas.

When the animation loop is running, it appears to block the events from being processed.

I can run my animation like this:

def run_game():
    for i in range(5000):
        with hold_canvas(space):
            space.clear()
            space.fill_style = 'black'
            space.fill_rect(0,0, width, height)
            ship.update()
            space.fill_style = 'white'
            space.fill_arc(ship.position.x, ship.position.y, ship.size, 0, math.pi * 2)

And I can specify an event changing the ship’s velocity like this:

from ipyevents import Event 
d = Event(source=space, watched_events=['keydown'])
d.on_dom_event(ship.thrusting)

Each one works on their own, but the event does not fire while the run_game() is running because it is blocking.

Is there a way to run this asynchronously?

Could you perhaps provide an example, which shows how one would write a game for ipycanvas?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tomanizercommented, Apr 12, 2020

Martin, you are amazing. Thanks a lot for this example! And for you work on ipycanvas. I want to use it for teaching kids. and the interactivity and graphics within a notebook make a real difference there.

0reactions
martinRenoucommented, Apr 14, 2020

I guess this is one of the first things a new user encouters with ipycanvas

I agree. It should be added to the documentation then 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interactive Animation. and how do we make one?
An interactive animation is an animation that can be controlled by someone beyond just starting and stopping the animation.
Read more >
Interactive Control For Physically-Based Animation
We propose the use of interactive, user-in-the-loop techniques for controlling physically-based animated characters. With a suitably.
Read more >
Make your Characters Interactive! - Animation Rigging in Unity
Let's create procedural animations using Animation Rigging!▻ This video is sponsored by Unity.○ Learn more about Constraints: ...
Read more >
The A-Z Steps to Create A Mini Interactive Game with Saola ...
1. Design the game playing scene · 2. Add animation to the cages · 3. Add animation to the bottom cloud · 4....
Read more >
The Necessity Of Interactive Animation For Games
Animation is Communication. After control, the most important thing to the player is information. Anything we can tell about the world or the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found