2d

Difference between using Canvas and JPanel for a 2D game engine (and Buffering?)

≯℡__Kan透↙ 提交于 2019-12-12 04:37:21
问题 I learned from various tutorials to use a Canvas on top of a JFrame to render images for a 2D Game Engine. I had to create a BufferStrategy to keep the image smooth and such, but recently I've heard using a JPanel instead to render images. Should I use JPanel? If so, do I still need to create a BufferStrategy or is it integrated. Am I just really misinformed and am I even making sense? I'm a beginner so feel free to try to correct me and guide me- I am very overwhelmed with this for some

Transpose a 2d Array with varying dimensions in Java

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 04:36:56
问题 Hey I'm trying to transpose a 2d Array who's rows/columns are inputted by the user. I've looked around on this site and pretty much all the advice I see is for square arrays (2x2,3x3, etc...) this is what I have so far import java.util.Scanner; public class ArrayTranspose { public static void main(String[] args) { Scanner kb = new Scanner(System.in); System.out.print("Input the number of rows (must be between 2 and 5): "); int rows = kb.nextInt(); if ((rows < 2) && (rows > 5)) { System.out

the fillStyle of canvas is not working

一曲冷凌霜 提交于 2019-12-12 04:31:42
问题 i have a function that has a loop. in the loop it creates a canvas and sets the opacity. Then it sets the background color and converts the canvas to an image. Somehow the Opacity is being set on the canvas but the background color doesn't get set. if (remain <= 0) { var canvas = document.createElement('canvas'); context = canvas.getContext('2d'); for (var i = 0; i < img.length; ++i) { if (img[i]) { var opacity = item.opa; context.globalAlpha = opacity; context.drawImage(img[i],0,0); } } var

Unity - collision failure for fast moving objects

元气小坏坏 提交于 2019-12-12 04:21:41
问题 Does anyone have any suggestions on how to deal with fast moving objects missing collisions in Unity. I am creating a breakout game for mobile and discovered that when the paddle is moved very fast then it misses the collision with the ball. I changed the collision to continuous detection but that throws up weird behaviour such as paddle being pushed down on collision. I also tried playing around with the dontgothrough script to make it work for 2D colliders without success. Anyone have any

Shifting rows and columns in 2D arrays - Javascript

若如初见. 提交于 2019-12-12 04:16:33
问题 I have a situation as such: var array = [ [1,2,3], [4,5,6], [7,8,9] ] And I am trying to create a function that shifts either a row or a column so the result would be: shiftRow(array, 1) [ [3,1,2], [4,5,6], [7,8,9] ] shiftColumn(array,1) [ [7,2,3], [1,5,6], [4,8,9] ] I want the first number to be the last number then continue from there in any instance. I have tried several nested for loops, and I'm quite stuck at figuring this out. Keep in mind I have only been coding for a few months though

Displaying 2D Schematics in WPF with Drawing Visuals

时光总嘲笑我的痴心妄想 提交于 2019-12-12 03:17:18
问题 I am creating a WPF application that will display 2D vector graphics of a city-scale water management system. I have captured data from hundreds pages of schematic drawings of valves, pumps, treatment facilities, etc and the piping that interconnects them. Combine this with mapping information of individual residences and commercial properties and the data set has about 100,000 node instances along with the interconnecting pipe information. I have a proof-of-concept application that creates a

Unity 2D animation running partially

孤街醉人 提交于 2019-12-12 03:16:01
问题 I have a 2D skeleton animation of human walk cycle - which is fine. I am trying hard to code that should STOP only hands animation but legs should not (on a player input - for example on space bar press) Is it possible to disable animation keyframes/curves/properties on some condition Or any other way to achieve this. 回答1: Have multiple states in your Animation Controller. Let one state have both hands and legs animation, and the other have only legs animation. Transition from the first state

2D Isometric(diamond shape) game engine - Reversed sprites

倾然丶 夕夏残阳落幕 提交于 2019-12-12 03:06:48
问题 All my sprites are reversed when I try to draw my isometric map. Here is the tileset.png mentionned in the following code : Object.h/Object.cpp I can use them to draw tiles, UI element, etc. ... #pragma once class Object { public: //FUNCTIONS Object(); void addComponent(float value); int getComponent(float index); void editComponent(float index, float value); void deleteComponent(float index); private: vector<int> components; }; #include "Object.cpp" - #pragma once //FUNCTIONS Object::Object(

Floodfill implementetion

假如想象 提交于 2019-12-12 02:52:02
问题 I have a problem with my flood fill function: void floodfill(int x, int y,Pixel old, Pixel new){ Pixel current = getPixel(x,y); if(current.r == old.r && current.g == old.g && current.b == old.b){ setPixel(x,y,new); floodfill(x+1,y,old,new); floodfill(x-1,y,old,new); floodfill(x,y+1,old,new); floodfill(x,y-1,old,new); floodfill(x+1,y+1,old,new); floodfill(x-1,y-1,old,new); floodfill(x+1,y+1,old,new); floodfill(x-1,y+1,old,new); } } In struct 'Pixel' I have rgb values of the pixel. I am trying

Vec1 = Circle centre, Vec2 = mousepos, find the point on the circle between Vec1, Vec2

妖精的绣舞 提交于 2019-12-12 02:52:00
问题 I have two vectors: one is in the centre of a circle, another is at the mouse position. I want to find the point on the circle that is between the two vectors. I specifically want the answer in terms of circle centre + diameter, not trigonometry. So, Circle centre + circle diameter (in the direction of) the mouse position. If it helps, think of a clock. I need the vector coordinance of the 'number' the 'hand' is pointing to. The hand is always pointing toward the variable vector 'mouse