How do i fix my game from a slow render speed? (-------===answered===-------)

I created a game in processing and when the character moves the map tends to take a while to render.. ill display the code below. The map is named map1. I am new so it may be very poorly opimized and if that is the problem just tell me what i can do to fix it.

float w,a,s,d = 0; float menu = 1; float game = 0; float ram = 0; float running = 1; float x = 50; float y = 50; PImage title; PImage start; PImage quit; PImage down; PImage left; PImage right; PImage up; PImage ver; PImage pistol; PImage spistol; PImage uzi; PImage xm1; PImage xm2; PImage cursor; PImage map1; PImage dir; void setup() { size(1366,768); surface.setResizable(true); background(0); noStroke(); fill(255); noCursor(); title = loadImage("title.gif"); start = loadImage("start.gif"); quit = loadImage("quit.gif"); down = loadImage("Down.png"); left = loadImage("Left.png"); right = loadImage("Right.png"); up = loadImage("up.png"); ver = loadImage("ver.png"); pistol = loadImage("Pistol.gif"); spistol = loadImage("Scope Pistol.gif"); uzi = loadImage("UZI.png"); xm1 = loadImage("XM-1.png"); xm2 = loadImage("XM-2.png"); cursor = loadImage("cursor.png"); map1 = loadImage("map1.png"); dir = down; textSize(20); } void draw() { if(menu == 1) { clear(); text(frameRate, width-32, 20); image(title,width/2.732,030); image(start,width/3.902,250); image(quit,width/3.902,350); pistol.resize(132,84); right.resize(150,150); image(right,width/1.437,275); image(ver,0,0); image(pistol,width/1.366,350); cursor.resize(32,32); image(cursor,mouseX,mouseY); } if(game == 1) { clear(); text(frameRate, width-32, 20); image(map1,x,y); dir.resize(75,75); image(dir,683,384); keypress(); detect(); } } void detect() { if(x == 630) { x=620; } if(x == -1690) { x=-1680; } if(y == 330) { y=320; } if(y == -1990) { y=-1980; } if(x == -1060 && y<-880) { x=-1050; } if(y == -890 && x<-1050 && x>-1200) { y=-880; } if(x==-1190 && y<-880) { x=-1200; } if(x==-1060 && y>-380) { x=-1050; } if(x==-1190 && y>-380) { x=-1200; } if(y==-370 && x>-1200 && x<-1050) { y=-380; } if(x==-20 && y<-320 && y>-1170) { x=-10; } if(x==-140 && y<-320 && y>-1170) { x=-150; } if(y==-330 && x>-150 && x<-10) { y=-320; } if(y==-1160 && x>-150 && x<-10) { y=-1170; } } void keypress() { if(w == 1) { dir=up; y=y+2.5; } if(a == 1) { dir=left; x=x+2.5; } if(s == 1) { dir=down; y=y-2.5; } if(d == 1) { dir=right; x=x-2.5; } } void mouseReleased() { if(menu == 1) { if(mouseX>width/3.902 && mouseX <width/3.902+185 && mouseY>350 && mouseY <350+75) { exit(); } if(mouseX>width/3.902 && mouseX <width/3.902+185 && mouseY>250 && mouseY <250+75) { menu = 0; game = 1; x=50; y=50; } } } void keyPressed() { if(keyCode == ESC) { game = 0; menu = 1; key=0; } if(key == 'w') { w = 1; } if(key == 'a') { a = 1; } if(key == 's') { s = 1; } if(key == 'd') { d = 1; } } void keyReleased() { if(key == 'w') { w = 0; } if(key == 'a') { a = 0; } if(key == 's') { s = 0; } if(key == 'd') { d = 0; } }

Answers

  • Your code will improve if you move your resize calls to setup. If you need to have images of different size, resize them all in setup and reference them in draw exactly the way you are referencing all the images you load in setup.

    Kf

  • edited March 2017

    It has improved but the map still seems to lag

  • I fixed it by changing the size(1366,768); to size(1366,768,P2D);

Sign In or Register to comment.