Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 30 Nov 2012
Offline Last Active Today, 03:12 AM

Posts I've Made

In Topic: Scrolling text area

28 April 2015 - 04:58 AM

By guess is that you will need to make a variable for the text, and then have setText and getText functions. I will make it easy for you:

public class MsgList : MonoBehaviour {
	private Vector2 scrollPosition;
        private String text;
	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {


	void OnGUI() {
		scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Width (200), GUILayout.Height (50));
		GUILayout.Label (text);
		GUILayout.EndScrollView ();
        public void setText(string Text){

Assuming this is C# (This looks like Unity, am I right?)


Now all you need to do from the player is, in unity, do something like FindObjectsOfType, and either call setText on it or send a message. Eventually, you will want a more complicated system that keeps strings in a cage while making sure each one is shown for enough time, and you might also want play a sound or visual effect.

In Topic: What do you have on your Desk?

26 March 2015 - 04:23 AM

I have my laptop, a van for my laptop, a pair of headphones, a big pencil sharpener, 2 small pencil sharpeners, a pencil, a bunch of business cards, a letter, some toffees, a empty container that used to hold cheese, some old paper, a sock, a candy wrapping, and a strip of rubber that I have no idea what it's for. 

In Topic: SpriteSheet Class won't correctly display transparent images

05 March 2015 - 10:10 PM

I don't think you can have a image with both alpha and color key. Your code should be:

        rect = pygame.Rect(rectangle)
        image = pygame.Surface(rect.size, pygame.SRCALPHA)
        image.blit(self.sheet, (0, 0), rect)
        return image

what this code does is first give the image a alpha channel by using the flag SRCALPHA. Then you are making sure it is fully transparent, since its black by default, and then write your image over it like you normally would.


The main important part is to decide whether you want to use the extra processing power and memory to use alpha mapped images, or just use color keys, that look worse. You are trying to do both, which doesn't really work.



I found the file you based this on on the pygame wiki. The only thing you changed was the convert_alpha. Now your sprite sheet has a alpha channel, but not your sprites. To get sprites with alpha, use SRCALPHA

In Topic: My First Game Concept

22 February 2015 - 04:52 AM

whats the game going to be about?

In Topic: Pygame Rect move help

20 February 2015 - 04:43 AM

what I meant is doing controll f over all your files to find all references to player.rect (with good encapsulation, you should have as few as possible. So for examle, if your line of code looks like this:

player.rect.topleft=(0,0) #reset position after hit

change it to this:

player.rect.topleft=(0,0) #reset position after hit
assert isinstance(player.rect,pygame.Rect), "line 679 file __main__.py in check collision: player.rect is no longer a rectangle"

what assert dous is throw a error when the condition os no longer true. So here, if player.rect becomes a tuple, like its doing in your error, it will throw a Assertion error.

to clarify: There is no problem in the code you posted, it must be caused by bad encapsulation (you don't need to know what that is)

your functions will become (just a example, do this for your whole project, including when you use it in the constructor):

    def move_left(self):
        assert isinstance(self.rect, pygame.Rect), "line {linenumber} in player.move_left: player.rect no longer is a rectangle"
        self.rect.move_ip(self.speed, 0)

    def move_right(self):
        assert isinstance(self.rect, pygame.Rect), "line {linenumber} in player.move_right: player.rect no longer is a rectangle"
        self.rect.move_ip(-self.speed, 0)

    def move_up(self):
        assert isinstance(self.rect, pygame.Rect), "line {linenumber} in player.move_up: player.rect no longer is a rectangle"
        self.rect.move_ip(0, self.speed)

    def move_down(self):
        assert isinstance(self.rect, pygame.Rect), "line {linenumber} in player.move_down: player.rect no longer is a rectangle"
        self.rect.move_ip(0, -self.speed

so yea, if all alse fails, try printing self.rect in all the functions. If they are the right rectangle, but just not the right format, you can convert them at the start of the function, like this:

def move_down(self):
    if not isinstance(self.rect,pygame.Rect):

(but please don't do this unless you have tried everything, your code will become a chaos.

The whole point of the assertions is that the program will crash at the point where the data type changes.


So, summary, this code is fine, look for a problem somewhere else. And a important lesson: Never do step 2 until you have understood step 1. If you still have any questions, just ask and PM if I take to long.