OK! ( I need some work on it myself, so ill try your's for practice)
Printable View
OK! ( I need some work on it myself, so ill try your's for practice)
yes bring it on.
also, can someone tell me exactly how to get the font size of a font?
in my menu i want it to make the select text font increase in size, and i need to know how to compare it's current size to something.
Emericaska8r, I don't know how to compare the numbers but I do know how to change them. Here's an example (working script):
Spoiler for example:
This is the important line:
%chrono trigger%, I've never used this method before, but you may want to try integrating it into your code (assuming its not a joke, anyway):Code:fontname:setPixelSizes(fontwidth, fontheight)
http://youresam.com/tutorials/collisionbox.htm
anyone can reply or help me???
here you go have at it:
Code:System.usbDiskModeActivate()
red = Color.new(225,0,0)
player = Image.load("player.png")
background = Image.load("background.png")
pic1 = Image.load("pic1.png")
pic2 = Image.load("pic2.png")
Pic = { }
Pic[1] = { x= 80, y = 95, height = pic1:height(), width = pic1:width() }
Player = { }
Player[1] = { x = 50, y = 107 }
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
playerHeight = 90
playerWidth = 90
function collisionCheck(Pic)
if (Player[1].x + playerWidth > Pic[1].x) and (Player[1].x < Pic[1].x + Pic[1].width) and (Player[1].y + playerHeight > Pic[1].y) and (Player[1].y < Pic[1].y + Pic[1].height) then
Player[1].x = oldx
Player[1].y = oldy
end
end
function movePlayer()
pad = Controls.read()
if pad:left() then
Player[1].x = Player[1].x - 1
end
if pad:right() then
Player[1].x = Player[1].x + 1
end
if pad:up() then
Player[1].y = Player[1].y - 1
end
if pad:down() then
Player[1].y = Player[1].y + 1
end
end
while true do
pad = Controls.read()
oldx = Player[1].x
oldy = Player[1].y
screen:clear()
collisionCheck(Pic[1])
screen:blit(0,0,background)
screen:blit(Pic[1].x,Pic1.y,pic1)
screen:blit(140,107,pic2)
screen:blit(Player[1].x,Player[1].y,player)
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end
if pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
end
if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 2
end
if pad:down() and Player[1].y < screenheight then
Player[1].y = Player[1].y + 2
end
screen.waitVblankStart()
screen.flip()
end
I didn't touch the collision code but I found a little mistype somewhere else on blitting your pic1. Also, here's the collision function I use all the time:Code:System.usbDiskModeActivate()
red = Color.new(225,0,0)
player = Image.load("player.png")
background = Image.load("background.png")
pic1 = Image.load("pic1.png")
pic2 = Image.load("pic2.png")
Pic = { }
Pic[1] = { x= 80, y = 95, height = pic1:height(), width = pic1:width() }
Player = { }
Player[1] = { x = 50, y = 107 }
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
playerHeight = 90
playerWidth = 90
function collisionCheck(Pic)
if (Player[1].x + playerWidth > Pic[1].x) and (Player[1].x < Pic[1].x + Pic[1].width) and (Player[1].y + playerHeight > Pic[1].y) and (Player[1].y < Pic[1].y + Pic[1].height) then
Player[1].x = oldx
Player[1].y = oldy
end
end
function movePlayer()
pad = Controls.read()
if pad:left() then
Player[1].x = Player[1].x - 1
end
if pad:right() then
Player[1].x = Player[1].x + 1
end
if pad:up() then
Player[1].y = Player[1].y - 1
end
if pad:down() then
Player[1].y = Player[1].y + 1
end
end
while true do
pad = Controls.read()
oldx = Player[1].x
oldy = Player[1].y
screen:clear()
collisionCheck(Pic[1])
screen:blit(0,0,background)
screen:blit(Pic[1].x,Pic[1].y,pic1)
screen:blit(140,107,pic2)
screen:blit(Player[1].x,Player[1].y,player)
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end
if pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
end
if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 2
end
if pad:down() and Player[1].y < screenheight then
Player[1].y = Player[1].y + 2
end
screen.waitVblankStart()
screen.flip()
end
Here's how you use it:Code:function collision(ob1,ob2)
if (ob1.x + ob1.w > ob2.x) and (ob1.x < ob2.x + ob2.w) and (ob1.y + ob1.h > ob2.y) and (ob1.y < ob2.y + ob2.h) and (ob1.z + ob1.dp > ob2.z) and (ob1.z < ob2.z + ob2.dp) then
return true
else
return false
end
end
1. Make sure the ob1 and ob2 you give it have w and h values representing width and height (or you can edit the function)
2. if collision(someobject,some otherobject) then *whatever should happen when they collide* end
surely that wouldn't work if you had blitted the same image twice...
ok that takes care of part of it. but when i use the getPixelSizes( or whatever command, what does that output? because i want to do like:Zitat:
Zitat von Aphonia
but what exactly would the variable size be shown as after size = getPixelSize(thisFont)??Code:size = getPixelSize(thisFont)
if size[x] > 30 then
size = size - 1
end
--EDIT-- i found a way around it so i don't really care anymore.
i get how to use the function ,but what is the .z and .dp? (i bolded and underlined them in the code box) are they something im mising or what are they?Zitat:
Zitat von TacticalPinguin
speaking of collision, how would you find out what side of a "block" the "other block" was hitting it on?
so like if collision occured on the right side that it would perform a different action than the top.
there will almost always be 2 sides colliding in a block based collision.Zitat:
speaking of collision, how would you find out what side of a "block" the "other block" was hitting it on?
so like if collision occured on the right side that it would perform a different action than the top.
wow never mind about that, i have another question though lol.
i want to know if blitting a lot of images slows down cpu, because in my super mario bros. game, it always slows when a lot of bricks and what not are being shown on the screen. At first i thought the main slower was my collision code, but i think it might be blitting images.
anybody know about this?
anybody use the function above and know what those extra variables are?
Thexxbestxx, be more specific. I have no idea what you want, and I think everyone else is in the same boat.
--------------
Emericaska8r, the more things you do, the slower things go. I figure an image is harder to blit than a single collision check, but I don't know.
Make sure you're only blitting what will actually appear onscreen (and maybe a one-tile, offscreen buffer to make things pretty), and you should be fine. If it runs slow, try rewriting your code in the simplest way possible. You can have a bunch of images and collision with no slowdown.
z (location on z axis) and dp (depth) for 3d stuff, I suppose.Zitat:
Zitat von %chrono trigger%
You should cut that out if you're using 2d.
yea he PMed me and that was exactly it, I was using it for 3d and I forgot to cut those out. emericask8r; yes, blitting images slows lp down a LOT, theyre pretty much the main concern in optimization. USE BUFFERS!
ok, yes i only have it blitting the visible images, but how would i use a buffer in my program? i can pm you my newest source code if you'd like.Zitat:
Zitat von TacticalPinguin
what does this error mean?-----> calling 'blit' on bad self (number expected, got nil)
and how would you generally fix it?
you are giving it a string instead of a number
Blackshark- Basically, ANY images that do not move, put them all on oen image. AKA:
background:blit(x,y,somei mage)
i need help with figthing animation, can some one show a basic one
yoursam whats a general way of fixing an error like that?
how about giving it a real number?
How can I get that to work?Code:function createTmpImages(table,x,y)
for i = 1, table.lines do
p = {img, idx}
p.img = Image.createEmpty(x, y)
table.tmpImg[i] = p
end
end
For example Id call
createTmpImages(playlist, 50,50)
then I'd expect
for i = 1, playlist.lines do
Am I going about this the wrong way?
Can I encrypt .txt files on the PSP so only the PSP can read them??
the thing is that everything moves since the game scrolls. (if your post was about me and using buffers)Zitat:
Zitat von TacticalPinguin
srry emericaska8r for replying without an aswer, but i cant continue with my game at all unless i get this one thing fixed.
heres the code (again):
the exact error says: script.lua:47: calling 'blit' on bad self (number expected, got nil)Code:System.usbDiskModeActivate()
red = Color.new(225,0,0)
player = Image.load("player.png")
background = Image.load("background.png")
pic1 = Image.load("pic1.png")
pic2 = Image.load("pic2.png")
Pic = { }
Pic[1] = { x= 80, y = 95, h = pic1:height(), w = pic1:width() }
Player = { }
Player[1] = { x = 50, y = 107, h = player:height(), w = player:width() }
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
playerHeight = 90
playerWidth = 90
function movePlayer()
pad = Controls.read()
if pad:left() then
Player[1].x = Player[1].x - 1
end
if pad:right() then
Player[1].x = Player[1].x + 1
end
if pad:up() then
Player[1].y = Player[1].y - 1
end
if pad:down() then
Player[1].y = Player[1].y + 1
end
end
function collision(Pic,Player)
if (Pic[1].x+Pic[1].w > Player[1].x ) and (Pic[1].x < Player[1].x + Player[1].w) and (Pic[1].y + Pic[1].h > Player[1].y) and (Pic[1].y < Player[1].y + Player[1].h) then
return true
else
return false
end
end
Player[1].x = Player[1].oldx
Player[1].y = Player[1].oldy
while true do
pad = Controls.read()
screen:clear()
screen:blit(0,0,background)
screen:blit(Pic[1].x,Pic[1].y,pic1)
screen:blit(140,107,pic2)
screen:blit(Player[1].x,Player[1].y,player)
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end
if pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
end
if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 2
end
so your sam said i was calling a string and not a number, but i dont see where the error comes from.
can anyone fix it?
Urameshi- Use AnimLib. (Something like that) I personally haven't used it, but I heard it's good and easy to use.
pspfreak9- Yes, you can. But you would have to write your own encrypting algorithm.
What in the world is wrong with my script?
I keep getting the error: ERROR: main.lua(some number) loop in gettable
Spoiler for main.lua:
All variables are loaded in my index.lua!
Spoiler for index.lua:
Gameo- We need that line number.
Blackshark-Anything that doesnt move around in relation to everything else, AKA if it moves with the background then buffer it. Also, if you want you can sencd me your code and I'll look through it and see if there are any big things you can do to blit fewer images.
Can function parameters be used in iterators?
for example
function (table)
For i = 1, table.lines do
never mind...Just realised I was giving it a name that didnt exist...stupid...
1) If i clear the screen and make it white, then blit a transperent image on it, and take a screen shot will the screen shot be transperent.
2) As for enycryption, could I do something like this:
3) How can I select characters from a txt file from a txt file like maybe the third letter in a txt file. So i want something like this:Code:if VAR == 4 then
VAR = "B"
end
The "i don't know what goes here" will be the third letter in the txt file.Code:if (i dont what goes here) == "3" then
whatever
end
No, the screen can never have a transparent value.Zitat:
Zitat von pspfreak9
Yes, but make sure you make the "B" a 4Zitat:
Zitat von pspfreak9
whatever = string.sub(file:read(3),3 ,3)Zitat:
Zitat von pspfreak9
2)I had thought about using BASE64 or ROT13 as a method of obfuscation.
Though I have never attempted it as obfuscation. BASE64 is already being used
Ok thanks but can you explain the line of code i bolded, and underlined plz.Zitat:
Zitat von youresam
file:read(3) will return 3 characters from the text file
and Im telling it to take from character 3 to character 3 of that string.
you could also do:
file:seek("set",3)
whatever = file:read(1)
Ok, I get it thanks youresam.
-= Double Post =-
Are there any tuts on LUA file io anywhere?
-= Double Post =-
any1...
I really could use sme help getting this fixed dont have a clue how to fix it the error is at the bottom
heres the code:
the exact error says: script.lua:47: calling 'blit' on bad self (number expected, got nil)Code:System.usbDiskModeActivate()
red = Color.new(225,0,0)
player = Image.load("player.png")
background = Image.load("background.png")
pic1 = Image.load("pic1.png")
pic2 = Image.load("pic2.png")
Pic = { }
Pic[1] = { x= 80, y = 95, h = pic1:height(), w = pic1:width() }
Player = { }
Player[1] = { x = 50, y = 107, h = player:height(), w = player:width() }
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
playerHeight = 90
playerWidth = 90
function movePlayer()
pad = Controls.read()
if pad:left() then
Player[1].x = Player[1].x - 1
end
if pad:right() then
Player[1].x = Player[1].x + 1
end
if pad:up() then
Player[1].y = Player[1].y - 1
end
if pad:down() then
Player[1].y = Player[1].y + 1
end
end
function collision(Pic,Player)
if (Pic[1].x+Pic[1].w > Player[1].x ) and (Pic[1].x < Player[1].x + Player[1].w) and (Pic[1].y + Pic[1].h > Player[1].y) and (Pic[1].y < Player[1].y + Player[1].h) then
return true
else
return false
end
end
Player[1].x = Player[1].oldx
Player[1].y = Player[1].oldy
while true do
pad = Controls.read()
screen:clear()
screen:blit(0,0,background)
screen:blit(Pic[1].x,Pic[1].y,pic1)
screen:blit(140,107,pic2)
screen:blit(Player[1].x,Player[1].y,player)
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end
if pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
end
if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 2
end
so your sam said i was calling a string and not a number, but i dont see where the error comes from.
can anyone fix it?
Not sure, the code looks fine to me.Zitat:
Zitat von %chrono trigger%
-= Double Post =-
Yeah there are. http://www.lua.org/pil/21.1.htmlZitat:
Zitat von pspfreak9
exactly but thanks for trying
anybody else now?
could it be my images?
(im trying everything)
You never set a value for Player[1].oldx and Player[1].oldy, so the numbers become nil.Code:Player[1].x = Player[1].oldx
Player[1].y = Player[1].oldy