Right now I'm busy re-creating the Rush hour game with MATLAB Guide (keep in mind that I'm completely new to MATLAB). What I'm doing now is that I've created the gamefield using axes (a 6x6 field, so 36 axes). On top of that I've created the actual cars (also with axes) and displayed them by using imshow.
carPlayer = imread('D:\Aschaffenburg\Engineering Project\Images\Car_player01.png');
imshow(carPlayer, 'Parent', handles.car_player01);
Now I want to get drag and drop working on the cars. So I've started working on tracking the mouse.
% function drag_and_drop should be attached to WindowButtonMotionFcn handles = guihandles(RushHourGUI);
pos = get(RushHourGUI, 'currentpoint'); % get mouse location on figure
x = pos(1); y = pos(2); % assign locations to x and y
set(handles.lbl_x, 'string', ['x loc:' num2str(x)]); % update text for x loc
set(handles.lbl_y, 'string', ['y loc:' num2str(y)]); % update text for y loc
% get position information of the uicontrol
bounds = get(handles.car_player01,'position');
lx = bounds(1); ly = bounds(2);
lw = bounds(3); lh = bounds(4);
The mouse tracking is working and it prints it on the screen, but the "hotspot" (to see if the mouse is in the boundaries of the axes) for the car player (which you have to move) is not working. However it is already giving me an error:
Reference to non-existent field 'car_player01'.
Even though the axes is right there, it still doesn't properly see it. The m file drag_and_drop requests it from the main file RushourGUI.m. So I added the m.file to the main by doing this:
function RushHourGUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
set(hObject, 'WindowButtonMotionFcn', @drag_and_drop);
Can this affect it in any way??
After that I want to enable the uicontrol:
*% test to see if mouse is within the uicontrol.
if x >= lx && x <= (lx + lw) && y >= ly && y <= (ly + lh)
set(handles.car_player01, 'ButtonDownFcn', @grab);
As you can see the 3 sets are commented out because the "enable" is not a valid property. Since I'm pretty new to MATLAB I really have no clue on how to fix this.
Any help would be appreciated!
Thanks in advance. If you have any questions, please let me know.