![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
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 ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
|
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)
Ugh... any help would be GREATLY appreciated! Thanks, spykr |
|
|
|
|
|
|
#2 |
![]() |
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. |
|
|
|
|
|
#3 |
![]() ![]() ...in a dream...
|
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
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.
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) Last edited by SG57; 02-16-2008 at 01:30 PM.. |
|
|
|
|
|
#4 |
![]() Developer and Tutor.
My Mood:
Join Date: Jul 2007
Real First Name: Craig
Location: Widnes, England
Just Played: Life.
Posts: 1,646
Trader Feedback: 0
|
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 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 Code:
if CursorHover(object / image) and pad:cross() then -- show a menu or something of that sort end 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). |
|
|
|
|
|
#5 |
|
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 |
|
|
|
|
|
|
#6 |
![]() ![]() ...in a dream...
|
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.
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) |
|
|
|
|
|
#7 | |
|
Quote:
. 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... |
||
|
|
|
|
|
#8 |
![]() ![]() ...in a dream...
|
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
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) |
|
|
|
![]() |
| Tags |
| click , luaplayer , object |
| Thread Tools | |
|
|