• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

drawing objects on Camer X & Y after settings it from matrix_build_lookat

C

Chris Livermore

Guest
hi guys,

Im stuck! I have been doing some practice work and following some tutorials for smooth camera flow when following the player, However now I am trying to implement an inventory to the game. the problem I am running into is that by having a camera object that sets matrix_build_lookat and matrix_build_projection_ortho I am unable to get the draw event in my inventory to actually move with the camera.

here is my code:

obj_camera:
create:
----------------------------------------------------------------------------------------------------------
camera = camera_create();

var vm = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
var pm = matrix_build_projection_ortho(1920,1280,1,10000);
camera_set_view_mat(camera,vm);
camera_set_proj_mat(camera,pm);
view_camera[0] = camera;


follow = obj_PLAYER;
xTo = x;
yTo = y;
-----------------------------------------------------------------------------------------------------------

step:
----------------------------------------------------------------------------------------------------------
//xTo yTo = what it is following - its current state
x += (xTo -x)/25;
y += (yTo -y)/25;

//if we have not set the camera to follow anyone we will not move camera.
if (follow != noone){

xTo = follow.x;
yTo = follow.y;

}

var vm = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
camera_set_view_mat(camera,vm);

----------------------------------------------------------------------------------------------------------


INVENTORY

(I have 2 objects, one that builds the inventory and one that draws the GUI)

objInventory (this build the Inventory):
create:
----------------------------------------------------------------------------------------------------------

var vx = camera_get_view_x(view_camera[0]);
var vy = camera_get_view_y(view_camera[0]);

if(!instance_exists(objInventoryGUI)) {
inventoryDisplay = instance_create_depth(vx,vy, depth - 1, objInventoryGUI);
with(inventoryDisplay) {
x = vy //sprite_get_xoffset(sprite_index);
y = room_height - vx //sprite_get_yoffset(sprite_index);
}
}
//Clean up created things
else {
instance_destroy(objInventoryGUI);
}
-----------------------------------------------------------------------------------------------------------
Key Press I:

-----------------------------------------------------------------------------------------------------------
var vx = camera_get_view_x(view_camera[0]);
var vy = camera_get_view_y(view_camera[0]);

if(!instance_exists(objInventoryGUI)) {
inventoryDisplay = instance_create_depth(vx,vy, depth - 1, objInventoryGUI);
with(inventoryDisplay) {
x = vy //sprite_get_xoffset(sprite_index);
y = room_height - vx //sprite_get_yoffset(sprite_index);
}
}
//Clean up created things
else {
instance_destroy(objInventoryGUI);
}

-------------------------------------------------------------------------------------------------------------


objInventoryGUI:
create:
-------------------------------------------------------------------------------------------------------------

textBorder = 22; //The border of the sprite, how much to draw text in

myItems = playerInventory; //Shorter DS grid name
myColor = c_black; //Alter display color
//If the inventory is empty. Totally optional
isEmpty = false;
emptyMessage = "You've no items.";

globalvar itemSelected, scrolledAmount, inventoryEndAt; //We'll need this in several functions & other objects
itemSelected = 0; //The currently selected item from the list
inventoryOnScreen = 0;
inventoryEndAt = min(ds_grid_height(myItems), floor((sprite_height - (textBorder * 3)) / 32)); //How many items to display in the list. Either the amount of items in the list, or the amount that will fit in the sprite.
if(ds_grid_get(myItems, 0, 0) == 0) { //Checks to see if inventory is initially empty
inventoryEndAt = 0;
isEmpty = true;
}
scrolledAmount = 0; //How far down the list we've looked
-------------------------------------------------------------------------------------------------------------
Draw:
-------------------------------------------------------------------------------------------------------------

var vx = camera_get_view_x(view_camera[0]);
var vy = camera_get_view_y(view_camera[0]);
x = vx + sprite_xoffset;
y = vy + sprite_yoffset;
draw_self();
draw_set_colour(myColor);
//Draw the column names
draw_text(bbox_left + textBorder, bbox_top + textBorder, "Image");
draw_text(bbox_left + 125, bbox_top + textBorder, "Name");
draw_text(bbox_left + 225, bbox_top + textBorder, "Amount");

itemLeftStart = bbox_left + 120;
itemTopStart = bbox_top + 48;
//textHeight = max(string_height(string(ds_grid_get(myItems, 0, 0))), sprite_get_height(sprArmor)); //Gets the height of the string EXPLAIN CASTING

for(i = 0; i < inventoryEndAt; ++i) {
for(j = 0; j < ds_grid_width(myItems); ++j) {
inventoryOnScreen = i; //Be able to track what value i is outside of the for loop
if(j == 0) //Draw the name in the right spot
draw_text(itemLeftStart, itemTopStart + (i * 32), ds_grid_get(myItems, 0, i + scrolledAmount));
else if(j == 1) //Draw amount in the right spot
draw_text(itemLeftStart + 140, itemTopStart + (i * 32), ds_grid_get(myItems, 1, i + scrolledAmount));
else if(j == 3) //Draw sprite in the right spt
draw_sprite(ds_grid_get(myItems, j, i + scrolledAmount), 0, bbox_left + 40, itemTopStart + (i * 32) + 16);
}
}

//Show item selection by a rectangle
draw_rectangle(bbox_left + textBorder, itemTopStart + ((itemSelected - scrolledAmount)
* 32), bbox_right - textBorder, itemTopStart + ((itemSelected - scrolledAmount) * 32)
+ 32, true);

-------------------------------------------------------------------------------------------------------------------


thanks for taking the time to look at this guys I am really at a loss on this one and cant find much relate to it!
 
Top