QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

"Click" on object in luaplayer?

This is a discussion on "Click" on object in luaplayer? within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Hey all, I'm trying to create a operating system/shell for lua, and I need to figure out hot to figure ...

Reply
 
LinkBack Thread Tools
Old 02-15-2008, 09:52 PM   #1
 
spykr's Avatar
 
Join Date: Feb 2008
Posts: 8
Trader Feedback: 0
Default "Click" on object in luaplayer?

Hey all,
I'm trying to create a operating system/shell for lua, and I need to figure out hot to figure out what object that the mouse "clicks" on. Here's my code for the mouse (currently, it's pretty simplistic):
Code:
pad = Controls.read()
    
if pad:start() then
    break
end

AnalogX = pad:analogX()
if math.abs(AnalogX) > 32 then
    CursorX = CursorX + AnalogX / 50
end
	    
AnalogY = pad:analogY()
if math.abs(AnalogY) > 32 then
    CursorY = CursorY + AnalogY / 50
end

screen:blit(CursorX, CursorY, CursorImg)
How could I figure out what object that the user actually "clicked" on? I have an idea, but that would involve creating an array to list every pixel on the screen, and then, each time an object is drawn, change the values according to where the object is drawn on the screen. I would think that this would be very processor-intensive. Is there any way to figure out what object is drawn in front at a certain point?

Ugh... any help would be GREATLY appreciated!
Thanks,
spykr
spykr is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-15-2008, 10:08 PM   #2
 
Join Date: Jan 2008
Posts: 612
Trader Feedback: 0
Default

if (the cursor is on top of the part you want to click on) and pad:cross() then
do whatever needs to be done when clicked on
end
Always make pseudocode of what you are trying to do (aka make the concept) and then make the actual code. Makes things much easier.
TurtlesPwn is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-15-2008, 10:41 PM   #3

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

To determine whether the cursor is over anything, maybe make a class (classes supported in Lua?) with common functions and variables (Draw, X, Y, Width, Height, ID (or name if you like), backColor, foreColor, onPress() as function, onIdle(hovering as boolean) as function and colliding(x,y,width,heigh t) as function). This should get inherited by more specific shell objects.

For buttons, it'd inherit that class and have it contain things that buttons only make use of. For checkboxes, it'd inherit that class and add things like checked (as boolean, for when onPress() is ran, swaps this flag), groupBoxID (if the check box is in a group box whether to effect other check boxes, or are those radio buttons?), etc. You can use VB.net tools for a means of obtaining member names and usages (better then forgetting about something then having to redo some part of your code )


Code:
NUM_SHELL_OBJECTS = 4

START_BUTTON_ID = 1
EXIT_BUTTON_ID = 2
WELCOME_LABEL_ID = 3
ACCEPT_CHECKBOX_ID = 4
-- etc.

pressing = { cross = false }

baseClass = { X, Y, Width, Height, ID, backColor, foreColor, onPress(), onIdle(bool), colliding(x,y,width,height) } -- not sure if this is the correct way to make a lua class, so... 

startButton = { baseClass } -- I dunno what else a button needs :P
exitButton = { baseClass } -- above ^^
welcomeLabel = { baseClass } -- I dunno what labels need specifically ;)
acceptDialog = { baseClass, checked, parentID } -- checked for if it's checked, parentID for the groupbox ID parent if any

shellObject = { startButton, exitButton, welcomeLabel, acceptDialog } -- each of these are classes that have inherit a base class with teh common stuff as well as the more use-specific stuff

-----------------

while true do
  screen:clear()

  -- draw background or w/e, anything non-shellobject related

  for i = 0, NUM_SHELL_OBJECTS
      if pad:cross() and not pressing.cross then
        pressing.cross = true
        
        if shellObject[i].colliding (CursorX, CursorY, 1, 1) then -- 1,1 = width/height of collision area for cursor, preferably the top left part of hte cursor if it's like the windows mouse 
          shellObject[i].onPress() -- mouse is over the current shell object + cross is pressed, so...
        end
      else
        pressing.cross = false

        if shellObject[i].colliding (CursorX, CursorY, 1, 1) then
          shellObject[i].onIdle(true) -- true = mouse is hovering over the object, not pressed yet, useful for a status bar for seeing what an object does before pressing
        else
          shellObject[i].onIdle(false) -- mouse isn't over the object and not pressing it (duh) 
        end
      end

      shellObject[i].Draw()
  end

  screen.waitVblankStart()
  screen.flip()
end
I'd write your base class and a few other things if I knew how to in Lua (define an inherited class mainly). I guess I could just add the baseclass as a class within a class, only difference would be .baseClass before accessing any members in it.

Not sure if this is the best way, but it offers a lot of control and pretty easily upgradeable.

If yaustar or some other higher-ups (?) bother to look in here, they may be able to offer a better design for ya.
__________________

Last edited by SG57; 02-16-2008 at 01:30 PM..
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-16-2008, 02:01 AM   #4
Developer and Tutor.
 
FaT3oYCG's Avatar
 
My Mood: Happy
Join Date: Jul 2007
Real First Name: Craig
Location: Widnes, England
Just Played: Life.
Posts: 1,646
Trader Feedback: 0
Default

here you can have the code for my cursor code that i made for pspengiun

Code:
function CursorHover(Object)
if (cursor.x + 1 > Object.x) and (cursor.x < Object.x +Object.width) and (cursor.y + 1 > Object.y) and (cursor.y < Object.y + Object.height) then
return true
end
end
and to stop it going off the screen

Code:
function CursorPositionCheck()

if
cursor.x + CursorWidth < 9  
then
cursor.x = 0
end

if
cursor.x - CursorWidth > 479
then
cursor.x = 479
end

if
cursor.y + CursorHeight < 13
then
cursor.y = 0
end

if
cursor.y - CursorHeight > 271
then
cursor.y = 271
end

end
then use

Code:
if CursorHover(object / image) and pad:cross() then
-- show a menu or something of that sort
end
so if it was hovering over an image it would return to

if true and you press cross then
-- show a menu or something of that sort
end
__________________
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: is down for a while ... I'll bring a new one back soon.

Currently working on:
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? - A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
FaT3oYCG is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-16-2008, 09:43 PM   #5
 
spykr's Avatar
 
Join Date: Feb 2008
Posts: 8
Trader Feedback: 0
Default

Wow!
Thanks a lot, y'all.
Now I just have to determine which clickable object is on top, but I'm off to a great start, now. I'll be sure to put whoever really helps me in the "Special Thanks" section of my credits (that is, if I ever get at least a BETA version of this...)

Thanks for the help,
spykr
spykr is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-16-2008, 10:16 PM   #6

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

Heh, I've always thought of a small shell as a personal goal of mine, so I've given the design some thought a few times. This time I was able to write up a small sample of it atleast

Hope all goes well, you'd be surprised how much you learn actually experimenting and whatnot compared to just lessons or homework.
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-17-2008, 02:41 PM   #7
 
spykr's Avatar
 
Join Date: Feb 2008
Posts: 8
Trader Feedback: 0
Default

Quote:
Originally Posted by SG57
Hope all goes well, you'd be surprised how much you learn actually experimenting and whatnot compared to just lessons or homework.
Well, this is just something I'm doing in my spare time. Lol, i'm not quite in college yet . Although I scored a 23 on a practice ACT. I've taught myself to program all from online tutrials and forums. I started out with python, so lua isn't all that much different.
Anyway, I digress...
spykr is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-17-2008, 03:31 PM   #8

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

I also got started with lessons online. But have learned a majority of things from having to use them in a project, gaining experience.

Either way hope all goes well with you
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
click , luaplayer , object

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 05:34 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us