I have 24 buttons that will shape a circle together.
So, the image of the buttons should look in a rotating way like this:
I want to use the same 3 images (setImages(); 3 images for 3 mouseClick conditions in 1 button) in each of them. I thought I could maybe rotate the buttons instead of loading new images.
Is there any way to rotate the buttons? Or could you give me an idea like what would be the most logical way to do this?
Here is my code:
for(int i=0; i<3; ++i){
(imgden1[i] = loadImage("den" + i + ".png")).resize(20,20);} //the same 3 images for all the buttons
for(int k=1; k<25; ++k){ //24 buttons in total
cp5.addButton("Button" + k) // The button
.setPosition((50+40*k),140) //I will set the algorithm for position later when I solve the rotation problem
.setImages(imgden1)
.updateSize()
.setSize(20, 20) // (width, height)
.setFont(font)
.moveTo(AreaRingGroup);
} // add it to the group
;
Related
I'm trying to make a midi-editor in processing and I need to have rectangular cells that you can click on to add a note there.
So far I've done googling but haven't found a result. What happens is when you click the further down the less accurate it gets.
I don't know what is going wrong and I've had this problem in the past but couldn't fix it.
Note: The cells are not square.
Example processing code to snap the mouse coordinates to the center of the nearest grid cell (where cell dimensions are defined by rectangle width and height).
int w = 48; // rectangle width
int h = 24; // rectangle height
int snapX = round(mouseX / w) * w + w/2; // '+ w/2' is offset to center of cell
int snapY = round(mouseY / h) * h + h/2; // '+ h/2' is offset to center of cell
I have more than 30 canvas on the DOM with a shape drawn on to the canvas, which will be arranged in overlapping position to make a Pattern, like many triangles will be joined to make a pattern . Please find the below image for reference.
https://i.stack.imgur.com/Cg2wI.png
Ill also be able to draw on any of the canvas and the drawing should replicate on all the shapes. I have used createjs-nextstage property to bypass mousedown to underlying canvas. In desktop its working fine but on Touch devices its not working (stagemousemove is not firing).
for (var k = 0; k < currentArray.length; k++) .
{
if (k != 0)
currentArray[k].nextStage = currentArray[k - 1];
}
For my 2D Game; I have a panel with an image Component (with a sprite) and a GridLayout component.
On the panel i have also put a script that creates buttons for the panel (as children)
public void InitializeGrid(int rows, int columns, List<RbzFilteredWord> words)
{
RectTransform myRect = GetComponent<RectTransform>();
buttonHeight = myRect.rect.height / (float)rows;
buttonWidth = myRect.rect.width / (float)columns;
GridLayoutGroup grid = this.GetComponent<GridLayoutGroup>();
grid.cellSize = new Vector2(buttonWidth, buttonHeight);
...
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
button = (Button)Instantiate(prefab);
button.transform.SetParent(transform, false);
...
}
Problem:
The text of each button must indicate the color of the pixel (from the underlying image) at the pivot location of that button
I know that this method is available: GetPixel(x,y), but i don't know which coordinates i need to use as parameters for this method, since i'm a noob at unity
x and y are the position indexes in the pixels bidimensional array of teh texture.
That is:
x goes from 0 to the width - 1 of the texture image (in pixels)
y goes from 0 to the height - 1 of the texture image (in pixels)
http://deepschool.kd.io/Pages/Experiments/draw.htm
This is a Image editor I am working on, But it has a bug. Let's say you have created an image a 15x Zoom, when you change the zoom, the image is lost. Why is this? and what is the Remedy?
HTML:
Zoom:
<input type="number" id="zoom" min="1" max="50" onchange="zoomy()">
JS:
var zoomy = function() {
var zoomamount = zoom.value
var canvassize = zoomamount * 16
c.width = canvassize
c.height = canvassize
};
Thanks In Advance
If you want to zoom into canvas, it means you have to redraw it with zoom.
So instead of drawing pixels on click right onto canvas, which is made of pure pixels... You need to first create some representation of your grid of pixels.
var gridOfPixels = [];
Let's say you are ok with static size for now. Make it 8x8 pixels. At start you want to initialize your array:
for (var i=0; i < 8*8; i++) gridOfPixels[i] = 0;
So the grid canvas is ready, now we need to draw it.
function renderGrid() {
for (var y=0; y < 8; y++)
for (var x=0; x < 8; x++)
renderPixel( x, y, gridOfPixels[x+y*8] );
}
You already know how to renderPixel - calculate the rectangle position (posX = x*pixWidth, posY*pixHeight), where pixWidth is canvasWidth/8, etc.. Now you draw all your pixels, using the third parameter for the color.
To finish, you have to connect onclick to put a pixel on grid, and then call renderGrid so the user sees the change.
$('#my-canvas').click(function(e) {
var x = ...;
var y = ...; // calculate the position of pixels from mouse position inside canvas
// dont forget to check that x,y are in the 0-7 range
// dont forget to convert x,y to whole number using parseInt()
gridOfPixels[x+y*8] = 1;
renderGrid(); // update the grid canvas
});
Now, every time you resize the canvas or change some variables, the original canvas content will be saved in your grid, and you can renderGrid() any time you need to. You could even do it in realtime, animating the color of the pixels, etc..
Have fun. :)
I am trying to draw a grid on the screen of a Windows Phone; it will help me better position my sprites on the screen rather than guessing locations on the screen.
I have found several examples of a grid (2d or 3d) using XNA 3.0, but unfortunately the architectures are different and so the code doesnt work in XNA 4.0
Does anyone have something that could work?
Thanks!
You can download a PrimitiveBatch class here http://create.msdn.com/en-US/education/catalog/sample/primitives and use the code below to generate an appropriate grid as a texture.
PrimitiveBatch primitiveBatch;
private Texture2D GenerateGrid(Rectangle destRect, int cols, int rows, Color gridColor, int cellSize)
{
int w = (int)(cols * gridCellSize);
int h = (int)(rows * gridCellSize);
float uselessWidth = destRect.Width - w;
float uselessHeigth = destRect.Height - h;
Rectangle bounds = new Rectangle((int)(uselessWidth / 2) + destRect.X, (int)(uselessHeigth / 2) + destRect.Y, w, h);
RenderTarget2D grid = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
GraphicsDevice.SetRenderTarget(grid);
GraphicsDevice.Clear(Color.Transparent);
primitiveBatch.Begin(PrimitiveType.LineList);
float x = bounds.X;
float y = bounds.Y;
for (int col = 0; col < cols + 1; col++)
{
primitiveBatch.AddVertex(new Vector2(x + (col * gridCellSize), bounds.Top), gridColor);
primitiveBatch.AddVertex(new Vector2(x + (col * gridCellSize), bounds.Bottom), gridColor);
}
for (int row = 0; row < rows + 1; row++)
{
primitiveBatch.AddVertex(new Vector2(bounds.Left, y + (row * gridCellSize)), gridColor);
primitiveBatch.AddVertex(new Vector2(bounds.Right, y + (row * gridCellSize)), gridColor);
}
primitiveBatch.End();
GraphicsDevice.SetRenderTarget(null);
return grid;
}
One quick and dirty way you can do it (as it is for debugging the quicker the better) is to simply create a texture of a grid that is of the same resolution you are running your XNA game at (if you are running it at the same resolution as the phone, this will be 480x800). Most of the texture will simply be an alpha map and with grid lines of one pixel, you could create multiple resolutions or you can repeat a small texture of a single pixel cross dividing a section of the screen that is divisible by the resolution you are running at.
The draw method will be something as below and be called everyframe.
This code can declared inside your game class
Texture2D gridTexture;
Rectangle gridRectangle;
This code should be in your LoadContent method
//Best to use something like a png file
gridTexture = content.Load<Texture2D>("pathto/mygridtexture");
gridRectangle = new Rectangle(0,0,resolutionX,resolutionY);
This method should be called from your Draw method last to ensure it is on top assuming you are just using the standard spriteBatch.Begin() to render sprites (first if you are doing FrontToBack rendering).
public void DrawGrid()
{
spriteBatch.Draw(gridTexture, gridRectangle, Color.White);
}
This grid will remain stationary throughout the running of your application and should be useful when trying to line up your UI or objects that have relative positions in your game.
HTH.
You may want to take a look at the XPF project by RedBadger. It enables you to use XAML style layout in an XNA project.