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

2 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Walter Roberson
Walter Roberson il 10 Lug 2017
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 Commenti
Walter Roberson
Walter Roberson il 18 Lug 2017
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 il 19 Lug 2017
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?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Number games in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by