|
Problem with direct x
Hey, I'm taking a C++ class at my college and I'm having trouble getting a program to run right. I'm using someone else's engine and it seems to have a conflict somewhere. I'm not going to post the whole enging because its way too big, but here is the part that matters and also the part that i am calling it with. This is for a regular windows application project in .NET.
I put in a lot of code just so you can see the whole switch statement... Basically what happens is sandScroll is out background image variable and SetVelocity is the function called from the engine that makes it move whichever way we set it for.
All of our velocities work if done once and not changed while running the program. When we make it so that depending on which direction we are facing ( the switch statement) it shifts which way the background map scrolls, it will crash if it goes to any of the horizontal movements. left and right make the program crash. If you set them to 0,0 for the velocity so the background resets everything works fine except when you go horizontal, obviously it doesn't move at all(plus it resets the image back to default center location so it looks really bad.)
I am trying to figure out if there is a flaw here or what could be causing this. As I said, we tried setting each of these variables singly instead of doing it in the case and everything works fine. It only breaks when you are going one velocity and then you switch to the horizontal movement ones. Switching between any of the other movement schemes works fine, such as moving from going up to going up to the left.
variable direction is just based upon which direction our sprite is pointing(aimed by the mouse)
Case 2 and Case 6 are where it does the horizontal movement... or not  . I have to set it to 0,0 in order to test the other ones, but they do work then. If you need more information let me know, but i cant figure out why it is breaking.
Code that is in the Render() function of my main .cpp
//should be scrolling the screen per the direction that we are facing - David
//Engine is messed up - fix on lines 2409 in engine for horizontal movement
switch (direction)
{
case 0:
sandScroll.SetVelocity(0,1);
break;
case 1:
sandScroll.SetVelocity(-1,1);
break;
case 2:
sandScroll.SetVelocity(1,0);
break;
case 3:
sandScroll.SetVelocity(-1,-1);
break;
case 4:
sandScroll.SetVelocity(0,-1);
break;
case 5:
sandScroll.SetVelocity(1,-1);
break;
case 6:
sandScroll.SetVelocity(-1,0);
break;
case 7:
sandScroll.SetVelocity(1,1);
break;
default:
sandScroll.SetVelocity(0,0);
break;
}
---------------------------------------------------------------------
Engine code from header file:
// Figure out which way the layer is moving
switch( m_MoveDirection )
{
case None:
{
// The layer is not moving so just straight copy it
CoySurfaceToSurface( 0, m_pLayerSurface, 0, pTargetSurface, m_bTransparent, m_ColorKey );
return S_OK;
}
case Horizontal:
{
// The layer is moving horizontally so it needs to
// be split into two different reagions; left and right
RECT RectL, RectR;
// The right rectangle starts at the offset
POINT DestPointR = { OffsetX, OffsetY };
// The left rectangle starts at the origin
POINT DestPointL = { 0, OffsetY };
// Fill in the source dimensions for the right
// rectangle
SetRect( &RectR, 0,
0,
m_SurfaceWidth - OffsetX,
m_SurfaceHeight );
// Fill in the source dimensions for the left
// rectangle
SetRect( &RectL, m_SurfaceWidth - OffsetX,
0,
OffsetX,
m_SurfaceHeight );
// Coy the left rectangle to the destination surface
CoySurfaceToSurface( &RectL, m_pLayerSurface, &DestPointL,
pTargetSurface, m_bTransparent, m_ColorKey );
// Coy the right rectangle to the destination surface
CoySurfaceToSurface( &RectR, m_pLayerSurface, &DestPointR,
pTargetSurface, m_bTransparent, m_ColorKey );
return S_OK;
}
case Vertical:
{
// The layer is moving vertically so it
// needs to be split into 2 regions; top and bottom
RECT RectT, RectB;
// Fill in the destination for the top rectangle
POINT DestPointT = { OffsetX, 0 };
// Fill in the destination for the bottom rectangle
POINT DestPointB = { OffsetX, OffsetY };
// Fill in the source dimensions for the top rectangle
SetRect( &RectT, 0,
m_SurfaceHeight - OffsetY,
m_SurfaceWidth,
OffsetY );
// Fill in the source dimensions for the bottom rectangle
SetRect( &RectB, 0,
0,
m_SurfaceWidth,
m_SurfaceHeight - OffsetY);
// Coy the top rectangle to the destination surface
CoySurfaceToSurface( &RectT, m_pLayerSurface, &DestPointT,
pTargetSurface, m_bTransparent, m_ColorKey );
// Coy the bottom rectangle to the destination surface
CoySurfaceToSurface( &RectB, m_pLayerSurface, &DestPointB,
pTargetSurface, m_bTransparent, m_ColorKey );
return S_OK;
}
case Both:
{
// The layer is moving diagonally so
// it needs to be split into four regions
RECT Rect0, Rect1, Rect2, Rect3;
// Fill in the destination points for the four rectangles
POINT DestPoint0 = { OffsetX, OffsetY },
DestPoint1 = { OffsetX, 0 },
DestPoint2 = { 0, OffsetY },
DestPoint3 = { 0, 0 };
// Fill in the dimensions for the source rectangles
SetRect( &Rect0, 0, 0, m_SurfaceWidth - OffsetX, m_SurfaceHeight - OffsetY );
SetRect( &Rect1, 0, m_SurfaceHeight - OffsetY, m_SurfaceWidth - OffsetX, OffsetY );
SetRect( &Rect2, m_SurfaceWidth - OffsetX, 0, OffsetX, m_SurfaceHeight - OffsetY );
SetRect( &Rect3, m_SurfaceWidth - OffsetX, m_SurfaceHeight - OffsetY, OffsetX, OffsetY );
// Coy the rectangles to the destination surface
CoySurfaceToSurface( &Rect0, m_pLayerSurface, &DestPoint0,
pTargetSurface, m_bTransparent, m_ColorKey );
CoySurfaceToSurface( &Rect1, m_pLayerSurface, &DestPoint1,
pTargetSurface, m_bTransparent, m_ColorKey );
CoySurfaceToSurface( &Rect2, m_pLayerSurface, &DestPoint2,
pTargetSurface, m_bTransparent, m_ColorKey );
CoySurfaceToSurface( &Rect3, m_pLayerSurface, &DestPoint3,
pTargetSurface, m_bTransparent, m_ColorKey );
return S_OK;
}
}
return S_OK;
}
|