"ParentBlock" code with demo
Posted: Wed Nov 05, 2014 4:00 am
This script allows you to create a block which many actors can become "parrented" to.
Instructions:
updateParentBlock(id, x, y, width, height, z);
This code sets/updates the initial variables of the ParentBlock ID.
snapToParentBlock(id, offsetx, offsety, offsetz);
This sets the actor's X and Y equal to the blocks X and Y, plus the offsets you specified. It also alters the Z depth, which can also be offset.
drawParentBlock(id);
This is used in a canvas, make sure to stretch the canvas to the views size.
Copy the code to your global code, and name it something fitting.
Skydereign will probably notice some more optimized way of doing this, but that's part of the fun! Enjoy guys.
Reason for file size: I apparently used a font that's about 20MB lol O:...
In the demo, you can use left and right to control the box .
Instructions:
updateParentBlock(id, x, y, width, height, z);
This code sets/updates the initial variables of the ParentBlock ID.
snapToParentBlock(id, offsetx, offsety, offsetz);
This sets the actor's X and Y equal to the blocks X and Y, plus the offsets you specified. It also alters the Z depth, which can also be offset.
drawParentBlock(id);
This is used in a canvas, make sure to stretch the canvas to the views size.
Copy the code to your global code, and name it something fitting.
- Code: Select all
//Creating the struct
typedef struct {
int x, y, width, height;
double z;
} parentBlock;
parentBlock ParentBlock[9999];
//Struct Creation
void updateParentBlock(int id, int X, int Y, int Width, int Height, double Z) //Set the initial X and Y, or update it.
{
ParentBlock[id].x=X;
ParentBlock[id].y=Y;
ParentBlock[id].width=Width;
ParentBlock[id].height=Height;
ParentBlock[id].z=Z;
}
void snapToParentBlock(int id, int offsetX, int offsetY, double offsetZ) //Snaps an actor to the given block, technically "parrenting" it. Also effects Z depth.
{
x=ParentBlock[id].x+offsetX;
y=ParentBlock[id].y+offsetY;
ChangeZDepth("Event Actor", ParentBlock[id].z+offsetZ);
}
void drawParentBlock(int id) // Use this in a canvas to debug/draw the window, stretch canvas to views size.
{
moveto(-view.x+ParentBlock[id].x, -view.y+ParentBlock[id].y); //Honestly don't know why it has to be negative.
lineto(-view.x+ParentBlock[id].x, -view.y+ParentBlock[id].y+ParentBlock[id].height);
lineto(-view.x+ParentBlock[id].x+ParentBlock[id].width, -view.y+ParentBlock[id].y+ParentBlock[id].height);
lineto(-view.x+ParentBlock[id].x+ParentBlock[id].width, -view.y+ParentBlock[id].y);
lineto(-view.x+ParentBlock[id].x, -view.y+ParentBlock[id].y);
}
Skydereign will probably notice some more optimized way of doing this, but that's part of the fun! Enjoy guys.
Reason for file size: I apparently used a font that's about 20MB lol O:...
In the demo, you can use left and right to control the box .