Subscript indices must either be real positive integers or logicals.

조회 수: 2 (최근 30일)
Curtis Vannor
Curtis Vannor 2017년 7월 18일
편집: Curtis Vannor 2017년 7월 21일
Im trying to create a mario game and am coming across the error mentioned above on this line:
if (handles.Template(Row,Column) == 0);
The rest of the code is shown below:
[Rows Columns Color] = size(handles.Template)
for RowIndex = 1:1:Rows
for ColumnIndex = 1:1:Columns
if handles.Template(RowIndex, ColumnIndex, 2) <= 22 &&...
handles.Template(RowIndex, ColumnIndex, 3) <= 24
handles.Template(RowIndex,ColumnIndex,:) == 1;
else
handles.Template(RowIndex,ColumnIndex,:) == 0;
end
end
end
configurePin(a,'A0','AnalogInput')
CurrentX = 0;
for time = [1:1:10000];
A2Voltage = readVoltage(a, 'A0');
if A2Voltage >= 3
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)+15)/29);
set(handles.SpriteAxis,'xdir','normal')
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','on');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','off');
set(I,'visible','on');
axis off
if (handles.Template(Row,Column) == 0);
handles.SpriteAxis.Position(1) = handles.SpriteAxis.Position(1)+15;
end
elseif A2Voltage < 2
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)-15)/29);
set(handles.SpriteAxis,'xdir','reverse')
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','on');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','off');
set(I,'visible','on');
axis off
if (handles.Template(Row,Column) == 0)
handles.SpriteAxis.Position(1) = handles.SpriteAxis.Position(1)-15;
end
end
end

채택된 답변

Jan
Jan 2017년 7월 18일
What is your question?
You have to use the debugger to find the reason of the problem. The indices are defined here:
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)+15)/29);
Obviously at least one of them is not positive. You can test this easily by letting Matlab stop at the error:
dbstop if error
or use the corresponding menu in the editor. Then run the code again until it stops at the error. Now check the values of Row and Column.
for time = [1:1:10000];
to the faster and nicer
for time = 1:10000
  댓글 수: 11
Walter Roberson
Walter Roberson 2017년 7월 21일
If there are no "hot spots" on the sprites (places that should act differently -- e.g., does it matter whether it is Mario's foot that touches the rope compared to Mario's hand?) then it is easiest to use the centroid of the sprite as the reference point, as then the distance left and right would be the same. This does have a small challenge if the sprite is an odd number of pixels in width: you should be conscious of whether the reference point is the center of the pixel or the left edge or the right edge of the pixel.
Curtis Vannor
Curtis Vannor 2017년 7월 21일
편집: Curtis Vannor 2017년 7월 21일
Im not really sure what you mean by converting between the coordinate systems. I made this function:
function [ new_coordinates ] = coortrans( in1,in2 )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
size(in1)/size(in2)
end
Which gave a ratio of the size of the larger stage to the template, but what do I do from here?
Also, will the centroid be necessary since the sprite is its own axis? Couldn't I just use the position parameter of the axis itself?

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by