Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sprites and Actor error
#1
I am learning python with my son and struggling with something quite fundamental!

We are working through a python games programming for kids book and just want to chuck a few sprites on screen and move them about and check collisions etc.

I was hoping to find a library that allowed me to put a sprite on a background using some sort of xor type operation so I could easily delete it and leave the background in tact.

So I have tried using various methods but haven't found one that does this.
Compounding my frustration is I cannot seem to use Actor. In the book I am using it has all the code at the back and it just has the following:

from random import randint
apple = Actor("apple")

When I run it, it not surprisingly says:
NameError: name 'Actor' is not defined

If I add import actors at the beginning it seems to get further but I get an error:
ModuleNotFoundError: No module named 'actors.internal'

Now it may well be that Actor is not what I need for manipulating sprites but I'd like to know what I am missing. There is little on the Internet on this, it's almost as if it should just work!

Thsnks
Quote
#2
What's the name of the book? Or, if you have a direct link to Amazon, that'd be helpful.

Actor isn't something in the standard library, so without more information, I'm not sure what package it's trying to use. Unless (and this is a strong possibility) it's a custom package designed specifically for the book, in which case Actor would be from an earlier chapter.

Depending on the author, all the code in the book could be (...probably is) online somewhere, possibly on the publisher's site, possibly on github. Either way, the first couple pages of the book would say where the code can be found.

One of the problems with books, in general, is if there's a typo or mistake, they can't fix it. So there will be errata released on the publisher's site saying what the right code is, or possibly reworded explanations of things. Which brings us back to the beginning when I asked which book it is, exactly :p


*edit* OR! If you give us a little more context, like how the Actor class is used (full code helps), we can probably figure out what it's doing and write one close enough to what the code in the book is expecting.
Quote
#3
The book was https://www.amazon.co.uk/Computer-Coding...man+python

Because the book used the Actor class I thought it must be a standard / well known library and I was just missing something fundamental. The lack of information on the Internet suggest that this may not be the case. The book just referenced it with no import statement, I used pip install actor and then the import to get a bit further but the class still seemed to fail when initialising with the error mentioned in the original post.

So I'll move on! I just need to find the best library to manage sprites. I haven't really researched this as I got hung up on the Actor bit so any suggestions would be gratefully received.
Quote
#4
(Nov-07-2018, 08:46 AM)ajlconsulting Wrote: The book just referenced it with no import statement
Are you sure that book did not define Actor class before that section somewhere? Did it reference a Glossary in the end of the book that defines classes? Or do they reference an online source of code somewhere?

It could be as little as
class Actor:
    pass
However if they use methods (class functions) like this
apple = Actor("apple")
apple.update()
then there is more defined in the Actor class.

Quote:So I'll move on! I just need to find the best library to manage sprites.
I would be cautious moving on. You can easily have the same occur later on and not find another class defined without finding where Actor is defined. And you would be more involved in the book by then. Possibly even more confused.

In what way are you using sprites? In games, pygame is the most used library for displaying and moving sprites.
Quote
#5
The book has a glossary at the back (thank you Amazon preview), and the code is as you describe. No imports, Actor without being imported/defined, etc. So I looked at the introduction.

It uses Pygame Zero, which is apparently a wrapper around python/pygame that adds a few things auto-magically for you to make building games faster.

https://pygame-zero.readthedocs.io/en/st...ction.html

You need to run your program through pygame zero, since it adds a few magic things for you (like opening a window, handling OS events, defining what an Actor or a Sprite are, etc). So running like python my_file.py won't work, but pgzrun my_file.py should work.

If you haven't already installed pygame zero, you'll need to do so before that command will work, though. If python is already installed, installing pygame zero should be as easy as pip install pgzero.

Interestingly, it's installed by default on Raspbian, which is an OS for RaspberryPis, which explains (at least to me) why it's called pygameZERO, as the Zero is a relatively new version of the raspberry pi that's super inexpensive (I picked up 3 of them at $5 each).
metulburr likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PyGame] move randomly sprites reutB 4 1,485 Mar-29-2017, 01:12 PM
Last Post: metulburr
  How can I get rid of the line following the sprites? Houston11 1 997 Jan-06-2017, 10:14 PM
Last Post: Mekire

Forum Jump:


Users browsing this thread: 1 Guest(s)