No appropriate method, property, or field 'Mariorun1' for class 'matlab.gr​aphics.pri​mitive.Ima​ge'.

조회 수: 2 (최근 30일)
Im trying to make a Mario game gui using an arduino joystick as a controller. For some reason I keep getting an error in the loop where the mario sprites alternates and mario moves horizontally. Can anyone help with this? The code below is in the opening function of the gui.
a = arduino('COM8','Uno');
[Sprites Spritesmap SpritesAlpha] = imread('some_mario_stuff_and_more_by_pokekoks-d4wzrc5.png');
handles.Sprites.Sprites = Sprites;
handles.Sprites.Mariorun1 = Sprites(181:1:213,89:1:121,:);
handles.Sprites.Mariorun2 = Sprites(219:1:251,9:1:41,:);
handles.Sprites.Mariorun3Jump = Sprites(220:1:254,127:1:161,:);
handles.Sprites.MarioStanding = Sprites(181:1:213,11:1:43,:);
Stage_UC = imread('Mario1_1.png');
Mario_Structure = load('mario_stages.mat');
handles.Template = Mario_Structure.Stage1_1.statMapInd; % or whatever it's called.
Stage = Stage_UC(1:1:227,:,:);
imshow(Stage);
axes(handles.TempAxis)
imshow(handles.Template);
axes(handles.MarioAxis)
imshow(Stage);
axes(handles.MarioSpriteAxis)
handles.Sprites = imagesc(handles.Sprites.MarioStanding);
handles.Sprites.AlphaData = SpritesAlpha(181:1:213,11:1:43,:);
axis off
configurePin(a,'A0','AnalogInput')
for time = [1:1:10000];
A2Voltage = readVoltage(a, 'A0');
CurrentX = 0;
if A2Voltage >= 3
handles.Sprites = imagesc(handles.Sprites.Mariorun1);
handles.Sprites.AlphaData = SpritesAlpha(181:1:213,89:1:121,:);
axis off
pause(.04)
handles.Sprites = imagesc(handles.Sprites.Mariorun2);
handles.Sprites.AlphaData = SpritesAlpha(219:1:251,9:1:41,:);
axis off
pause(.04)
handles.Sprites = imagesc(handles.Sprites.Mariorun1);
handles.Sprites.AlphaData = SpritesAlpha(181:1:213,89:1:121,:);
axis off
pause(.04)
handles.Sprites = imagesc(handles.Sprites.Mariorun3Jump);
handles.Sprites.AlphaData = SpritesAlpha(220:1:254,127:1:161,:);
axis off
CurrentX = CurrentX + 1
set(handles.MarioSpriteAxis, 'Position' ,[CurrentX 21.385 1.8 0.615]);
elseif A2Voltage < 2
set(handles.MarioSpriteAxis,'xdir','reverse')
handles.Sprites = imagesc(handles.Sprites.Mariorun1);
handles.Sprites.AlphaData = SpritesAlpha(181:1:213,89:1:121,:);
axis off
pause(.04)
handles.Sprites = imagesc(handles.Sprites.Mariorun2);
handles.Sprites.AlphaData = SpritesAlpha(219:1:251,9:1:41,:);
axis off
pause(.04)
handles.Sprites = imagesc(handles.Sprites.Mariorun1);
handles.Sprites.AlphaData = SpritesAlpha(181:1:213,89:1:121,:);
axis off
pause(.04)
handles.Sprites = imagesc(handles.Sprites.Mariorun3Jump);
handles.Sprites.AlphaData = SpritesAlpha(220:1:254,127:1:161,:);
axis off
CurrentX = CurrentX - 1
set(handles.MarioSpriteAxis, 'Position' ,[CurrentX 21.385 1.8 0.615])
end
end
if true
% code
end
%Update handles structure
guidata(hObject, handles);

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 10일
You have, for example,
handles.Sprites = imagesc(handles.Sprites.Mariorun1);
This replaces all of handles.Sprites with the output of imagesc(), which is going to be a primitive image() object. image() objects do not have Mariorun2 properties, so when you do
handles.Sprites = imagesc(handles.Sprites.Mariorun2);
a few lines down, there is no Mariorun2 property to access.
  댓글 수: 20
Walter Roberson
Walter Roberson 2017년 7월 18일
You have
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)-15)/29);
What reason do you have to expect that those will not be 0? Or even -1 for Column ?
Curtis Vannor
Curtis Vannor 2017년 7월 19일
Ok I understand. But I am curious if there is a way to check the color of the template axis in the area in front of mario before mario approaches that are in order to dictate whether or not mario can interact with that area. The stage is as shown:
And the template under this is as shown:
The solid objects are shown in blue and green on the template. Can you help me with this?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number games에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by