• Benvenuto in Making Videogames!
  • Dai sfogo alla tua fantasia!
  • Crea il tuo Videogioco!
Benvenuto ospite! Login Registrati




Valutazione discussione:
  • 0 voto(i) - 0 media
  • 1
  • 2
  • 3
  • 4
  • 5
telecamera a scorrimento..
#3
si grazie questo è per far scorrere la telecamera (ma come la collego allo sprite del personaggio eh <.<) e il tasto destro premuto sarà if evt.key == pygame.K_LEFT:
comunque ditemi se ci sono errori su questo codice:

#! usr/bin/env python

import pygame

screen = pygame.display.set_mode((800, 600))
background = pygame.image.load('Scrolling_BasicBackground.jpg').convert()

# we render the viewport in a smaller rectangle centered within the screen
# to give us room to print statistics.
#
vpRenderOffset = (80,60)
vpStatsOffset = (80,540)

vpCoordinate = 0
minHorzScrollBounds = 0
maxHorzScrollBounds = 1996 # 2636 - 640
advanceVelocity = 0
scrollVelocity = 10

# generate an event 30 times a second, and perform simulation update. this
# keeps the game running at the same speed in framerate-independent fashion.
#
UPDATE = pygame.USEREVENT
pygame.time.set_timer(UPDATE, int(1000.0/30))

if not pygame.font.get_init():
pygame.font.init()
arialFnt = pygame.font.SysFont('Arial', 16)

running = True
while running:
for evt in pygame.event.get():
if evt.type == pygame.QUIT:
running = False

elif evt.type == pygame.KEYDOWN:
if evt.key == pygame.K_LEFT:
advanceVelocity += -scrollVelocity
elif evt.key == pygame.K_RIGHT:
advanceVelocity += scrollVelocity

elif evt.key == pygame.K_ESCAPE:
pygame.event.post(pygame.event.Event(pygame.QUIT, {}))

elif evt.type == pygame.KEYUP:
if evt.key == pygame.K_LEFT:
advanceVelocity += scrollVelocity
elif evt.key == pygame.K_RIGHT:
advanceVelocity += -scrollVelocity

elif evt.type == UPDATE:
vpCoordinate += advanceVelocity
if vpCoordinate < minHorzScrollBounds:
vpCoordinate = minHorzScrollBounds
if vpCoordinate > maxHorzScrollBounds:
vpCoordinate = maxHorzScrollBounds

# render
screen.fill((0,0,0))
viewport = background.subsurface((vpCoordinate, 0) + (640, 480))
screen.blit(viewport, vpRenderOffset)
screen.blit(arialFnt.render('coordinate: %4d' % vpCoordinate, True, (255,255,255)), vpStatsOffset)
pygame.display.flip()
 
Rispondi
  


Messaggi in questa discussione
telecamera a scorrimento.. - da Alche - 24-10-2010, 06:14 PM
RE: telecamera a scorrimento.. - da Zapetino - 24-10-2010, 07:27 PM
RE: telecamera a scorrimento.. - da Alche - 24-10-2010, 09:16 PM
RE: telecamera a scorrimento.. - da steve - 24-10-2010, 10:52 PM
RE: telecamera a scorrimento.. - da Alche - 24-10-2010, 11:36 PM
RE: telecamera a scorrimento.. - da steve - 25-10-2010, 04:12 PM
RE: telecamera a scorrimento.. - da Alche - 25-10-2010, 05:12 PM
RE: telecamera a scorrimento.. - da steve - 25-10-2010, 08:48 PM
RE: telecamera a scorrimento.. - da Alche - 25-10-2010, 08:54 PM
RE: telecamera a scorrimento.. - da steve - 26-10-2010, 12:48 AM
RE: telecamera a scorrimento.. - da Alche - 26-10-2010, 02:50 PM

Vai al forum:


Browsing: 1 Ospite(i)