Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Question about dragging a picture:
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Eulogy




PostPosted: Mon Mar 29, 2004 10:59 am   Post subject: Question about dragging a picture:

Hello everyone,
It's my first post, so I'm a little nervous.
I'm trying to create my first game, and I've encountered a problem.
My game idea is simple, a puzzle that the user reassembles.
My problem: I have the puzzle pieces in bitmaps, but I don't know how to implement them into my game.

What I need to happen:
The puzzle pieces need to be able to be clicked, and dragged around the screen freely. Can anyone reply with the source code needed to for 1 bitmap? I can do the rest.

Thank you.
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Mon Mar 29, 2004 11:55 am   Post subject: (No subject)

I'd say put the picture variables in arrays, make it so that you don't have to hold the mouse button to move it, like once you click it, you have to click it again to drop it. Update the position of the picture everytime the mouse button is clicked and the x and y is different, then when the user clicks again, it stays in the last recorded position.
guruguru




PostPosted: Mon Mar 29, 2004 11:58 am   Post subject: (No subject)

Heres an idea...

code:

setscreen ("nobuttonbar; offscreenonly; graphics")

var piece1 : int := Pic.FileNew (puzzlepiece1)     % Load your picutre
var height : int := Pic.Height (piece1)
var width : int := Pic.Width (piece1)
var x, y, button : int                             % The mouse variables

Pic.Draw (piece1, 50, 50, picMerger)               % Display your picture
View.Update                                        % Put pic on screen

loop
    Mouse.Where (x, y, button)                     % Test where the mouse is
    if button = 1 and whatdotcolor not= 0 then     % If mouse is pressed and your not clicking white
        Pic.Draw (piece1, x + width div 2, y + height div 2)    % Draw the picutre again at mouse
        cls
        View.Update                                % Update the screen...
    end if
end loop

% And done...


Hope it helped... but I thinck that would only work for one piece, just put the x and y coordinates of the piece in an array, then update them when you move the pic.
Tony




PostPosted: Mon Mar 29, 2004 3:07 pm   Post subject: (No subject)

I imagine it being something like
code:

loop
Mouse.Where(x,y,b)
if b=1 then %button pressed
//ID what picture is picked up
   loop
   exit when b=0 %drag picture around while mouse is down
   picture(picID).x = x
   picture(picID).y = y
   Mouse.Where(x,y,b)
   end loop
end loop


I also sujest implementing a snap - that is, if the picture is within certain distance of the square, it gets snaped into it, so that user doesn't have to make per pixel adjustments in positioning
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: