how to center this background call?

Status
Not open for further replies.

Xyonel

Indie Developer, All-in-one artist.
Veteran
Joined
Jul 22, 2018
Messages
137
Reaction score
28
First Language
Italian
Primarily Uses
RMMV
How can I center the image on a wide screen ?

Scene_Album_TT.prototype.createBackground = function () {
this._backSprite = new Sprite();
this._backSprite.bitmap = ImageManager.loadTripleTriad(this.image_list['AlbumBackground']);
this.addChild(this._backSprite);

I tried :
Scene_Album_TT.prototype.createBackground = function () {
this._backSprite = new Sprite();
this._backSprite.bitmap = ImageManager.loadTripleTriad(this.image_list['AlbumBackground']);
this._backSprite.bitmap.x = Graphics.width/2;
this._backSprite.bitmap.y = Graphics.height/2;
this.addChild(this._backSprite);


even this does not show changes:
this._backSprite.bitmap.x = Graphics.boxWidth/2;
this._backSprite.bitmap.y = Graphics.boxHeight/2;

there is another action that I must do in order to let it work?
maybe this is only a definition and must be called?
 
Last edited:

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
934
Reaction score
682
First Language
English
Primarily Uses
RMMV
@Xyonel Hmm, you seem to be setting the X and Y value of the bitmap and not the sprite.

Code:
this._backSprite.x = Graphics.width / 2 - this._backSprite.width / 2;
this._backSprite.y = Graphics.height / 2 - this._backSprite.height / 2;

// Or
this._backSprite.anchor.set(0.5, 0.5);
this._backSprite.x = Graphics.width / 2;
this._backSprite.y = Graphics.height / 2;
 

Xyonel

Indie Developer, All-in-one artist.
Veteran
Joined
Jul 22, 2018
Messages
137
Reaction score
28
First Language
Italian
Primarily Uses
RMMV
thanks, could you explain me how anchor.set works ? and why is needed?
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
934
Reaction score
682
First Language
English
Primarily Uses
RMMV
@Xyonel You do not have to set the anchor property, but doing so means a little less math when you want to center the sprite. Basically, anchor sets the origin point of the sprite. If you have ever tinkered with the 'Origin' option in a 'Show Picture' event command, this is exactly the same (but more customizable). By default, the anchor points are set to 0 and 0 which means the origin point for the sprite is the top left. By setting the anchor to 0.5 and 0.5 the origin point is the center of the sprite. The origin point would be the bottom right if set to 1 and 1.
 

Xyonel

Indie Developer, All-in-one artist.
Veteran
Joined
Jul 22, 2018
Messages
137
Reaction score
28
First Language
Italian
Primarily Uses
RMMV
thanks, very useful.
 

Wavelength

Pre-Merge Boot
Global Mod
Joined
Jul 22, 2014
Messages
4,590
Reaction score
3,837
First Language
English
Primarily Uses
RMVXA

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Why is it so hard to accept existential stoicism? To insist stoics must be deterministic is like insisting God couldnt create evolving animals. Drop the dogmas and concider the compatible mechanics
I just had a duel at Duel Links, and started right away with a fusion monster... felt like an actual yugioh main character :3
Now listen closely... Here's a little lesson in trickery, This is going down in history...
So the four of my friends are singing a song and I'm like... ohoho I don't know this song. Better act like I do!
A boss that spams confuse, blind, silence, oil and slow on all party members? Good idea FF12 *headdesk*

Forum statistics

Threads
93,511
Messages
913,114
Members
123,045
Latest member
califert
Top