Note that there are some explanatory texts on larger screens.

plurals
  1. POPygame.transform.rotate scales istead rotation
    primarykey
    data
    text
    <p>Recently I decided to start my third pygame game.In that game the player should fire at airplanes from the cannon in the bottom of the screen,by pointing to the airplane with the mouse.I putted the code in more modules(more.py files) for easier understanding.I started by trying to get cannon barel rotate towards mouse current position.So here we go.</p> <p>main.py</p> <pre><code>import pygame,sys import screen import constants from pygame.locals import * from loop import * screen.screen = pygame.display.set_mode((800,600)) main_loop() </code></pre> <p>constatns.py</p> <pre><code>import pygame pygame.init() scr = pygame.display.list_modes() resolution = (scr[0][0],scr[0][1]) angle = 0 barell = pygame.image.load("barell.png") tux = pygame.image.load("tux.png") tux2 = pygame.transform.scale(tux,(100,100)) </code></pre> <p>loop.py</p> <pre><code>import pygame,event import screen import constants import math import random import groups from faster_barell import * faster_barell = faster_barell() faster_barell.add_to_group() def main_loop(): while True: mx,my = pygame.mouse.get_pos() event.Event() screen.screen.fill([0,0,0]) groups.barell_group.draw(screen.screen) for t in groups.barell_group: dx = mx - t.rect.x dy = my - t.rect.y angle = math.atan2(dx,dy) angle2 = math.degrees(angle) constants.angle = angle2 t.image = pygame.transform.rotate(constants.barell,angle2) pygame.display.flip() </code></pre> <p>screen.py </p> <pre><code>import pygame import constants pygame.init() screen = None </code></pre> <p>event.py</p> <pre><code>import pygame,sys from pygame.locals import * class Event(object): def __init__(self): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() </code></pre> <p>faster_barell.py</p> <pre><code>import pygame import constants import groups class faster_barell(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = constants.barell self.rect = self.image.get_rect() self.rect.x = 750 self.rect.y = 550 def add_to_group(self): groups.barell_group.add(self) </code></pre> <p>groups.py</p> <pre><code>import pygame barell_group = pygame.sprite.Group() </code></pre> <p>Now instead of rotating pygame(I can't really explain how)scales the barell image.The barell image is just a blank(white) 10x30 image).Now here comes even more strange part.When in t.image = pygame.transform.rotate(constants.barell,angle2) I change constants.barell to constants.tux2(which is just a tux image(just for testing it won't be in the game) everything works just fine! Here is the tux image I worked with <a href="http://upload.wikimedia.org/wikipedia/commons/3/3e/Tux-G2.png" rel="nofollow">http://upload.wikimedia.org/wikipedia/commons/3/3e/Tux-G2.png</a> .I tried to solve the problem by changing dx and dy in math.atan2 to something else(dy,dx,-dy,dx,-dx,-dy and so on)please help I'm trying to solve this for about 6 hours(I never ask on stackoverflow unless I really can't do anything to get the code working)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload