Bonjour je suis débutant en Processing j’essaie actuellement de créer deux codes un qui fait se déplacer des pions sur une carte et l'autre qui fait apparaître le plan au fur et à mesure
Le premier
int gridSize, mapSize,x1, y1, tailleX, taille, displayX, displayY; // size of each grid and size of the map in grids
PVector gridPos, pixelPos; // position on grid and position in pixels on window
void setup() {
size(1000, 600);
smooth();
frameRate(30);
mapSize = 20; // 20 grids by 20 grids
gridSize = int(width/mapSize); // assuming width and height are the same value
gridPos = new PVector(10, 10); // start at 0, 0 (top left)
}
void draw() {
PImage planrpg = loadImage("map_1.jpg");
image ( planrpg,200,0,800,600);
/*PImage planfog = createImage(gridSize*3,gridSize*3,RGB);
planfog.copy
(
planrpg,
int(gridPos.x ),
int(gridPos.y ),
int(gridSize*3),
int(gridSize*3),int(gridPos.x ),int(gridPos.y ),int(gridSize*3),int(gridSize*3));
image(planfog,int(gridPos.x * gridSize) ,int(gridPos.y * gridSize));
for (int i = 0; i < gridSize; i++) { // rows
for (int j = 0; j < gridSize; j++) { // columns
rect(gridSize * i, gridSize * j, gridSize, gridSize);
}
}
pixelPos = new PVector(gridPos.x * gridSize + (gridSize/2), gridPos.y * gridSize + (gridSize/2));
noStroke();
fill(255, 0, 0);
rectMode(CENTER);
rect(pixelPos.x, pixelPos.y, gridSize/2, gridSize/2);
}
void mousePressed() {
if (abs(mouseX - pixelPos.x) > abs(mouseY - pixelPos.y)) { // we move in X
if (mouseX - pixelPos.x > 0) {
gridPos.x++;
} else {
gridPos.x--;
}
} else { // we move in Y
if (mouseY - pixelPos.y > 0) {
gridPos.y++;
} else {
gridPos.y--;
}
}
}
celui ci fait apparaître un pion sur une carte puis je souhaite ajouter sur la gauche de l'écran des rectangle pour sélectionner d'autre pion jusqu’à quatre ou cinq puis que un fois sélectionné que ce soit celui ci qui se déplace .
L'autre code il s'agit de faire apparaître une carte au fur et à mesure des clics ça fonctionne un peu quand je suis en position 0,0 c bon mais plus je me déplace vers le bas et vers la droite de l’écran j'ai des rayures noires qui apparaissent sûrement une erreur de calcul mais je ne trouve pas vraiment comment régler le problème
int gridSize, mapSize; // size of each grid and size of the map in grids
PVector gridPos, pixelPos; // position on grid and position in pixels on window
void setup() {
size(982, 982);
smooth();
frameRate(30);
mapSize = 80; // 20 grids by 20 grids
gridSize = width/mapSize*4; // assuming width and height are the same value
gridPos = new PVector(10, 10); // start at 0, 0 (top left)
background(0);
}
void draw() {
//background(0);
PImage planrpg = loadImage("planrpg.jpg");
PImage planfog = createImage(gridSize*3,gridSize*3,RGB);
planfog.copy
(
planrpg,
int(gridPos.x * gridSize + (gridSize/2)),
int(gridPos.y * gridSize + (gridSize/2)),
int(gridSize*3),
int(gridSize*3),int(gridPos.x ),int(gridPos.y ),int(gridSize*3),int(gridSize*3));
image(planfog,int(gridPos.x * gridSize) ,int(gridPos.y * gridSize));
stroke(127);
noFill();
rectMode(CORNER);
for (int i = 0; i < gridSize; i++) { // rows
for (int j = 0; j < gridSize; j++) { // columns
rect(gridSize * i, gridSize * j, gridSize, gridSize);
}
}
// --- Calculating pixelPos from gridPos
pixelPos = new PVector(gridPos.x * gridSize + (gridSize/2), gridPos.y * gridSize + (gridSize/2));
pixelPos.y+gridSize/2,gridSize, gridSize);
}
void mousePressed() {
if (abs(mouseX - pixelPos.x) > abs(mouseY - pixelPos.y)) { // we move in X
if (mouseX - pixelPos.x > 0) {
gridPos.x++;
} else {
gridPos.x--;
}
} else { // we move in Y
if (mouseY - pixelPos.y > 0) {
gridPos.y++;
} else {
gridPos.y--;
}
}
}
J'ai juste essayé de remettre en forme le code parce que j'avais du mal, et je vois qu'il y a un balise de commentaire ouvrante '/*" sans fermeture en plein milieu du code.
int gridSize, mapSize,x1, y1, tailleX, taille, displayX, displayY; // size of each grid and size of the map in grids
PVector gridPos, pixelPos; // position on grid and position in pixels on window
void setup() {
size(1000, 600);
smooth();
frameRate(30);
mapSize = 20; // 20 grids by 20 grids
gridSize = int(width/mapSize); // assuming width and height are the same value
gridPos = new PVector(10, 10); // start at 0, 0 (top left)
}
void draw() {
PImage planrpg = loadImage("map_1.jpg");
image ( planrpg,200,0,800,600);
/*PImage planfog = createImage(gridSize*3,gridSize*3,RGB);
planfog.copy
(
planrpg,
int(gridPos.x ),
int(gridPos.y ),
int(gridSize*3),
int(gridSize*3),int(gridPos.x ),int(gridPos.y ),int(gridSize*3),int(gridSize*3)
);
image(planfog,int(gridPos.x * gridSize) ,int(gridPos.y * gridSize));
for (int i = 0; i < gridSize; i++) { // rows
for (int j = 0; j < gridSize; j++) { // columns
rect(gridSize * i, gridSize * j, gridSize, gridSize);
}
}
pixelPos = new PVector(gridPos.x * gridSize + (gridSize/2), gridPos.y * gridSize + (gridSize/2));
noStroke();
fill(255, 0, 0);
rectMode(CENTER);
rect(pixelPos.x, pixelPos.y, gridSize/2, gridSize/2);
}
void mousePressed() {
if (abs(mouseX - pixelPos.x) > abs(mouseY - pixelPos.y)) { // we move in X
if (mouseX - pixelPos.x > 0) {
gridPos.x++;
} else {
gridPos.x--;
}
} else { // we move in Y
if (mouseY - pixelPos.y > 0) {
gridPos.y++;
} else {
gridPos.y--;
}
}
}
int gridSize, mapSize; // size of each grid and size of the map in grids
PVector gridPos, pixelPos; // position on grid and position in pixels on window
void setup() {
size(982, 982);
smooth();
frameRate(30);
mapSize = 80; // 20 grids by 20 grids
gridSize = width/mapSize*4; // assuming width and height are the same value
gridPos = new PVector(10, 10); // start at 0, 0 (top left)
background(0);
}
void draw() {
//background(0);
PImage planrpg = loadImage("planrpg.jpg");
PImage planfog = createImage(gridSize*3,gridSize*3,RGB);
planfog.copy
(
planrpg,
int(gridPos.x * gridSize + (gridSize/2)),
int(gridPos.y * gridSize + (gridSize/2)),
int(gridSize*3),
int(gridSize*3),int(gridPos.x ),int(gridPos.y ),int(gridSize*3),int(gridSize*3)
);
image(planfog,int(gridPos.x * gridSize) ,int(gridPos.y * gridSize));
stroke(127);
noFill();
rectMode(CORNER);
for (int i = 0; i < gridSize; i++) { // rows
for (int j = 0; j < gridSize; j++) { // columns
rect(gridSize * i, gridSize * j, gridSize, gridSize);
}
}
// --- Calculating pixelPos from gridPos
pixelPos = new PVector(gridPos.x * gridSize + (gridSize/2), gridPos.y * gridSize + (gridSize/2));
pixelPos.y+gridSize/2,gridSize, gridSize);
}
void mousePressed() {
if (abs(mouseX - pixelPos.x) > abs(mouseY - pixelPos.y)) { // we move in X
if (mouseX - pixelPos.x > 0) {
gridPos.x++;
} else {
gridPos.x--;
}
} else { // we move in Y
if (mouseY - pixelPos.y > 0) {
gridPos.y++;
} else {
gridPos.y--;
}
}
}
[processing] debtutant
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.