Advertising (This ad goes away for registered users. You can Login or Register)

[Tutorial] Python PSP Programming

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
blacky94
Posts: 7
Joined: Fri Jun 29, 2012 11:22 pm

Re: [Tutorial] Python PSP Programming

Post by blacky94 »

sorry, was confused, image 2 ist the background and image 1 is half transparent
Advertising
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [Tutorial] Python PSP Programming

Post by qwikrazor87 »

Code: Select all

while True:
    screen.clear(CLEAR_COLOR)
    screen.blit(image2)
    screen.blit(image1, blend = True)
    screen.swap()
Try that.
Advertising
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
blacky94
Posts: 7
Joined: Fri Jun 29, 2012 11:22 pm

Re: [Tutorial] Python PSP Programming

Post by blacky94 »

Hi,

i have again a problem with python. I want to blit a image on a surface, the image have the size 480x272. It works fine when i blit it with the parameter sx = 0, sy = 0, w = 480, h = 272, dx = 0, dy = 0, dw = 480, dh = 272.
But when I press the left button the image should change the position
press left x = x - 16
parameter -> sx = 0 - x, sy = 0, w = 480, h = 272, dx = 0, dy = 0, dw = 480, dh = 272
But the sx position is now negative and i become the error:
ValueError: subsurface rectangle outside surface area
and when i press right the x variable should be x = x + 16, but it dont work, too. and i become the same error because the x+width position is now over 480. here is a sample:

Code: Select all

import pspnet
import psp2d
import pspos


screen = psp2d.Screen()
CLEAR_COLOR = psp2d.Color(255,255,255)
image = psp2d.Image("test.png") #size -> 480x272
x = 0
while True:
    pad = psp2d.Controller()
    if pad.left:
        x += 16
    if pad.right:
        x -= 16
    screen.clear(CLEAR_COLOR)
    screen.blit(image,sx = x,sy = 0)
    screen.swap()
hope you can help me again :)
Acid_Snake
Retired Mod
Posts: 3100
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: [Tutorial] Python PSP Programming

Post by Acid_Snake »

try creating an empty image instance with more resolution and then blit the image into that empty image, then blit the empty image into the screen, something like this:

Code: Select all

empty_img = psp2d.Image(1000, 1000)
img = psp2d.Image(path_to_your_image)
scr = psp2d.Screen()
empty_img.blit(img)
scr.blit(empty_img)
please don't copy-paste this code, it will most likely not work, it's just to show you the idea, which you have to properly implement into your needs
Tonakai
Posts: 594
Joined: Sun Aug 05, 2012 3:00 am
Location: United Kingdom.

Re: [Tutorial] Python PSP Programming

Post by Tonakai »

Very interesting tutorial here. I'll definitelly be looking into this once I've got a better grasp on Python (looks like a chose a good language to learn).

One thing I'm wondering is whether following your "Python GUI" tutorials prior to this would give me an advantage?
ultear
Posts: 1
Joined: Fri Dec 28, 2012 8:09 pm

Re: [Tutorial] Python PSP Programming

Post by ultear »

Thanks for the tutorial is just what I was looking for ;)
I'm Overfloooow
Posts: 78
Joined: Fri Oct 19, 2012 7:24 am
Location: :: anywhere ::

Re: [Tutorial] Python PSP Programming

Post by I'm Overfloooow »

You can run those files with pyGames :) Its make us more fun. .
@Exploit hunting are my favourite activities since I got my first Phat PSP

http://lolpsvhex.blogspot.com/
hgoel0974
Retired Mod
Posts: 2155
Joined: Mon Jul 23, 2012 11:42 pm
Location: New York

Re: [Tutorial] Python PSP Programming

Post by hgoel0974 »

dude Thanks for allowing me to add these to the wiki :D
I read them only so that I knew what I was putting on the Wiki and now I know that python is closer to C# than C++ so, I can make homebrew in python then! :D
Just a question though, suppose I want to launch other homebrew, how would I do it?
"If the truth is a cruel mistress, then a lie must be a nice girl"
Acid_Snake
Retired Mod
Posts: 3100
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: [Tutorial] Python PSP Programming

Post by Acid_Snake »

yeah I answered that question in a PM
SifJar
Posts: 251
Joined: Tue Jan 11, 2011 10:19 pm

Re: [Tutorial] Python PSP Programming

Post by SifJar »

Can anyone give me some pointers on running the code on PC? I have installed PyGame, and tried importing pygame as psp2d, but that didn't work (pygame has no Screen() function), so I'm not sure what I need to do. Or am I meant to import both pygame and psp2d (in which case, where do I get the psp2d module for PC)? Any advice would be great, would make it much easier to mess around with this rather than having to transfer py scripts back and forth between my PC and PSP for editing.

EDIT: Well I figured that out, needed to download this: https://code.google.com/p/pspstacklessp ... p&can=2&q=

But I do have another question; what would be the correct way to exit a program? For example I have this script:

Code: Select all

#! /usr/bin/env python
import pygame, psp2d
scr = psp2d.Screen()
fnt = psp2d.Font("font.png")
img = psp2d.Image(480, 272)
img.clear(psp2d.Color(0,0,0))
fnt.drawText(img, 0, 0, "Hello World!")
fnt.drawText(img, 0, 20, "Press X to change the screen")
scr.blit(img)
scr.swap()
while True:
    pad = psp2d.Controller()
    if pad.cross:
        img.clear(psp2d.Color(255,0,0))
        fnt.drawText(img, 0, 0, "Now it's RED!")
        fnt.drawText(img, 0, 20, "Triangle to quit, Circle to change again!")
        scr.blit(img)
        scr.swap()
        while True:
            pad = psp2d.Controller()
            if pad.triangle: exit() #HERE
            elif pad.circle:
                img.clear(psp2d.Color(0,255,0))
                fnt.drawText(img, 0, 0, "GREEN!")
                fnt.drawText(img, 0, 20, "Square to exit now")
                scr.blit(img)
                scr.swap()
                while True:
                    pad = psp2d.Controller()
                    if pad.square: exit() #HERE
which works great apart from exiting the program (the lines commented with "#HERE"), which crashes both then PSP and when it is run on the PC. Is there some better way to do this? If so, could someone please tell me it? I've tried looking at samples, but I can't seem to find what I'm looking for...

EDIT: Actually, this does work on PC. But not on the PSP. And obviously the PSP is the more important factor here (although ideally the solution would work on both)
Locked

Return to “Programming and Security”