It is currently Thu Sep 09, 2010 4:49 am




Post new topic Reply to topic  [ 13 posts ]  Go to page Previous  1, 2
Trying to attach 2 rects to a whole rect 
Author Message

Joined: Fri Feb 05, 2010 4:30 am
Posts: 60
Post Re: Trying to attach 2 rects to a whole rect
Mmm, I don't really notice a difference with move_ip, but I guess it doesn't really matter. As for the scrolling and the player position, I'm not really sure how to do it..I've tried a lot of stuff, like getting the remainder when divided by the screen dimension..but its confusing me greatly.

EDIT: Maybe the scroll code could be fixed with something I did to keep the player on screen:
Code:
        if player.rect.left < -self.scroll_x + SCREEN_WIDTH / 4:
            self.scroll_x = -player.rect.left + SCREEN_WIDTH / 4
        if player.rect.right > -self.scroll_x + SCREEN_WIDTH * .75:
            self.scroll_x = -player.rect.right + SCREEN_WIDTH * .75
        if player.rect.top < -self.scroll_y + SCREEN_HEIGHT / 4:
            self.scroll_y = -player.rect.top + SCREEN_HEIGHT / 4
        if player.rect.bottom > -self.scroll_y + SCREEN_HEIGHT * .75:
            self.scroll_y = -player.rect.bottom + SCREEN_HEIGHT * .75

That code works perfectly, though I'm not sure how to implement it with pygame.mouse.get_pos().


Wed Mar 03, 2010 11:06 pm
Profile
Site Admin

Joined: Wed Oct 22, 2008 11:28 pm
Posts: 129
Post Re: Trying to attach 2 rects to a whole rect
Code:
x,y = pygame.mouse.get_pos()
x2,y2 = player.rect.center

x3 = x2 + (x-SCREEN_WIDTH/2)
y3 = y2 + (y-Screen_HEIGHT/2)


x3 and y3 will be the mouse position in relation to the player centered camera :)


Thu Mar 04, 2010 3:03 pm
Profile

Joined: Fri Feb 05, 2010 4:30 am
Posts: 60
Post Re: Trying to attach 2 rects to a whole rect
:O Thanks, it worked! This is my code for it:
Code:
        self.scroll_x = -(player.headRect.centerx + (pygame.mouse.get_pos()[0] - SCREEN_WIDTH / 2)) + SCREEN_WIDTH / 2
        self.scroll_y = -(player.headRect.centery + (pygame.mouse.get_pos()[1] - SCREEN_HEIGHT / 2)) + SCREEN_HEIGHT / 2


Now I can start figuring out other problems :P


Fri Mar 05, 2010 6:00 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page Previous  1, 2


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
© 2008-2009 PyedPypers.org
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forum/DivisionCore.