Zitat:
Zitat von EminentJonFrost
it would be eaiser to just do:
you dont need to create 2 tables.Code:table = {}
table[1] = { x = 5, y = 6 }
screen:blit(table[1].x, talbe[1].y, image)
Printable View
Zitat:
Zitat von EminentJonFrost
it would be eaiser to just do:
you dont need to create 2 tables.Code:table = {}
table[1] = { x = 5, y = 6 }
screen:blit(table[1].x, talbe[1].y, image)
Yea, I downloaded The Gimp, yet when I try to save it with that transparent background it says because of .png capabilites, the layer must be merged, and then it doesn't save it with the invisible background? Any ideas? ???????
If you're having problems with transparent backgrounds, PM me the images, i'll do it.Zitat:
Zitat von emericaska8r
I'll explain them as best I can.Zitat:
Zitat von PSPduh
screen:drawLine
The syntax for screen:drawLine is as follows:
The x0 represents the starting "x" (horizontal) coordinates for a line.Code:screen:drawLine(x0, y0, x1, y1, color)
The y0 represents the starting "y" (vertical) coordinates for a line.
The x1 represents the ending "x" (horizontal) coordinates for a line.
The y1 represents the ending "y" (vertical) coordinates for a line.
The color represents the color of the line.
EXAMPLE:
If I wanted to display a red line starting at the top left corner of the screen, and ending at the bottom right corner of the screen, I would use the following linesof code:
Code:red = Color.new(255,0,0)
x0 = 0
y0 = 0
x1 = 480
y1 = 272
while true do
screen:drawLine(x0, y0, x1, y1, red)
screen.waitVblankStart()
screen.flip()
end
screen:fillRect
The syntax for screen:fillRect is as follows:
The x represents the "x" (horizontal) coordinates for the top left-hand corner of the rectangle that you want to fill with a color.Code:screen:fillRect(x, y, width, height, color)
The y represents the "y" (vertical) coordinates for the top left-hand corner of the rectangle that you want to fill with a color.
The width represents the width (in pixels) of the rectangle that you want to fill with a color.
The height represents the height (in pixels) of the rectangle that you want to fill with a color.
The color represents the color that the rectangle will be filled with.
EXAMPLE:
If I wanted to fill a rectangle with the color red that starts at the top left-hand corner of the screen, and extends 200 pixels in both directions (vertical and horizontal), I would use the following lines of code:
Code:red = Color.new(255,0,0)
x = 0
y = 0
width = 200
height = 200
while true do
screen:fillRect(x, y, width, height, red)
screen.waitVblankStart()
screen.flip()
end
Hope that cleared things up a bit. :icon_smil
Does anybody know if its faster to blit a whole image at once (so one big image) or two small slices? I need every bit of speed to be able to blit all the units.
If a unit moves, I need to delete the unit first and then blit it at the new position. I can delete the whole unit and blit it at the new place. OR I can delete only the part where it isnt anymore. But if it moves diagonaly it has to delete two slices (eg upper- and leftside).
I know its better to blit one big image then alot of smaller ones that form an image the same size. But im not sure if its the same if the smaller images have a smaller surface than the big one.
I hope its clear I tried my best.
BTW Why am I a PREMIUM Member suddenly? Thx to who ever made me one though!
Thank you so much! :Punk: I'm copying that into notepad so I wont forget it.Zitat:
Zitat von Jeffery
EDIT: Is there a way to make a curved line? And no I can't use a preset one in an image, for the app I'm making.
I've kinda wondered how to do that myself, and I'll give it a try and see if I can come up with something. The only possible way that I can think of right now would be to draw every pixel in the curved line that you would want to create. Of course, that would take up a ton of lines of code.
It doesn't have to be a ton of code, depends on the curve. I just think it would go really slow, because it has to blit the curve pixel by pixel.
I found this in the lua snippet thread in the dev's dungeon:
Even though it would draw a circle, at least it is curved. But maybe I could use a for loop to draw the curved line, so it wouldn't take up lines and lines of code. That's what the for loop is there for, to do a lot in a little lines of code.Zitat:
Zitat von MagicianFB
EDIT: About screen:drawLine, do I need to use x0 y0 x1 y1? Because once you set them to what their equal to, then you can't change it. So can I do this:
Can I use different variables besides x0 y0 x1 y1? <<<< Thats what I really mean.Code:screen:drawLine(10,10,90,100,red)
Yep, you can use different variables or no variables at all (just the actual numbers).
yes you could do sometin like this:
me = 5
you = 6
them = 7
nine = 9
screen:drawline(me,you,th em,nine,red)
they just use x0,y0,x1,y1 as examples you could call variables whatever you want it don't matter
Thanks everybody!
drawing a curved line?
how about those old "y = x^2" (i think its like that...) formulas?
anyone whos used a graphing calculator should know what i mean. you can make the "y" be the position of the pixels, right?
and then make a "for" loop so that the pixels make a (curved) line.
I'll try that. But I'm having trouble with this code:
Yes I'm trying to make a pong game, but the rectangles wont show up. :(Code:black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
grey = Color.new(127,127,127)
red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
yellow = Color.new(255,255,0)
purple = Color.new(120,0,120)
pink = Color.new(255,0,255)
orange = Color.new(255,110,0)
width = 50
height = 100
x = 10
y = 136
x1 = 470
y1 = 136
screencolor = white
paddlecolor = black
while true do
screen:clear(white)
pad = Controls.read()
if pad:up() then
y = y + 2
screen.waitVblankStart(4)
end
if pad:down() then
y = y - 2
screen.waitVblankStart(4)
end
if pad:cross() then
y1 = y1 - 2
screen.waitVblankStart(4)
end
if pad:triangle() then
y1 = y1 + 2
screen.waitVblankStart(4)
end
if y1 <= -1 then
y1 = 0
end
if y <= -1 then
y = 0
end
if y <= 273 then
y = 272
end
if y1 <= 273 then
y1 = 272
end
screen:fillRect(x,y,width,height,black)
screen:fillRect(x1,y1,width,height,black)
screen.waitVblankStart()
screen.flip()
end
try switching back the colors. (blocks are white, background is black.)
and leave the "screen:clear()" alone, so it doesnt mention a color.
Meh, I took white out of screen:clear(), and changed the color of the paddles to white, and it didn't show up still. I guess I'll use pre-set images, or Image.createEmpty.Zitat:
Zitat von EminentJonFrost
wait, isnt it supposed to be "drawRect" instead of "fillRect"?
Whne I tried that it gave me that drawRect was a nil value.Zitat:
Zitat von EminentJonFrost
three things:Zitat:
Zitat von PSPduh
1. why do you have screen.waitVblankStart(4) after everytime you move??
2. the screen:fillRect is muuch too complicated for what you need. a simple Image.createEmpty command will work just as fine.
3. thats one big list of colors you got. ;)
the screen.waitVblankStarts are so the effects of pressing a button dont accidently repeat more than what you want.Zitat:
Zitat von Grimfate126
i agree with the amount of colors. thats alot. why do you have so many? if its so you dont have to remember them, then put this in your Favorites.
http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html
I dont know why I have so many colors. I just like to have a lot to choose from.
I have a question. I'm using a sprite sheet for a game I'm making. I wanted to ask if anybody can tell me how you set a certain point on the sprite sheet into a variable? For example, as seen on EvilMana:
Well, I wanted to know if you can put the sourcex, sourcey, width, and height into a variable when you load an image instead of using the blit command. I think it will be much easier that way to do animation and such without loading a lot of image files.Code:screen:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])
Any help will be appreciated. Thanks.
ShockD
Shock D, if i understand you correctly, then this might answer your question.
You could put:
image = Image.load("image.png")
height = image:height()
width = image:width()
as for sourcex and sourcey, i'm not really even sure what they are/do.
wats wrong with this code?
Code:while true do
screen:clear()
screen:blit(0, 0, menu)
screen.flip()
screen.waitVblankStart(120)
end
pad = Controls.read()
if pad:CROSS() then
screen:clear()
end
i=1
while i<=17 do
screen:clear()
counter:start()
screen:blit(0, 0, background)
screen:print(5, 100, questions[i], black)
screen:print(5, 200, answerOne[i], white)
screen:print(5, 215, answerTwo[i], white)
screen:print(5, 230, answerThree[i], white)
screen:print(5, 245, answerFour[i], white)
inputreceived=0
screen.flip()
screen.waitVblankStart()
while inputreceived==0 do
pad = Controls.read()
if pad:up() then
screen.flip()
if correctanswer[i]==1 then
screen:print(5, 110, "You're Correct!", green)
else
screen:print(5, 110, "Sorry, incorrect.", red)
i=0
end
inputreceived=1
end
if pad:right() then
screen.flip()
if correctanswer[i]==2 then
screen:print(5, 110, "You're Correct!", green)
else
screen:print(5, 110, "Sorry, incorrect.", red)
i=0
end
inputreceived=1
end
if pad:left() then
screen.flip()
if correctanswer[i]==3 then
screen:print(5, 110, "You're Correct!", green)
else
screen:print(5, 110, "Sorry, incorrect.", red)
i=0
end
inputreceived=1
end
if pad:down() then
screen.flip()
if correctanswer[i]==4 then
screen:print(5, 110, "You're Correct!", green)
else
screen:print(5, 110, "Sorry, incorrect.", red)
i=0
end
inputreceived=1
end
end
i = i+1
screen.flip()
screen.waitVblankStart(120)
end
while true do
screen:clear()
counter:stop()
currentTime = counter:time()
screen:print(10,10,"Your time is " .. currentTime,red)
screen.flip()
screen.waitVblankStart(240)
end
im working right now on a load/save feature for my game, loading is easy but when it come to saving:
file = io.open("loadsave/posx.txt","w")
file:write("posx = ".. posx )
file:write()
file:close()
this will save "posx = 0" (example) on a file, yeah, but how could i save more then 1 value, mutli-lines.
bronxbomber92, i believe your code should read :
if pad:cross() the cross shouldn't be in caps.
bronx, the cross shouldn't be caps!
EDIT: I was beat..:p
Yes, i actually beat someone :)
Thanks for the reply emericaska8r.Zitat:
Zitat von emericaska8r
The sourcex and sourcey tells the program where to get the width and height from the image. For example, if you have 4 sprites on the sheet, for sourcex you would have to specify how many pixels to the right the 4th sprite is and same with sourcey. Eh... I hope you understood that. If not then oh well.
Well anyway, that is a good idea. I'm going to play with that for awhile.
Much thanks,
ShockD
Edit: Damn... this stuff is frustrating. When I load my game into the PSP, the background image becomes all distorted (the image is a jpg). It works fine with the windows LUA player. When I convert it into a .png it says error loading image. I set the correct path and extention all right.
Also, it's a bit laggy but I think I know why. If anyone has some pointers on getting rid of lag, that would be great.
Thanks again,
ShockD
i tried that in windows lua player both ways, but the main menu screen would appear but when i press "c" (which is cross on windows) nothing happens, so it doesnt go on to the rest of the code. any help with that? thanksZitat:
Zitat von emericaska8r
@bronxbomber92
In your screen.waitVblankStart, why is there a 12, two spaces, then a zero? I'm just curious as to what that zero does. And also, shouldn't all of that code (the one outside the main loop with the Controls.read()) be in a function?
ShockD
the spaces are because of the formatting of the text of this forum. It should read screen.waitVblankStart(12 0). The 120 means it waits 120 cycles of the screen refreshing. So that means it waits 2 seconds, since the refreshing rate is 60 Hz.
theere isnt really two spaces, the forum did that...and i dont think the Controls.read() should be in a function. if u look lower in the code i have a controls.read() and that works their. so no, i don't think soZitat:
Zitat von ShockD
like this, agashka:
Code:file = io.open("loadsave/posx.txt","w")
file:write("posx = ".. posx\n"posx2 = " ..posx2)
file:close()
Yeah that's what I was thinking too. Oh yeah, Altair, I saw your post in the ps2dev site and I was wondering if you could tell me how you used a 1000x1000 image without any distortion or anything?Zitat:
Zitat von Altair
Thanks.
Zitat:
Zitat von ShockD
its not possible to load images greater than 480x272 in luaplayer unless there is a version i dont know about. youll just have to make seperate images i guess.
hi, i have an analog problem. here is my code:
when i move the analog nub right then player goes right, BUT when i move it left, the player STILL goes right. help. :(Code:function movePlayer()
pad = Controls.read()
dx = pad:analogX()
if math.abs(dx) < -100 then
Player[1].x = Player[1].x - 5
playerpic = 1
goingf = true
elseif math.abs(dx) > 120 then
Player[1].x=Player[1].x + 5
playerpic = 2
goingb = true
end
end
It's not possible to load an image greater than 512x512. Yeah that's exactly what I did so thanks anyway.Zitat:
Zitat von Grimfate126
ShockD
the absolute value of "dx" should not be able to be less than negative100.Code:function movePlayer()
pad = Controls.read()
dx = pad:analogX()
if math.abs(dx) < -100 then
Player[1].x = Player[1].x - 5
playerpic = 1
goingf = true
elseif math.abs(dx) > 120 then
Player[1].x=Player[1].x + 5
playerpic = 2
goingb = true
end
end
Zitat:
Zitat von EminentJonFrost
so how would i fix it. sry, im a total n00b at analog controls. it would have been much easier if it was like:
but life aint fair. thx for the help!Code:if analog:right() then
... blah